2018-12-01 18:56:05 +01:00
|
|
|
package de.ellpeck.naturesaura.items.tools;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.Helper;
|
2019-11-04 19:08:49 +01:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2018-12-01 18:56:05 +01:00
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
|
|
|
import de.ellpeck.naturesaura.reg.IModItem;
|
|
|
|
import de.ellpeck.naturesaura.reg.IModelProvider;
|
2020-01-22 01:32:26 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.ModRegistry;
|
2018-12-01 18:56:05 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.inventory.EquipmentSlotType;
|
|
|
|
import net.minecraft.item.ArmorItem;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.item.IArmorMaterial;
|
|
|
|
import net.minecraft.item.Item;
|
2018-12-01 18:56:05 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
|
|
|
import net.minecraft.potion.EffectInstance;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.potion.Effects;
|
2018-12-01 18:56:05 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2018-12-01 18:56:05 +01:00
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-01-26 01:41:49 +01:00
|
|
|
public class ItemArmor extends ArmorItem implements IModItem, IModelProvider {
|
2018-12-01 18:56:05 +01:00
|
|
|
|
|
|
|
private static List<Item[]> sets;
|
|
|
|
private final String baseName;
|
|
|
|
|
2020-01-26 01:41:49 +01:00
|
|
|
public ItemArmor(String baseName, IArmorMaterial materialIn, EquipmentSlotType equipmentSlotIn) {
|
2019-11-04 19:08:49 +01:00
|
|
|
super(materialIn, equipmentSlotIn, new Properties().group(NaturesAura.CREATIVE_TAB));
|
2018-12-01 18:56:05 +01:00
|
|
|
this.baseName = baseName;
|
2020-01-24 20:49:09 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
2020-01-22 01:32:26 +01:00
|
|
|
ModRegistry.add(this);
|
2018-12-01 18:56:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return this.baseName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) {
|
2018-12-01 18:56:05 +01:00
|
|
|
return Helper.makeRechargeProvider(stack, false);
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
public static boolean isFullSetEquipped(LivingEntity entity, int setIndex) {
|
2018-12-01 18:56:05 +01:00
|
|
|
if (sets == null) {
|
|
|
|
sets = new ArrayList<>();
|
2020-01-23 19:20:47 +01:00
|
|
|
sets.add(new Item[]{ModItems.INFUSED_IRON_SHOES, ModItems.INFUSED_IRON_PANTS, ModItems.INFUSED_IRON_CHEST, ModItems.INFUSED_IRON_HELMET});
|
2018-12-01 18:56:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Item[] set = sets.get(setIndex);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2019-10-20 22:30:49 +02:00
|
|
|
EquipmentSlotType slot = EquipmentSlotType.values()[i + 2];
|
2018-12-01 18:56:05 +01:00
|
|
|
ItemStack stack = entity.getItemStackFromSlot(slot);
|
|
|
|
if (stack.isEmpty() || stack.getItem() != set[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-24 20:49:09 +01:00
|
|
|
|
|
|
|
private static class EventHandler {
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onAttack(LivingAttackEvent event) {
|
|
|
|
LivingEntity entity = event.getEntityLiving();
|
|
|
|
if (!entity.world.isRemote) {
|
|
|
|
if (!isFullSetEquipped(entity, 0))
|
|
|
|
return;
|
|
|
|
Entity source = event.getSource().getTrueSource();
|
|
|
|
if (source instanceof LivingEntity)
|
|
|
|
((LivingEntity) source).addPotionEffect(new EffectInstance(Effects.WITHER, 40));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-01 18:56:05 +01:00
|
|
|
}
|