diff --git a/src/main/java/cr0s/warpdrive/api/IParticleContainerItem.java b/src/main/java/cr0s/warpdrive/api/IParticleContainerItem.java index 32898594..70e78718 100644 --- a/src/main/java/cr0s/warpdrive/api/IParticleContainerItem.java +++ b/src/main/java/cr0s/warpdrive/api/IParticleContainerItem.java @@ -4,18 +4,21 @@ import net.minecraft.item.ItemStack; public interface IParticleContainerItem { - ParticleStack getParticleStack(ItemStack container); + String TAG_PARTICLE = "particle"; + String TAG_AMOUNT_TO_CONSUME = "amountToConsume"; - int getCapacity(ItemStack container); + ParticleStack getParticleStack(final ItemStack container); - boolean isEmpty(ItemStack container); + int getCapacity(final ItemStack container); + + boolean isEmpty(final ItemStack container); // fills the container and return how much could be transferred or 0 if container is empty or contains different particles - int fill(ItemStack container, ParticleStack resource, boolean doFill); + int fill(final ItemStack container, final ParticleStack resource, final boolean doFill); // drains the container and return how much could be transferred or null if container is empty or contains different particles - ParticleStack drain(ItemStack container, ParticleStack resource, boolean doDrain); + ParticleStack drain(final ItemStack container, final ParticleStack resource, final boolean doDrain); // called during recipe match to set amount to consume in next call to getContainerItem - void setAmountToConsume(ItemStack container, int amount); + void setAmountToConsume(final ItemStack container, final int amount); } \ No newline at end of file diff --git a/src/main/java/cr0s/warpdrive/item/ItemElectromagneticCell.java b/src/main/java/cr0s/warpdrive/item/ItemElectromagneticCell.java index fb00275b..ab8e03ca 100644 --- a/src/main/java/cr0s/warpdrive/item/ItemElectromagneticCell.java +++ b/src/main/java/cr0s/warpdrive/item/ItemElectromagneticCell.java @@ -32,8 +32,6 @@ import net.minecraftforge.fml.relauncher.SideOnly; public class ItemElectromagneticCell extends ItemAbstractBase implements IParticleContainerItem { - private static final String AMOUNT_TO_CONSUME_TAG = "amountToConsume"; - public ItemElectromagneticCell(final String registryName) { super(registryName); @@ -75,7 +73,7 @@ public class ItemElectromagneticCell extends ItemAbstractBase implements IPartic if (particle != null && amount != 0) { particleStack = new ParticleStack(particle, amount); final NBTTagCompound tagCompound = new NBTTagCompound(); - tagCompound.setTag("particle", particleStack.writeToNBT(new NBTTagCompound())); + tagCompound.setTag(IParticleContainerItem.TAG_PARTICLE, particleStack.writeToNBT(new NBTTagCompound())); itemStack.setTagCompound(tagCompound); } updateDamageLevel(itemStack, particleStack); @@ -130,13 +128,13 @@ public class ItemElectromagneticCell extends ItemAbstractBase implements IPartic if (tagCompound == null) { tagCompound = new NBTTagCompound(); } - tagCompound.setInteger(AMOUNT_TO_CONSUME_TAG, amountToConsume); + tagCompound.setInteger(IParticleContainerItem.TAG_AMOUNT_TO_CONSUME, amountToConsume); } private int getAmountToConsume(@Nonnull final ItemStack itemStack) { final NBTTagCompound tagCompound = itemStack.getTagCompound(); if (tagCompound != null) { - return tagCompound.getInteger(AMOUNT_TO_CONSUME_TAG); + return tagCompound.getInteger(IParticleContainerItem.TAG_AMOUNT_TO_CONSUME); } return 0; } @@ -170,10 +168,10 @@ public class ItemElectromagneticCell extends ItemAbstractBase implements IPartic if (tagCompound == null) { return null; } - if (!tagCompound.hasKey("particle")) { + if (!tagCompound.hasKey(IParticleContainerItem.TAG_PARTICLE)) { return null; } - return ParticleStack.loadFromNBT(tagCompound.getCompoundTag("particle")); + return ParticleStack.loadFromNBT(tagCompound.getCompoundTag(IParticleContainerItem.TAG_PARTICLE)); } @Override @@ -201,7 +199,7 @@ public class ItemElectromagneticCell extends ItemAbstractBase implements IPartic final NBTTagCompound tagCompound = itemStack.hasTagCompound() ? itemStack.getTagCompound() : new NBTTagCompound(); assert tagCompound != null; - tagCompound.setTag("particle", particleStack.writeToNBT(new NBTTagCompound())); + tagCompound.setTag(IParticleContainerItem.TAG_PARTICLE, particleStack.writeToNBT(new NBTTagCompound())); if (!itemStack.hasTagCompound()) { itemStack.setTagCompound(tagCompound); } @@ -225,7 +223,7 @@ public class ItemElectromagneticCell extends ItemAbstractBase implements IPartic final NBTTagCompound tagCompound = itemStack.hasTagCompound() ? itemStack.getTagCompound() : new NBTTagCompound(); assert tagCompound != null; - tagCompound.setTag("particle", particleStack.writeToNBT(new NBTTagCompound())); + tagCompound.setTag(IParticleContainerItem.TAG_PARTICLE, particleStack.writeToNBT(new NBTTagCompound())); if (!itemStack.hasTagCompound()) { itemStack.setTagCompound(tagCompound); }