Skip to content
Closed
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
23 changes: 1 addition & 22 deletions src/main/java/gregtech/api/items/armor/ArmorLogicSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IElectricItem;
import gregtech.api.items.armor.ArmorMetaItem.ArmorMetaValueItem;
import gregtech.api.items.metaitem.ElectricStats;
import gregtech.api.items.metaitem.stats.IItemHUDProvider;

import net.minecraft.client.resources.I18n;
Expand All @@ -22,6 +20,7 @@

import java.util.List;

@Deprecated
public abstract class ArmorLogicSuite implements ISpecialArmorLogic, IItemHUDProvider {

protected final int energyPerUse;
Expand Down Expand Up @@ -63,22 +62,6 @@ public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
}
}

@Override
public void addToolComponents(ArmorMetaValueItem mvi) {
mvi.addComponents(new ElectricStats(maxCapacity, tier, true, false) {

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

@Override
public void addInformation(ItemStack itemStack, List<String> lines) {
addInfo(itemStack, lines);
}
});
}

public void addInfo(ItemStack itemStack, List<String> lines) {
int armor = (int) Math.round(20.0F * this.getAbsorption(itemStack) * this.getDamageAbsorption());
if (armor > 0)
Expand Down Expand Up @@ -129,10 +112,6 @@ public boolean shouldDrawHUD() {
return this.SLOT == EntityEquipmentSlot.CHEST;
}

public int getEnergyPerUse() {
return this.energyPerUse;
}

protected float getAbsorption(ItemStack itemStack) {
switch (this.getEquipmentSlot(itemStack)) {
case HEAD:
Expand Down
167 changes: 38 additions & 129 deletions src/main/java/gregtech/api/items/armor/ArmorMetaItem.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
package gregtech.api.items.armor;

import gregtech.api.items.metaitem.MetaItem;
import gregtech.api.items.metaitem.stats.IEnchantabilityHelper;
import gregtech.api.items.metaitem.stats.IItemComponent;
import gregtech.common.creativetab.GTCreativeTabs;

import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.ISpecialArmor;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import com.google.common.base.Preconditions;
import com.google.common.collect.Multimap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ArmorMetaItem<T extends ArmorMetaItem<?>.ArmorMetaValueItem> extends MetaItem<T>
implements IArmorItem, ISpecialArmor, IEnchantabilityHelper {
import java.util.List;

@Deprecated
public class ArmorMetaItem<T extends ArmorMetaItem<?>.ArmorMetaValueItem> extends MetaItem<T> implements ISpecialArmor {

public ArmorMetaItem() {
super((short) 0);
Expand All @@ -45,68 +38,30 @@ protected T constructMetaValueItem(short metaValue, String unlocalizedName) {
@NotNull
private IArmorLogic getArmorLogic(ItemStack itemStack) {
T metaValueItem = getItem(itemStack);
return metaValueItem == null ? new DummyArmorLogic() : metaValueItem.getArmorLogic();
}

@NotNull
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(@NotNull EntityEquipmentSlot slot,
@NotNull ItemStack stack) {
Multimap<String, AttributeModifier> multimap = super.getAttributeModifiers(slot, stack);
IArmorLogic armorLogic = getArmorLogic(stack);
multimap.putAll(armorLogic.getAttributeModifiers(slot, stack));
return multimap;
return metaValueItem == null ? new DummyArmorLogic(EntityEquipmentSlot.HEAD, "") :
metaValueItem.getArmorLogic();
}

@Override
public ArmorProperties getProperties(EntityLivingBase player, @NotNull ItemStack armor, DamageSource source,
double damage, int slot) {
IArmorLogic armorLogic = getArmorLogic(armor);
if (armorLogic instanceof ISpecialArmorLogic) {
return ((ISpecialArmorLogic) armorLogic).getProperties(player, armor, source, damage, getSlotByIndex(slot));
}
return new ArmorProperties(0, 0, Integer.MAX_VALUE);
}

@Override
public int getArmorDisplay(EntityPlayer player, @NotNull ItemStack armor, int slot) {
IArmorLogic armorLogic = getArmorLogic(armor);
if (armorLogic instanceof ISpecialArmorLogic) {
return ((ISpecialArmorLogic) armorLogic).getArmorDisplay(player, armor, slot);
}
return 0;
}

@Override
public void damageArmor(EntityLivingBase entity, @NotNull ItemStack stack, DamageSource source, int damage,
int slot) {
IArmorLogic armorLogic = getArmorLogic(stack);
armorLogic.damageArmor(entity, stack, source, damage, getSlotByIndex(slot));
}

@Override
public boolean handleUnblockableDamage(EntityLivingBase entity, @NotNull ItemStack armor, DamageSource source,
double damage, int slot) {
IArmorLogic armorLogic = getArmorLogic(armor);
if (armorLogic instanceof ISpecialArmorLogic) {
return ((ISpecialArmorLogic) armorLogic).handleUnblockableDamage(entity, armor, source, damage,
getSlotByIndex(slot));
}
return false;
}

@Override
public void onArmorTick(@NotNull World world, @NotNull EntityPlayer player, @NotNull ItemStack itemStack) {
IArmorLogic armorLogic = getArmorLogic(itemStack);
armorLogic.onArmorTick(world, player, itemStack);
}
int slot) {}

@Override
public boolean isValidArmor(@NotNull ItemStack stack, @NotNull EntityEquipmentSlot armorType,
@NotNull Entity entity) {
IArmorLogic armorLogic = getArmorLogic(stack);
return super.isValidArmor(stack, armorType, entity) &&
armorLogic.isValidArmor(stack, entity, armorType);
return super.isValidArmor(stack, armorType, entity) && armorLogic.getEquipmentSlot(stack) == armorType;
}

@Nullable
Expand All @@ -124,50 +79,20 @@ public String getArmorTexture(@NotNull ItemStack stack, @NotNull Entity entity,
return armorLogic.getArmorTexture(stack, entity, slot, type);
}

@Nullable
@Override
@SideOnly(Side.CLIENT)
public ModelBiped getArmorModel(@NotNull EntityLivingBase entityLiving, @NotNull ItemStack itemStack,
@NotNull EntityEquipmentSlot armorSlot, @NotNull ModelBiped _default) {
IArmorLogic armorLogic = getArmorLogic(itemStack);
return armorLogic.getArmorModel(entityLiving, itemStack, armorSlot, _default);
public void addInformation(@NotNull ItemStack itemStack, @Nullable World worldIn, @NotNull List<String> lines,
@NotNull ITooltipFlag tooltipFlag) {
lines.add(TextFormatting.RED + "Deprecated Item! Convert in an Assembler to get the new version"); // todo lang
}

@Override
public int getArmorLayersAmount(ItemStack itemStack) {
IArmorLogic armorLogic = getArmorLogic(itemStack);
return armorLogic.getArmorLayersAmount(itemStack);
}

@Override
public int getArmorLayerColor(ItemStack itemStack, int layerIndex) {
IArmorLogic armorLogic = getArmorLogic(itemStack);
return armorLogic.getArmorLayerColor(itemStack, layerIndex);
}

@Override
public void renderHelmetOverlay(@NotNull ItemStack stack, @NotNull EntityPlayer player,
@NotNull ScaledResolution resolution, float partialTicks) {
IArmorLogic armorLogic = getArmorLogic(stack);
armorLogic.renderHelmetOverlay(stack, player, resolution, partialTicks);
}

private static EntityEquipmentSlot getSlotByIndex(int index) {
switch (index) {
case 0:
return EntityEquipmentSlot.FEET;
case 1:
return EntityEquipmentSlot.LEGS;
case 2:
return EntityEquipmentSlot.CHEST;
default:
return EntityEquipmentSlot.HEAD;
}
public boolean isEnchantable(@NotNull ItemStack stack) {
return false;
}

public class ArmorMetaValueItem extends MetaValueItem {

private IArmorLogic armorLogic = new DummyArmorLogic();
private IArmorLogic armorLogic;

protected ArmorMetaValueItem(int metaValue, String unlocalizedName) {
super(metaValue, unlocalizedName);
Expand All @@ -179,63 +104,47 @@ public IArmorLogic getArmorLogic() {
return armorLogic;
}

public ArmorMetaValueItem setArmorLogic(IArmorLogic armorLogic) {
Preconditions.checkNotNull(armorLogic, "Cannot set ArmorLogic to null");
this.armorLogic = armorLogic;
this.armorLogic.addToolComponents(this);
public ArmorMetaValueItem setArmorLogic(EntityEquipmentSlot slot, String armorTextureName) {
this.armorLogic = new DummyArmorLogic(slot, armorTextureName);
return this;
}

@Override
public ArmorMetaValueItem addComponents(IItemComponent... stats) {
super.addComponents(stats);
public ArmorMetaValueItem setArmorLogic(IArmorLogic armorLogic) {
Preconditions.checkNotNull(armorLogic, "Cannot set ArmorLogic to null");
this.armorLogic = armorLogic;
return this;
}

@Override
public ArmorMetaValueItem setModelAmount(int modelAmount) {
return (ArmorMetaValueItem) super.setModelAmount(modelAmount);
public ArmorMetaValueItem setRarity(EnumRarity rarity) {
return (ArmorMetaValueItem) super.setRarity(rarity);
}

@Override
public ArmorMetaValueItem setRarity(EnumRarity rarity) {
return (ArmorMetaValueItem) super.setRarity(rarity);
public ArmorMetaValueItem setInvisible() {
super.setInvisible();
return this;
}
}

@Override
public boolean isEnchantable(@NotNull ItemStack stack) {
return true;
}
private static class DummyArmorLogic implements IArmorLogic {

@Override
public int getItemEnchantability(@NotNull ItemStack stack) {
return 50;
}
private final EntityEquipmentSlot slot;
private final String armorTextureName;

@Override
public boolean canApplyAtEnchantingTable(@NotNull ItemStack stack, @NotNull Enchantment enchantment) {
EntityEquipmentSlot slot = this.getEquipmentSlot(stack);
if (slot == null || enchantment.type == null) {
return false;
public DummyArmorLogic(EntityEquipmentSlot slot, String armorTextureName) {
this.slot = slot;
this.armorTextureName = armorTextureName;
}

IArmorLogic armorLogic = getArmorLogic(stack);
if (!armorLogic.canBreakWithDamage(stack) && enchantment.type == EnumEnchantmentType.BREAKABLE) {
return false;
@Override
public EntityEquipmentSlot getEquipmentSlot(ItemStack itemStack) {
return slot;
}

switch (slot) {
case HEAD:
return enchantment.type.canEnchantItem(Items.DIAMOND_HELMET);
case CHEST:
return enchantment.type.canEnchantItem(Items.DIAMOND_CHESTPLATE);
case LEGS:
return enchantment.type.canEnchantItem(Items.DIAMOND_LEGGINGS);
case FEET:
return enchantment.type.canEnchantItem(Items.DIAMOND_BOOTS);
default:
return enchantment.isAllowedOnBooks();
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) {
return String.format("gregtech:textures/items/armors/%s.png", armorTextureName);
}
}
}
Loading
Loading