Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arctic.paperArmor.items;
- import com.arctic.paperArmor.handlers.Inscriptions;
- import com.arctic.paperArmor.init.ModItems;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Items;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemArmor;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.ChatComponentText;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.IChatComponent;
- import net.minecraft.world.World;
- import net.minecraftforge.common.ISpecialArmor;
- import java.util.List;
- public class ItemArmorPaper extends ItemArmorPA implements ISpecialArmor{
- public ItemArmorPaper(int armorType) {
- super("paper", paper, armorType);
- }
- private final int water = 20;
- private final int fire = 10;
- private final int[] armorCounts = {5,8,7,4};
- private final int[] armorSlots = {3,2,1,0};
- @Override
- public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot) {
- return new ArmorProperties(0, ((ItemArmor)armor.getItem()).damageReduceAmount / 25D , armor.getMaxDamage() + 1 - armor.getItemDamage());
- }
- @Override
- public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
- return ((ItemArmor)armor.getItem()).damageReduceAmount;
- }
- @Override
- public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) {
- if (!source.isFireDamage())
- stack.damageItem(damage,entity);
- }
- protected enum Damage{
- water(Items.string,"water"),
- fire(null,"fire"),
- generic(Items.paper,null);
- Item drop;
- String msg;
- Damage(Item drop, String msg){
- this.drop = drop;
- this.msg = msg;
- }
- }
- @Override
- public void onArmorTick(World world, EntityPlayer player, ItemStack stack) {
- super.onArmorTick(world, player, stack);
- if (!world.isRemote) {
- if (stack.hasTagCompound()) {
- if (player.isWet()){
- if (stack.getTagCompound().hasKey("WetTick")){
- wetTick(player, stack);
- } else {
- stack.getTagCompound().setInteger("WetTick", water);
- }
- } else if (player.isBurning()){
- if (stack.getTagCompound().hasKey("FireTick")){
- fireTick(player, stack);
- } else {
- stack.getTagCompound().setInteger("FireTick", fire);
- }
- }
- for (Inscriptions inscription : Inscriptions.values()) {
- if (Inscriptions.hasInscription(stack,inscription)){
- Inscriptions.applyInscription(player,stack,inscription);
- }
- }
- } else {
- stack.setTagCompound(new NBTTagCompound());
- }
- }
- }
- private void breakPaper(EntityPlayer player, ItemStack stack){
- int amount = armorCounts[armorType];
- ItemStack stackDrop = new ItemStack(Items.paper,amount);
- EntityItem item = new EntityItem(player.worldObj,player.posX,player.posY,player.posZ);
- item.setEntityItemStack(stackDrop);
- player.worldObj.spawnEntityInWorld(item);
- }
- private void wetTick(EntityPlayer player, ItemStack stack){
- int wetTick = stack.getTagCompound().getInteger("WetTick");
- if (wetTick == 0) {
- damagePiece(player,stack,Damage.water);
- wetTick = water;
- } else wetTick--;
- stack.getTagCompound().setInteger("WetTick", wetTick);
- }
- private void fireTick(EntityPlayer player, ItemStack stack){
- int fireTick = stack.getTagCompound().getInteger("FireTick");
- if (fireTick == 0) {
- damagePiece(player,stack,Damage.fire);
- fireTick = fire;
- } else fireTick--;
- stack.getTagCompound().setInteger("FireTick", fireTick);
- }
- private void damagePiece(EntityPlayer player, ItemStack stack, Damage damage){
- stack.damageItem(1,player);
- if (stack.stackSize == 0){
- int amount = 0;
- if (player.getCurrentArmor(armorSlots[armorType])!=null) {
- //player.addChatComponentMessage(player.getCurrentArmor(armorSlots[armorType]).func_151000_E().appendText(" "+armorType));
- if (stack.getItem() == player.getCurrentArmor(armorSlots[armorType]).getItem()) {
- player.inventory.armorInventory[armorSlots[armorType]] = null;
- amount = armorCounts[armorType];
- }
- if (damage != null) {
- if (damage.msg != null) playBreakMSG(player, stack, damage.msg);
- if (damage.drop != null && amount > 0) {
- ItemStack stackDrop = new ItemStack(damage.drop, amount);
- EntityItem item = new EntityItem(player.worldObj, player.posX, player.posY, player.posZ);
- item.setEntityItemStack(stackDrop);
- player.worldObj.spawnEntityInWorld(item);
- }
- }
- }
- }
- }
- private void playBreakMSG(EntityPlayer player, ItemStack stack, String src){
- IChatComponent msg = stack.func_151000_E();
- msg.appendText(" It seams paper and "+src+" do not mix.");
- player.addChatComponentMessage(msg);
- }
- public int getDurabilityRemaining(ItemStack stack){
- return stack.getMaxDamage()-stack.getItemDamage();
- }
- @Override
- public boolean requiresMultipleRenderPasses() {
- return super.requiresMultipleRenderPasses();
- }
- @Override
- public int getRenderPasses(int metadata) {
- return super.getRenderPasses(metadata);
- }
- @Override
- public boolean hasEffect(ItemStack stack, int pass) {
- return super.hasEffect(stack, pass);
- }
- @Override
- public boolean hasEffect(ItemStack stack) {
- for (Inscriptions inscription : Inscriptions.values())
- if (Inscriptions.hasInscription(stack,inscription))
- return true;
- return false;
- }
- @Override
- public void addInformation(ItemStack stack, EntityPlayer player, List info, boolean bool) {
- for (Inscriptions inscription : Inscriptions.values()) {
- if (Inscriptions.hasInscription(stack, inscription)) {
- info.add("Inscribed with " + inscription.name().toLowerCase());
- }
- }
- }
- @Override
- public boolean getIsRepairable(ItemStack armor, ItemStack repair) {
- return repair.getItem() == ModItems.lacedPaperTile;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement