diff options
author | Alkalus <draknyte1@hotmail.com> | 2017-09-22 12:26:39 +1000 |
---|---|---|
committer | Alkalus <draknyte1@hotmail.com> | 2017-09-22 12:26:39 +1000 |
commit | bc74aaa35b726899e5830425eb7a8fb5e54501e8 (patch) | |
tree | 5c00ace3c3a5444ab9c60e5d0fbb58ede33d4d67 /src/Java/gtPlusPlus/core/tileentities | |
parent | eb0d3d0dee604e3eeff9c496b0bc4d374598a69e (diff) | |
download | GT5-Unofficial-bc74aaa35b726899e5830425eb7a8fb5e54501e8.tar.gz GT5-Unofficial-bc74aaa35b726899e5830425eb7a8fb5e54501e8.tar.bz2 GT5-Unofficial-bc74aaa35b726899e5830425eb7a8fb5e54501e8.zip |
+ Added a framework for a Trade-o-Mat alike device.
Diffstat (limited to 'src/Java/gtPlusPlus/core/tileentities')
-rw-r--r-- | src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java | 2 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java | 168 |
2 files changed, 170 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java index 2e644d6f9b..6d089ee29c 100644 --- a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java +++ b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java @@ -3,6 +3,7 @@ package gtPlusPlus.core.tileentities; import cpw.mods.fml.common.registry.GameRegistry; import gtPlusPlus.core.tileentities.general.*; import gtPlusPlus.core.tileentities.machines.TileEntityProjectTable; +import gtPlusPlus.core.tileentities.machines.TileEntityTradeTable; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbench; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbenchAdvanced; import gtPlusPlus.core.util.Utils; @@ -23,6 +24,7 @@ public class ModTileEntities { GameRegistry.registerTileEntity(TileEntityFirepit.class, "TileFirePit"); GameRegistry.registerTileEntity(TileEntityInfiniteFluid.class, "TileInfiniteFluid"); GameRegistry.registerTileEntity(TileEntityProjectTable.class, "TileProjectTable"); + GameRegistry.registerTileEntity(TileEntityTradeTable.class, "TileTradeTable"); } } diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java new file mode 100644 index 0000000000..b3ed225e31 --- /dev/null +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java @@ -0,0 +1,168 @@ +package gtPlusPlus.core.tileentities.machines; + +import java.util.List; +import java.util.Vector; + +import gtPlusPlus.core.container.Container_ProjectTable; +import gtPlusPlus.core.container.Container_TradeTable; +import gtPlusPlus.core.inventories.*; +import gtPlusPlus.core.inventories.projecttable.InventoryProjectMain; +import gtPlusPlus.core.inventories.projecttable.InventoryProjectOutput; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.nbt.NBTUtils; +import ic2.api.network.INetworkDataProvider; +import ic2.api.network.INetworkUpdateListener; +import ic2.api.tile.IWrenchable; +import ic2.core.IC2; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCraftResult; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; + +public class TileEntityTradeTable extends TileEntity implements INetworkDataProvider, INetworkUpdateListener, IWrenchable{ + + public InventoryProjectMain inventoryGrid; + public InventoryProjectOutput inventoryOutputs; + + /** The crafting matrix inventory (3x3). */ + public InventoryCrafting craftMatrix; + public IInventory craftResult; + private Container_TradeTable container; + + public TileEntityTradeTable(){ + this.inventoryGrid = new InventoryProjectMain();//number of slots - without product slot + this.inventoryOutputs = new InventoryProjectOutput();//number of slots - without product slot + this.canUpdate(); + } + + public void setContainer(Container_TradeTable container_TradeTable){ + this.container = container_TradeTable; + } + + @SuppressWarnings("static-method") + public NBTTagCompound getTag(final NBTTagCompound nbt, final String tag){ + if(!nbt.hasKey(tag)) + { + nbt.setTag(tag, new NBTTagCompound()); + } + return nbt.getCompoundTag(tag); + } + + @Override + public void writeToNBT(final NBTTagCompound nbt){ + super.writeToNBT(nbt); + nbt.setShort("facing", this.facing); + this.inventoryGrid.writeToNBT(this.getTag(nbt, "ContentsGrid")); + this.inventoryOutputs.writeToNBT(this.getTag(nbt, "ContentsOutput")); + + } + + @Override + public void readFromNBT(final NBTTagCompound nbt){ + super.readFromNBT(nbt); + this.prevFacing = (this.facing = nbt.getShort("facing")); + this.inventoryGrid.readFromNBT(nbt.getCompoundTag("ContentsGrid")); + this.inventoryOutputs.readFromNBT(nbt.getCompoundTag("ContentsOutput")); + } + + @Override + public List<String> getNetworkedFields(){ + final List<String> ret = new Vector(2); + ret.add("facing"); + return ret; + } + + + @Override + public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final int side){ + return false; + } + + private short facing = 0; + public short prevFacing = 0; + + @Override + public void setFacing(final short facing1){ + this.facing = facing1; + if (this.prevFacing != facing1) { + IC2.network.get().updateTileEntityField(this, "facing"); + } + this.prevFacing = facing1; + } + + @Override + public short getFacing(){ + return this.facing; + } + + + @Override + public boolean wrenchCanRemove(final EntityPlayer entityPlayer){ + return true; + } + + @Override + public float getWrenchDropRate(){ + return 1.0F; + } + + @Override + public ItemStack getWrenchDrop(final EntityPlayer entityPlayer){ + return new ItemStack(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord), 1, this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + } + + @Override + public void onNetworkUpdate(final String field) { + this.prevFacing = this.facing; + + } + + @Override + public void updateEntity() { + + //Data stick + ItemStack dataStick = this.inventoryOutputs.getStackInSlot(0); + if (dataStick != null && this.container != null){ + Utils.LOG_WARNING("Found Data Stick and valid container."); + + + ItemStack outputComponent = container.getOutputContent(); + ItemStack[] craftInputComponent = container.getInputComponents(); + + + ItemStack newStick = NBTUtils.writeItemsToNBT(dataStick, new ItemStack[]{outputComponent}, "Output"); + newStick = NBTUtils.writeItemsToNBT(newStick, craftInputComponent); + NBTUtils.setBookTitle(newStick, "Encrypted Project Data"); + int slotm=0; + Utils.LOG_WARNING("Uploading to Data Stick."); + for (ItemStack is : NBTUtils.readItemsFromNBT(newStick)){ + if (is != null){ + Utils.LOG_WARNING("Uploaded "+is.getDisplayName()+" into memory slot "+slotm+"."); + } + else { + Utils.LOG_WARNING("Left memory slot "+slotm+" blank."); + } + slotm++; + } + Utils.LOG_WARNING("Encrypting Data Stick."); + this.inventoryOutputs.setInventorySlotContents(1, newStick); + this.inventoryOutputs.setInventorySlotContents(0, null); + } + super.updateEntity(); + } + + @Override + public boolean canUpdate() { + return true; + } + + + + + +}
\ No newline at end of file |