Skip to content
Draft

Armor #546

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.util.List;

public interface IBreathingArmorLogic extends ISpecialArmorLogic {
public interface IBreathingArmorLogic extends ISpecialArmorLogic {

boolean mayBreatheWith(ItemStack stack, EntityPlayer player);

Expand Down
63 changes: 63 additions & 0 deletions src/main/java/supersymmetry/api/items/IStandardArmorLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package supersymmetry.api.items;

import gregtech.api.items.armor.ArmorMetaItem;
import gregtech.api.items.armor.ISpecialArmorLogic;
import gregtech.api.items.metaitem.stats.IItemBehaviour;
import gregtech.common.items.behaviors.TooltipBehavior;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.common.ISpecialArmor;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public interface IStandardArmorLogic extends ISpecialArmorLogic {

default ISpecialArmor.ArmorProperties getProperties(EntityLivingBase player, @NotNull ItemStack armor, DamageSource source, double damage,
EntityEquipmentSlot equipmentSlot) {
return new ISpecialArmor.ArmorProperties(0, 0, (int) player.getMaxHealth());
}

void addInformation(ItemStack stack, List<String> tooltips);

default int getArmorDisplay(EntityPlayer player, @NotNull ItemStack armor, int slot) {
return 0;
}

@Override
default void addToolComponents(ArmorMetaItem.ArmorMetaValueItem metaValueItem) {
metaValueItem.addComponents(new TooltipBehavior((ignored) -> {
}) {
@Override
public void addInformation(ItemStack itemStack, @NotNull List<String> lines) {
IStandardArmorLogic.this.addInformation(itemStack, lines);
}
}, new IItemBehaviour() {

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
return onRightClick(world, player, hand);
}
});
}

default ActionResult<ItemStack> onRightClick(World world, EntityPlayer player, EnumHand hand) {
if (player.getHeldItem(hand).getItem() instanceof ArmorMetaItem) {
ItemStack armor = player.getHeldItem(hand);
if (armor.getItem() instanceof ArmorMetaItem &&
player.inventory.armorInventory.get(getEquipmentSlot(armor).getIndex()).isEmpty() &&
!player.isSneaking()) {
player.inventory.armorInventory.set(getEquipmentSlot(armor).getIndex(), armor.copy());
player.setHeldItem(hand, ItemStack.EMPTY);
player.playSound(new SoundEvent(new ResourceLocation("item.armor.equip_generic")), 1.0F, 1.0F);
return ActionResult.newResult(EnumActionResult.SUCCESS, armor);
}
}

return ActionResult.newResult(EnumActionResult.PASS, player.getHeldItem(hand));
}
}
10 changes: 10 additions & 0 deletions src/main/java/supersymmetry/common/item/SuSyArmorItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import supersymmetry.api.items.IBreathingArmorLogic;
import supersymmetry.api.items.IStandardArmorLogic;
import supersymmetry.api.items.IBreathingItem;
import supersymmetry.client.renderer.handler.ITextureRegistrar;

Expand All @@ -26,6 +27,7 @@ public double getDamageAbsorbed(ItemStack stack, EntityPlayer player) {

public class SuSyArmorMetaValueItem extends ArmorMetaItem<SuSyArmorMetaValueItem>.ArmorMetaValueItem {
private IBreathingArmorLogic armorLogic = null;
private IStandardArmorLogic standardArmorLogic = null;
protected SuSyArmorMetaValueItem(int metaValue, String unlocalizedName) {
super(metaValue, unlocalizedName);
this.setMaxStackSize(1);
Expand All @@ -39,6 +41,14 @@ public SuSyArmorMetaValueItem setArmorLogic(IBreathingArmorLogic armorLogic) {
return this;
}

public SuSyArmorMetaValueItem setArmorLogic(IStandardArmorLogic standardArmorLogic) {
super.setArmorLogic(standardArmorLogic);
this.standardArmorLogic = standardArmorLogic;
if (standardArmorLogic instanceof IItemComponent)
this.addComponents((IItemComponent) standardArmorLogic);
return this;
}

}

protected SuSyArmorMetaValueItem constructMetaValueItem(short metaValue, String unlocalizedName) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/supersymmetry/common/item/SuSyMetaItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public class SuSyMetaItems {

public static ArmorMetaItem<?>.ArmorMetaValueItem JET_WINGPACK;

public static ArmorMetaItem<?>.ArmorMetaValueItem STEEL_HELMET;
public static ArmorMetaItem<?>.ArmorMetaValueItem STEEL_CHESTPLATE;
public static ArmorMetaItem<?>.ArmorMetaValueItem COTTON_PANTS;
public static ArmorMetaItem<?>.ArmorMetaValueItem TRENCH_BOOTS;

public static void initMetaItems() {
metaItem = new StandardMetaItem();
metaItem.setRegistryName("meta_item");
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/supersymmetry/common/item/armor/StandardArmor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package supersymmetry.common.item.armor;

import gregtech.api.items.metaitem.stats.IItemDurabilityManager;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import supersymmetry.api.items.IStandardArmorLogic;
import supersymmetry.client.renderer.handler.ITextureRegistrar;

import java.util.ArrayList;
import java.util.List;

import static net.minecraft.inventory.EntityEquipmentSlot.CHEST;
import static supersymmetry.api.util.SuSyUtility.susyId;

public class StandardArmor implements ITextureRegistrar, IStandardArmorLogic {
@SideOnly(Side.CLIENT)
protected ModelBiped Model;
private final String name;
private final int tier;
protected final EntityEquipmentSlot SLOT;

public StandardArmor(EntityEquipmentSlot slot, String name, int tier) {
SLOT = slot;
this.name = name;
this.tier = tier;
}

@Override
public EntityEquipmentSlot getEquipmentSlot(ItemStack itemstack) {return SLOT;}

@Override
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) {
return "susy:textures/armor/" + name + "_" + slot.getName() + ".png";
}

protected float getAbsorption(ItemStack itemStack) {
return getAbsorption(getEquipmentSlot(itemStack));
}

protected float getAbsorption(EntityEquipmentSlot slot) {
return switch (SLOT) {
case HEAD, FEET -> 0.15F;
case CHEST -> 0.4F;
case LEGS -> 0.3F;
default -> 0.0F;
};
}

@Override
@SideOnly(Side.CLIENT)
public List<ResourceLocation> getTextureLocations() {
List<ResourceLocation> models = new ArrayList<>();
models.add(susyId("armor/" + name + "_" + this.SLOT.toString()));
return models;
}

public void addInformation(ItemStack stack, List<String> tooltips) {
if (getEquipmentSlot(stack) == CHEST) {
tooltips.add(I18n.format("supersymmetry.steel_armor"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ public void registerSubItems() {
NOMEX_CHESTPLATE = addItem(15, "nomex_chestplate").setArmorLogic(new AdvancedBreathingTank(0, "nomex", 1, 0.6, AdvancedBreathingTank.INFINITE_OXYGEN));
NOMEX_LEGGINGS = addItem(16, "nomex_leggings").setArmorLogic(new AdvancedBreathingApparatus(LEGS, 0, "nomex", 1, 0.6));
NOMEX_BOOTS = addItem(17, "nomex_boots").setArmorLogic(new AdvancedBreathingApparatus(FEET, 0, "nomex", 1, 0.6));
STEEL_HELMET = addItem(18, "steel_helmet").setArmorLogic(new StandardArmor(HEAD, "steel", 1));
STEEL_CHESTPLATE = addItem(19, "steel_chestplate").setArmorLogic(new StandardArmor(CHEST, "steel", 1));
COTTON_PANTS = addItem(20, "cotton_pants").setArmorLogic(new StandardArmor(LEGS, "cotton", 1));
TRENCH_BOOTS = addItem(21, "trench_boots").setArmorLogic(new StandardArmor(FEET, "trench", 1));
}
}
Loading