Mekanism-tilera-Edition/common/buildcraft/api/gates/TriggerParameter.java

80 lines
1.8 KiB
Java
Raw Normal View History

2013-04-13 16:35:13 +02:00
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.gates;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class TriggerParameter implements ITriggerParameter {
protected ItemStack stack;
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#getItemStack()
*/
@Override
public ItemStack getItemStack() {
return stack;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#set(net.minecraft.src.ItemStack)
*/
@Override
public void set(ItemStack stack) {
if (stack != null) {
this.stack = stack.copy();
this.stack.stackSize = 1;
}
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#writeToNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void writeToNBT(NBTTagCompound compound) {
if (stack != null) {
2013-12-26 21:00:08 +01:00
NBTTagCompound tagCompound = new NBTTagCompound();
stack.writeToNBT(tagCompound);
compound.setCompoundTag("stack", tagCompound);
2013-04-13 16:35:13 +02:00
}
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#readFromNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void readFromNBT(NBTTagCompound compound) {
2013-12-26 21:00:08 +01:00
// Legacy code to prevent existing gates from losing their contents
2013-04-13 16:35:13 +02:00
int itemID = compound.getInteger("itemID");
if (itemID != 0) {
stack = new ItemStack(itemID, 1, compound.getInteger("itemDMG"));
2013-12-26 21:00:08 +01:00
return;
2013-04-13 16:35:13 +02:00
}
2013-12-26 21:00:08 +01:00
stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack"));
2013-04-13 16:35:13 +02:00
}
@Override
@Deprecated
2013-04-13 16:35:13 +02:00
public ItemStack getItem() {
return stack;
}
}