diff options
author | kekzdealer <kekzdealer@gmail.com> | 2019-12-10 11:36:39 +0100 |
---|---|---|
committer | kekzdealer <kekzdealer@gmail.com> | 2019-12-10 11:36:39 +0100 |
commit | c7329fe829f69f4585837a5f483dab064d57774f (patch) | |
tree | 73d512a3afa641f989df2c155949296dbfd383f0 /src/main | |
parent | f9eac626254ed31477925618a45af5005e4628ac (diff) | |
download | GT5-Unofficial-c7329fe829f69f4585837a5f483dab064d57774f.tar.gz GT5-Unofficial-c7329fe829f69f4585837a5f483dab064d57774f.tar.bz2 GT5-Unofficial-c7329fe829f69f4585837a5f483dab064d57774f.zip |
visiting Lucy~
Diffstat (limited to 'src/main')
31 files changed, 896 insertions, 460 deletions
diff --git a/src/main/java/blocks/Block_ItemDistributionNode.java b/src/main/java/blocks/Block_ItemDistributionNode.java deleted file mode 100644 index 07fd988445..0000000000 --- a/src/main/java/blocks/Block_ItemDistributionNode.java +++ /dev/null @@ -1,55 +0,0 @@ -package blocks; - -import cpw.mods.fml.common.registry.GameRegistry; -import itemBlocks.IB_ItemDistributionNode; -import kekztech.KekzCore; -import net.minecraft.block.BlockContainer; -import net.minecraft.block.material.Material; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import tileentities.TE_ItemDistributionNode; - -public class Block_ItemDistributionNode extends BlockContainer { - - private static Block_ItemDistributionNode instance = new Block_ItemDistributionNode(); - - private Block_ItemDistributionNode() { - super(Material.glass); - } - - public static Block_ItemDistributionNode getInstance() { - return instance; - } - - public void registerBlock() { - final String blockName = "kekztech_itemdistributionnode_block"; - super.setBlockName(blockName); - super.setCreativeTab(CreativeTabs.tabMisc); - super.setBlockTextureName(KekzCore.MODID + ":" + "ItemDistributionNode"); - super.setHardness(3.0f); - super.setResistance(2.0f); - GameRegistry.registerBlock(getInstance(), IB_ItemDistributionNode.class, blockName); - } - - @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float lx, float ly, float lz) { - if(world.isRemote) { - return true; - } - - final TileEntity te = world.getTileEntity(x, y, z); - if(te != null && te instanceof TE_ItemDistributionNode) { - player.openGui(KekzCore.instance, 0, world, x, y, z); - return true; - } - return false; - } - - @Override - public TileEntity createNewTileEntity(World world, int p_149915_2_) { - return new TE_ItemDistributionNode(); - } - -} diff --git a/src/main/java/blocks/Block_ItemDistributionCable.java b/src/main/java/blocks/Block_ItemProxyCable.java index 3caefc313a..dee566bab7 100644 --- a/src/main/java/blocks/Block_ItemDistributionCable.java +++ b/src/main/java/blocks/Block_ItemProxyCable.java @@ -1,40 +1,45 @@ package blocks; import cpw.mods.fml.common.registry.GameRegistry; -import itemBlocks.IB_ItemDistributionCable; +import itemBlocks.IB_ItemProxyCable; import kekztech.KekzCore; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import tileentities.TE_ItemDistributionCable; +import tileentities.TE_ItemProxyCable; -public class Block_ItemDistributionCable extends BlockContainer { +public class Block_ItemProxyCable extends BlockContainer { - private static Block_ItemDistributionCable instance = new Block_ItemDistributionCable(); + private static Block_ItemProxyCable instance = new Block_ItemProxyCable(); - private Block_ItemDistributionCable() { + private Block_ItemProxyCable() { super(Material.glass); } - public static Block_ItemDistributionCable getInstance() { + public static Block_ItemProxyCable getInstance() { return instance; } public void registerBlock() { - final String blockName = "kekztech_itemdistributioncable_block"; + final String blockName = "kekztech_itemproxycable_block"; super.setBlockName(blockName); super.setCreativeTab(CreativeTabs.tabMisc); - super.setBlockTextureName(KekzCore.MODID + ":" + "ItemDistributionCable"); + super.setBlockTextureName(KekzCore.MODID + ":" + "TFFTCasing"); super.setHardness(3.0f); super.setResistance(2.0f); - GameRegistry.registerBlock(getInstance(), IB_ItemDistributionCable.class, blockName); + GameRegistry.registerBlock(getInstance(), IB_ItemProxyCable.class, blockName); + } + + @Override + public boolean isOpaqueCube() { + return false; } @Override public TileEntity createNewTileEntity(World world, int p_149915_2_) { - return new TE_ItemDistributionCable(); + return new TE_ItemProxyCable(); } } diff --git a/src/main/java/blocks/Block_ItemProxyEndpoint.java b/src/main/java/blocks/Block_ItemProxyEndpoint.java new file mode 100644 index 0000000000..762880c877 --- /dev/null +++ b/src/main/java/blocks/Block_ItemProxyEndpoint.java @@ -0,0 +1,69 @@ +package blocks; + +import java.util.UUID; + +import cpw.mods.fml.common.registry.GameRegistry; +import itemBlocks.IB_ItemProxyEndpoint; +import items.Item_Configurator; +import kekztech.GuiHandler; +import kekztech.KekzCore; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import tileentities.TE_ItemProxyEndpoint; + +public class Block_ItemProxyEndpoint extends BlockContainer { + + private static Block_ItemProxyEndpoint instance = new Block_ItemProxyEndpoint(); + + private Block_ItemProxyEndpoint() { + super(Material.glass); + } + + public static Block_ItemProxyEndpoint getInstance() { + return instance; + } + + public void registerBlock() { + final String blockName = "kekztech_itemproxyendpoint_block"; + super.setBlockName(blockName); + super.setCreativeTab(CreativeTabs.tabMisc); + super.setBlockTextureName(KekzCore.MODID + ":" + "ItemProxyEndpoint"); + super.setHardness(3.0f); + super.setResistance(2.0f); + GameRegistry.registerBlock(getInstance(), IB_ItemProxyEndpoint.class, blockName); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float lx, float ly, float lz) { + if(world.isRemote) { + return true; + } + + final TileEntity te = world.getTileEntity(x, y, z); + if(te != null && te instanceof TE_ItemProxyEndpoint) { + final TE_ItemProxyEndpoint endpoint = (TE_ItemProxyEndpoint) te; + if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() instanceof Item_Configurator) { + + final ItemStack held = player.inventory.getCurrentItem(); + if(held.hasTagCompound() && held.getTagCompound().hasKey("config")) { + endpoint.setChannel(UUID.fromString(held.getTagCompound().getString("config"))); + } + } else { + player.openGui(KekzCore.instance, GuiHandler.ITEM_PROXY_ENDPOINT, world, x, y, z); + } + return true; + } + return false; + } + + @Override + public TileEntity createNewTileEntity(World world, int p_149915_2_) { + return new TE_ItemProxyEndpoint(); + } + +}
\ No newline at end of file diff --git a/src/main/java/blocks/Block_ItemProxySource.java b/src/main/java/blocks/Block_ItemProxySource.java new file mode 100644 index 0000000000..b2cdd4a656 --- /dev/null +++ b/src/main/java/blocks/Block_ItemProxySource.java @@ -0,0 +1,69 @@ +package blocks; + +import cpw.mods.fml.common.registry.GameRegistry; +import itemBlocks.IB_ItemProxySource; +import items.Item_Configurator; +import kekztech.GuiHandler; +import kekztech.KekzCore; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import tileentities.TE_ItemProxySource; + +public class Block_ItemProxySource extends BlockContainer { + + private static Block_ItemProxySource instance = new Block_ItemProxySource(); + + private Block_ItemProxySource() { + super(Material.glass); + } + + public static Block_ItemProxySource getInstance() { + return instance; + } + + public void registerBlock() { + final String blockName = "kekztech_itemproxysource_block"; + super.setBlockName(blockName); + super.setCreativeTab(CreativeTabs.tabMisc); + super.setBlockTextureName(KekzCore.MODID + ":" + "ItemProxySource"); + super.setHardness(3.0f); + super.setResistance(2.0f); + GameRegistry.registerBlock(getInstance(), IB_ItemProxySource.class, blockName); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float lx, float ly, float lz) { + if(world.isRemote) { + return true; + } + + final TileEntity te = world.getTileEntity(x, y, z); + if(te != null && te instanceof TE_ItemProxySource) { + final TE_ItemProxySource source = (TE_ItemProxySource) te; + if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() instanceof Item_Configurator) { + + final NBTTagCompound configNBT = new NBTTagCompound(); + configNBT.setString("config", source.getChannel().toString()); + final ItemStack held = player.inventory.getCurrentItem(); + held.setTagCompound(configNBT); + + } else { + player.openGui(KekzCore.instance, GuiHandler.ITEM_PROXY_SOURCE, world, x, y, z); + } + return true; + } + return false; + } + + @Override + public TileEntity createNewTileEntity(World world, int p_149915_2_) { + return new TE_ItemProxySource(); + } + +} diff --git a/src/main/java/container/Container_ItemDistributionNode.java b/src/main/java/container/Container_ItemProxyEndpoint.java index 08096bc80f..5718943efe 100644 --- a/src/main/java/container/Container_ItemDistributionNode.java +++ b/src/main/java/container/Container_ItemProxyEndpoint.java @@ -2,25 +2,24 @@ package container; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import tileentities.TE_ItemDistributionNode; +import net.minecraft.tileentity.TileEntity; -public class Container_ItemDistributionNode extends Container { +public class Container_ItemProxyEndpoint extends Container { - private final TE_ItemDistributionNode te; + private final IInventory teInventory; private int slotID = 0; - public Container_ItemDistributionNode(TE_ItemDistributionNode te, EntityPlayer player) { - this.te = te; + public Container_ItemProxyEndpoint(TileEntity te, EntityPlayer player) { + this.teInventory = (IInventory) te; - // Networked Storage - for(int i = 0; i < 4; i++) { - for(int j = 0; j < 4; j++) { - super.addSlotToContainer(new Slot(te, slotID++, 18 * j + 20, 19 * i + 20)); - } - } + // Source Slot + addSlotToContainer(new Slot(teInventory, slotID++, 80, 35)); + // Config slot + addSlotToContainer(new Slot(teInventory, slotID++, 100, 35)); //Inventory for (int i = 0; i < 3; i++) { @@ -62,7 +61,8 @@ public class Container_ItemDistributionNode extends Container { @Override public boolean canInteractWith(EntityPlayer player) { - return te.isUseableByPlayer(player); + return teInventory.isUseableByPlayer(player); } } + diff --git a/src/main/java/container/Container_ItemProxySource.java b/src/main/java/container/Container_ItemProxySource.java new file mode 100644 index 0000000000..50facb4bf2 --- /dev/null +++ b/src/main/java/container/Container_ItemProxySource.java @@ -0,0 +1,80 @@ +package container; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +public class Container_ItemProxySource extends Container { + + private final IInventory teInventory; + + private int slotID = 0; + + public Container_ItemProxySource(TileEntity te, EntityPlayer player) { + this.teInventory = (IInventory) te; + + // Source Slots + addSlotToContainer(new Slot(teInventory, slotID++, 53, 8)); + addSlotToContainer(new Slot(teInventory, slotID++, 71, 8)); + addSlotToContainer(new Slot(teInventory, slotID++, 89, 8)); + addSlotToContainer(new Slot(teInventory, slotID++, 107, 8)); + addSlotToContainer(new Slot(teInventory, slotID++, 53, 26)); + addSlotToContainer(new Slot(teInventory, slotID++, 71, 26)); + addSlotToContainer(new Slot(teInventory, slotID++, 89, 26)); + addSlotToContainer(new Slot(teInventory, slotID++, 107, 26)); + addSlotToContainer(new Slot(teInventory, slotID++, 53, 44)); + addSlotToContainer(new Slot(teInventory, slotID++, 71, 44)); + addSlotToContainer(new Slot(teInventory, slotID++, 89, 44)); + addSlotToContainer(new Slot(teInventory, slotID++, 107, 44)); + addSlotToContainer(new Slot(teInventory, slotID++, 53, 62)); + addSlotToContainer(new Slot(teInventory, slotID++, 71, 62)); + addSlotToContainer(new Slot(teInventory, slotID++, 89, 62)); + addSlotToContainer(new Slot(teInventory, slotID++, 107, 62)); + + //Inventory + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 9; j++) { + addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + // Hotbar + for (int i = 0; i < 9; i++) { + addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142)); + } + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotRaw) { + ItemStack stack = null; + final Slot slot = (Slot) inventorySlots.get(slotRaw); + + if (slot != null && slot.getHasStack()) { + final ItemStack stackInSlot = slot.getStack(); + stack = stackInSlot.copy(); + + if (slotRaw < 3 * 9) { + if (!mergeItemStack(stackInSlot, 3 * 9, inventorySlots.size(), true)) { + return null; + } + } else if (!mergeItemStack(stackInSlot, 0, 3 * 9, false)) { + return null; + } + + if (stackInSlot.stackSize == 0) { + slot.putStack((ItemStack) null); + } else { + slot.onSlotChanged(); + } + } + return stack; + } + + @Override + public boolean canInteractWith(EntityPlayer player) { + return teInventory.isUseableByPlayer(player); + } + +} diff --git a/src/main/java/container/Gui_ItemProxyEndpoint.java b/src/main/java/container/Gui_ItemProxyEndpoint.java new file mode 100644 index 0000000000..0fb1b6e05b --- /dev/null +++ b/src/main/java/container/Gui_ItemProxyEndpoint.java @@ -0,0 +1,50 @@ +package container; + +import org.lwjgl.opengl.GL11; + +import kekztech.KekzCore; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; + +public class Gui_ItemProxyEndpoint extends GuiContainer { + + private final ResourceLocation texture = new ResourceLocation(KekzCore.MODID, "textures/gui/ItemTech1by1.png"); + + private final InventoryPlayer inventory; + private final IInventory te; + + public Gui_ItemProxyEndpoint(TileEntity te, EntityPlayer player) { + super(new Container_ItemProxyEndpoint(te, player)); + inventory = player.inventory; + this.te = (IInventory) te; + + } + + @Override + protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { + + Minecraft.getMinecraft().renderEngine.bindTexture(texture); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + final int x = (super.width - super.xSize) / 2; + final int y = (super.height - super.ySize) / 2; + + super.drawTexturedModalRect(x, y, 0, 0, super.xSize, super.ySize); + } + + @Override + protected void drawGuiContainerForegroundLayer(int p1, int p2) { + super.fontRendererObj.drawString( + I18n.format(te.getInventoryName()), + (super.xSize / 2) - (fontRendererObj.getStringWidth(I18n.format(te.getInventoryName())) / 2), + 6, 4210752, false); + super.fontRendererObj.drawString( + I18n.format(inventory.getInventoryName()), 8, super.ySize - 96 + 2, 4210752); + } +} diff --git a/src/main/java/container/Gui_ItemDistributionNode.java b/src/main/java/container/Gui_ItemProxySource.java index 08f530fce8..e72928f7ff 100644 --- a/src/main/java/container/Gui_ItemDistributionNode.java +++ b/src/main/java/container/Gui_ItemProxySource.java @@ -8,20 +8,21 @@ import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; -import tileentities.TE_ItemDistributionNode; -public class Gui_ItemDistributionNode extends GuiContainer { +public class Gui_ItemProxySource extends GuiContainer { - private final ResourceLocation texture = new ResourceLocation(KekzCore.MODID, "textures/gui/ItemDistributionNode.png"); + private final ResourceLocation texture = new ResourceLocation(KekzCore.MODID, "textures/gui/ItemTech4by4.png"); private final InventoryPlayer inventory; - private final TE_ItemDistributionNode te; + private final IInventory te; - public Gui_ItemDistributionNode(TE_ItemDistributionNode te, EntityPlayer player) { - super(new Container_ItemDistributionNode(te, player)); + public Gui_ItemProxySource(TileEntity te, EntityPlayer player) { + super(new Container_ItemProxySource(te, player)); inventory = player.inventory; - this.te = te; + this.te = (IInventory) te; } diff --git a/src/main/java/itemBlocks/IB_ItemDistributionCable.java b/src/main/java/itemBlocks/IB_ItemProxyCable.java index 832e95ca0a..590cb98285 100644 --- a/src/main/java/itemBlocks/IB_ItemDistributionCable.java +++ b/src/main/java/itemBlocks/IB_ItemProxyCable.java @@ -7,9 +7,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; -public class IB_ItemDistributionCable extends ItemBlock { +public class IB_ItemProxyCable extends ItemBlock { - public IB_ItemDistributionCable(Block block) { + public IB_ItemProxyCable(Block block) { super(block); } diff --git a/src/main/java/itemBlocks/IB_ItemDistributionNode.java b/src/main/java/itemBlocks/IB_ItemProxyEndpoint.java index cfea3853db..90d683c226 100644 --- a/src/main/java/itemBlocks/IB_ItemDistributionNode.java +++ b/src/main/java/itemBlocks/IB_ItemProxyEndpoint.java @@ -7,16 +7,16 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; -public class IB_ItemDistributionNode extends ItemBlock { +public class IB_ItemProxyEndpoint extends ItemBlock { - public IB_ItemDistributionNode(Block block) { + public IB_ItemProxyEndpoint(Block block) { super(block); } @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void addInformation(ItemStack stack, EntityPlayer player, List lines, boolean advancedTooltips) { - lines.add("Access point for Item Distribution Networks"); - lines.add("Wired networks do not require a controller"); + lines.add("Point the marked side to where you want to provide an inventory proxy to."); + lines.add("Insert an Integrated Circuit to set the network channel."); } } diff --git a/src/main/java/itemBlocks/IB_ItemProxySource.java b/src/main/java/itemBlocks/IB_ItemProxySource.java new file mode 100644 index 0000000000..cc937b3b33 --- /dev/null +++ b/src/main/java/itemBlocks/IB_ItemProxySource.java @@ -0,0 +1,23 @@ +package itemBlocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +public class IB_ItemProxySource extends ItemBlock { + + public IB_ItemProxySource(Block block) { + super(block); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List lines, boolean advancedTooltips) { + lines.add("Point to an inventory to act as source for the item proxy network."); + lines.add("Insert an Integrated Circuit to set the network channel."); + lines.add("Only one source can use one channel on the same network."); + } +} diff --git a/src/main/java/items/Item_Configurator.java b/src/main/java/items/Item_Configurator.java new file mode 100644 index 0000000000..ed319eb37e --- /dev/null +++ b/src/main/java/items/Item_Configurator.java @@ -0,0 +1,43 @@ +package items; + +import java.util.List; + +import cpw.mods.fml.common.registry.GameRegistry; +import kekztech.KekzCore; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class Item_Configurator extends Item { + + private static final Item_Configurator instance = new Item_Configurator(); + + private Item_Configurator() { + // I am a singleton + } + + public static Item_Configurator getInstance() { + return instance; + } + + public void registerItem() { + super.setHasSubtypes(false); + final String unlocalizedName = "kekztech_configurator"; + super.setUnlocalizedName(unlocalizedName); + super.setCreativeTab(CreativeTabs.tabMisc); + super.setMaxStackSize(1); + super.setTextureName(KekzCore.MODID + ":" + "DiamondHeatPipe"); + GameRegistry.registerItem(getInstance(), unlocalizedName); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean b) { + list.add("Used to configure Item Proxy Networks"); + if(stack.hasTagCompound() && stack.getTagCompound().hasKey("config")) { + list.add("Channel: " + stack.getTagCompound().getString("config")); + } + } + +} diff --git a/src/main/java/kekztech/GuiHandler.java b/src/main/java/kekztech/GuiHandler.java index 21ad5c95ae..439baff31f 100644 --- a/src/main/java/kekztech/GuiHandler.java +++ b/src/main/java/kekztech/GuiHandler.java @@ -1,21 +1,26 @@ package kekztech; -import container.Container_ItemDistributionNode; -import container.Gui_ItemDistributionNode; +import container.Container_ItemProxyEndpoint; +import container.Container_ItemProxySource; +import container.Gui_ItemProxyEndpoint; +import container.Gui_ItemProxySource; import cpw.mods.fml.common.network.IGuiHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import tileentities.TE_ItemDistributionNode; public class GuiHandler implements IGuiHandler { - + + public static final int ITEM_PROXY_SOURCE = 0; + public static final int ITEM_PROXY_ENDPOINT = 1; + @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { final TileEntity te = world.getTileEntity(x, y, z); if(te != null) { - if(ID == 0) { - return new Container_ItemDistributionNode((TE_ItemDistributionNode) te, player); + switch(ID) { + case ITEM_PROXY_SOURCE: return new Container_ItemProxySource(te, player); + case ITEM_PROXY_ENDPOINT: return new Container_ItemProxyEndpoint(te, player); } } return null; @@ -25,8 +30,9 @@ public class GuiHandler implements IGuiHandler { public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { final TileEntity te = world.getTileEntity(x, y, z); if(te != null) { - if(ID == 0) { - return new Gui_ItemDistributionNode((TE_ItemDistributionNode) te, player); + switch(ID) { + case ITEM_PROXY_SOURCE: return new Gui_ItemProxySource(te, player); + case ITEM_PROXY_ENDPOINT: return new Gui_ItemProxyEndpoint(te, player); } } return null; diff --git a/src/main/java/kekztech/IConduit.java b/src/main/java/kekztech/IConduit.java deleted file mode 100644 index ce726a2207..0000000000 --- a/src/main/java/kekztech/IConduit.java +++ /dev/null @@ -1,8 +0,0 @@ -package kekztech; - -public interface IConduit { - - public void setNetwork(ItemDistributionNetworkController network); - public ItemDistributionNetworkController getNetwork(); - -} diff --git a/src/main/java/kekztech/ItemDistributionNetworkController.java b/src/main/java/kekztech/ItemDistributionNetworkController.java deleted file mode 100644 index 11383845b2..0000000000 --- a/src/main/java/kekztech/ItemDistributionNetworkController.java +++ /dev/null @@ -1,193 +0,0 @@ -package kekztech; - -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.UUID; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - -public class ItemDistributionNetworkController implements Comparable<ItemDistributionNetworkController> { - - private static final HashSet<ItemDistributionNetworkController> instances = new HashSet<>(); - - private final UUID uuid = UUID.randomUUID(); - private final LinkedList<IConduit> conduits = new LinkedList<>(); - private final boolean[] slotDirections = new boolean[15]; - private final ItemStack[] networkedItemStacks = new ItemStack[15]; - //private final HashMap<String, IConduit> sources = new HashMap<>(); // k = resource name, v = source conduit - - public ItemDistributionNetworkController() { - - } - - /** - * Places a new conduit as it's own network. Merges with adjacent networks automatically. - * - * @param conduit - * The conduit to be placed - */ - public static void placeConduit(IConduit conduit) { - - conduit.setNetwork(new ItemDistributionNetworkController()); - conduit.getNetwork().addConduit(conduit); - /* - final TileEntity te = (TileEntity) conduit; - final int x = te.xCoord; - final int y = te.yCoord; - final int z = te.zCoord; - - // Search for adjacent Networks on all six sides - final HashSet<ItemDistributionNetworkController> networks = new HashSet<>(); - final World world = te.getWorldObj(); - final TileEntity te1x = world.getTileEntity(x + 1, y, z); - final TileEntity te0x = world.getTileEntity(x - 1, y, z); - final TileEntity te1y = world.getTileEntity(x, y + 1, z); - final TileEntity te0y = world.getTileEntity(x, y - 1, z); - final TileEntity te1z = world.getTileEntity(x, y, z + 1); - final TileEntity te0z = world.getTileEntity(x, y, z - 1); - if(te1x != null && te1x instanceof IConduit) { - final IConduit c = (IConduit) te1x; - networks.add(c.getNetwork()); - } - if(te0x != null && te0x instanceof IConduit) { - final IConduit c = (IConduit) te0x; - networks.add(c.getNetwork()); - } - if(te1y != null && te1y instanceof IConduit) { - final IConduit c = (IConduit) te1y; - networks.add(c.getNetwork()); - } - if(te0y != null && te0y instanceof IConduit) { - final IConduit c = (IConduit) te0y; - networks.add(c.getNetwork()); - } - if(te1z != null && te1z instanceof IConduit) { - final IConduit c = (IConduit) te1z; - networks.add(c.getNetwork()); - } - if(te0z != null && te0z instanceof IConduit) { - final IConduit c = (IConduit) te0z; - networks.add(c.getNetwork()); - } - // Return prematurely if no adjacent network was found - if(networks.size() == 0) { - return; - } - // Sort networks by descending size - final LinkedList<ItemDistributionNetworkController> networkList = new LinkedList<>(); - networkList.addAll(networks); - Collections.sort(networkList, Collections.reverseOrder()); - // Larger networks consume smaller networks to reduce copying around data - while(networkList.size() > 1) { - final ItemDistributionNetworkController l = networkList.get(networkList.size() - 2); - final ItemDistributionNetworkController r = networkList.getLast(); - l.appendNetwork(r); - networkList.removeLast(); - }*/ - - } - - /** - * Deletes this conduit and breaks up adjacent networks into separate networks. - * - * @param conduit - * Conduit to be removed. - */ - public static void destroyConduit(IConduit conduit) { - - } - - public void run() { - - } - - @Override - public boolean equals(Object o) { - if(o instanceof ItemDistributionNetworkController) { - final ItemDistributionNetworkController network = (ItemDistributionNetworkController) o; - return uuid.equals(network.getUUID()); - } else { - return false; - } - } - - @Override - public int compareTo(ItemDistributionNetworkController o) { - return (int) Math.signum(o.getSize() - this.getSize()); - } - - public UUID getUUID() { - return uuid; - } - - public int getSize() { - return conduits.size(); - } - - /** - * Find out if this slot is designated as input and can accept an item into the network. - * - * Slots are numbered left to right, then top to bottom and start at zero. - * For example, the second slot in the second row, would have a slot number of five. - * - * @param slot: - * Slot number. - * @return whether this slot can accept input or not. - */ - public boolean isInputSlot(int slot) { - if(slot >= slotDirections.length) { - return false; - } - return slotDirections[slot]; - } - - /** - * Return the ItemStack that is contained in the given slot number. - * - * Slots are numbered left to right, then top to bottom and start at zero. - * For example, the second slot in the second row, would have a slot number of five. - * - * @param slot: - * Slot number. - * @return ItemStack at given slot number. - */ - public ItemStack getStackInSlot(int slot) { - if(slot >= networkedItemStacks.length) { - return null; - } - return networkedItemStacks[slot]; - } - - public void setStackInSlot(int slot, ItemStack itemStack) { - if(slot < networkedItemStacks.length && isInputSlot(slot)) { - networkedItemStacks[slot] = itemStack; - } - } - - /** - * Register a new conduit to this network. - * - * @param conduit - * New conduit. - */ - private void addConduit(IConduit conduit) { - conduits.add(conduit); - conduit.setNetwork(this); - } - - /** - * Merge another network with this one if they have been connected by a new conduit. - * - * @param network - * Network to merge with this one. - */ - private void appendNetwork(ItemDistributionNetworkController network) { - for(IConduit conduit : network.conduits) { - this.addConduit(conduit); - } - } - -} diff --git a/src/main/java/kekztech/Items.java b/src/main/java/kekztech/Items.java index a2870d6e2c..cb79d01947 100644 --- a/src/main/java/kekztech/Items.java +++ b/src/main/java/kekztech/Items.java @@ -42,7 +42,9 @@ public enum Items { YSZCeramicPlate(14,1), GDCCeramicPlate(15,1),
ItemServerBlade(16,1),
// Error Item
- Error(0,1);
+ Error(0,1),
+ // Configurator
+ Configurator(0, 1);
static {
YttriaDust.setOreDictName("dustYttriumOxide");
diff --git a/src/main/java/kekztech/KekzCore.java b/src/main/java/kekztech/KekzCore.java index 9d0ae23283..247131c7f7 100644 --- a/src/main/java/kekztech/KekzCore.java +++ b/src/main/java/kekztech/KekzCore.java @@ -2,6 +2,9 @@ package kekztech; import blocks.Block_ControlRod;
import blocks.Block_GDCUnit;
+import blocks.Block_ItemProxyCable;
+import blocks.Block_ItemProxyEndpoint;
+import blocks.Block_ItemProxySource;
import blocks.Block_ItemServerDrive;
import blocks.Block_ItemServerIOPort;
import blocks.Block_ItemServerRackCasing;
@@ -14,6 +17,7 @@ import blocks.Block_TFFTStorageFieldBlockT2; import blocks.Block_TFFTStorageFieldBlockT3;
import blocks.Block_TFFTStorageFieldBlockT4;
import blocks.Block_YSZUnit;
+import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
@@ -29,17 +33,21 @@ import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
import items.ErrorItem;
+import items.Item_Configurator;
import items.MetaItem_CraftingComponent;
import items.MetaItem_ReactorComponent;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
+import render.ConduitRenderer;
import tileentities.GTMTE_FluidMultiStorage;
import tileentities.GTMTE_ItemServer;
import tileentities.GTMTE_ModularNuclearReactor;
import tileentities.GTMTE_SOFuelCellMK1;
import tileentities.GTMTE_SOFuelCellMK2;
-import tileentities.TE_ItemDistributionCable;
-import tileentities.TE_ItemDistributionNode;
+import tileentities.TE_ItemProxyCable;
+import tileentities.TE_ItemProxyEndpoint;
+import tileentities.TE_ItemProxySource;
+import tileentities.TE_ItemServerIOPort;
import tileentities.TE_TFFTMultiHatch;
import util.Util;
@@ -77,6 +85,7 @@ public class KekzCore { ErrorItem.getInstance().registerItem();
MetaItem_ReactorComponent.getInstance().registerItem();
MetaItem_CraftingComponent.getInstance().registerItem();
+ Item_Configurator.getInstance().registerItem();
Items.registerOreDictNames();
// Blocks
Block_YSZUnit.getInstance().registerBlock();
@@ -93,14 +102,17 @@ public class KekzCore { Block_ItemServerDrive.getInstance().registerBlock();
Block_ItemServerRackCasing.getInstance().registerBlock();
Block_ItemServerIOPort.getInstance().registerBlock();
- // TODO: Disabled for new release
- //Block_ItemDistributionCable.getInstance().registerBlock();
- //Block_ItemDistributionNode.getInstance().registerBlock();
+ Block_ItemProxyCable.getInstance().registerBlock();
+ Block_ItemProxySource.getInstance().registerBlock();
+ Block_ItemProxyEndpoint.getInstance().registerBlock();
// Register TileEntities
GameRegistry.registerTileEntity(TE_TFFTMultiHatch.class, "kekztech_tfftmultihatch_tile");
- GameRegistry.registerTileEntity(TE_ItemDistributionCable.class, "kekztech_itemdistributioncable_tile");
- GameRegistry.registerTileEntity(TE_ItemDistributionNode.class, "kekztech_itemdistributionnode_tile");
- // Register a GUI?
+ GameRegistry.registerTileEntity(TE_ItemServerIOPort.class, "kekztech_itemserverioport_tile");
+ GameRegistry.registerTileEntity(TE_ItemProxyCable.class, "kekztech_itemproxycable_tile");
+ GameRegistry.registerTileEntity(TE_ItemProxySource.class, "kekztech_itemproxysource_tile");
+ GameRegistry.registerTileEntity(TE_ItemProxyEndpoint.class, "kekztech_itemproxyendpoint_tile");
+
+ // Register guis
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
}
@@ -111,7 +123,9 @@ public class KekzCore { sofc2 = new GTMTE_SOFuelCellMK2(13102, "multimachine.fuelcellmk2", "Solid-Oxide Fuel Cell Mk II");
mdr = new GTMTE_ModularNuclearReactor(13103, "multimachine.nuclearreactor", "Nuclear Reactor");
fms = new GTMTE_FluidMultiStorage(13104, "multimachine.tf_fluidtank", "T.F.F.T");
- is = new GTMTE_ItemServer(13105, "multimachine.itemserver", "Item Server");
+ is = new GTMTE_ItemServer(13105, "multimachine.itemserver", "Item Server");
+ // Register renderer
+ ConduitRenderer.getInstance().registerRenderer();
}
@Mod.EventHandler
diff --git a/src/main/java/render/ConduitRenderer.java b/src/main/java/render/ConduitRenderer.java new file mode 100644 index 0000000000..241dd18647 --- /dev/null +++ b/src/main/java/render/ConduitRenderer.java @@ -0,0 +1,83 @@ +package render; + +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import cpw.mods.fml.client.registry.RenderingRegistry; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import tileentities.TE_ItemProxyCable; + +public class ConduitRenderer implements ISimpleBlockRenderingHandler { + + private static final ConduitRenderer instance = new ConduitRenderer(); + private final int renderID = RenderingRegistry.getNextAvailableRenderId(); + + private ConduitRenderer() { + + } + + public static ConduitRenderer getInstance() { + return instance; + } + + public void registerRenderer() { + RenderingRegistry.registerBlockHandler(this); + } + + @Override + public int getRenderId() { + return renderID; + } + + @Override + public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { + + } + + @Override + public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, + RenderBlocks renderer) { + System.out.println("custom renderer"); + final TileEntity te = world.getTileEntity(x, y, z); + if(te instanceof TE_ItemProxyCable) { + final TE_ItemProxyCable cable = (TE_ItemProxyCable) te; + + final float thickness = TE_ItemProxyCable.getThickness(); + final float space = (1.0f - thickness) / 2.0f; + + if(cable.getConnections() == 63) { // No need to render a center cube if it's hidden anyways + block.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); + renderer.setRenderBounds(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); + } else if (cable.getConnections() == 0) { // Only center cube required + block.setBlockBounds(space, space, space, space + thickness, space + thickness, space + thickness); + renderer.setRenderBounds(space, space, space, space + thickness, space + thickness, space + thickness); + } + + final Tessellator f = Tessellator.instance; + f.startDrawingQuads(); + IIcon icon = block.getIcon(0, 0); + // South face + if(cable.isConnected(ForgeDirection.SOUTH)) { + System.out.println("tesselating"); + f.addVertexWithUV(x + space + thickness, y + space, z + 1, icon.getMaxU(), icon.getMaxV()); + f.addVertexWithUV(x + space + thickness, y + space + thickness, z + 1, icon.getMaxU(), icon.getMinV()); + f.addVertexWithUV(x + space, y + space + thickness, z + 1, icon.getMinU(), icon.getMinV()); + f.addVertexWithUV(x + space, y + space, z + 1, icon.getMinU(), icon.getMaxV()); + } + + f.draw(); + } + + return false; + } + + @Override + public boolean shouldRender3DInInventory(int modelId) { + return false; + } + +} diff --git a/src/main/java/tileentities/TE_ItemDistributionCable.java b/src/main/java/tileentities/TE_ItemDistributionCable.java deleted file mode 100644 index 325d04c211..0000000000 --- a/src/main/java/tileentities/TE_ItemDistributionCable.java +++ /dev/null @@ -1,25 +0,0 @@ -package tileentities; - -import kekztech.IConduit; -import kekztech.ItemDistributionNetworkController; -import net.minecraft.tileentity.TileEntity; - -public class TE_ItemDistributionCable extends TileEntity implements IConduit { - - private ItemDistributionNetworkController network; - - public TE_ItemDistributionCable() { - ItemDistributionNetworkController.placeConduit(this); - } - - @Override - public void setNetwork(ItemDistributionNetworkController network) { - this.network = network; - } - - @Override - public ItemDistributionNetworkController getNetwork() { - return network; - } - -} diff --git a/src/main/java/tileentities/TE_ItemDistributionNode.java b/src/main/java/tileentities/TE_ItemDistributionNode.java deleted file mode 100644 index 20b6500598..0000000000 --- a/src/main/java/tileentities/TE_ItemDistributionNode.java +++ /dev/null @@ -1,119 +0,0 @@ -package tileentities; - -import kekztech.IConduit; -import kekztech.ItemDistributionNetworkController; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - -public class TE_ItemDistributionNode extends TileEntity implements IConduit, IInventory { - -private ItemDistributionNetworkController network; - - public TE_ItemDistributionNode() { - ItemDistributionNetworkController.placeConduit(this); - } - - @Override - public void setNetwork(ItemDistributionNetworkController network) { - this.network = network; - } - - @Override - public ItemDistributionNetworkController getNetwork() { - return network; - } - - @Override - public int getSizeInventory() { - return 16; - } - - @Override - public ItemStack getStackInSlot(int slot) { - return network.getStackInSlot(slot); - } - - @Override - public ItemStack decrStackSize(int slot, int amount) { - - if(network.getStackInSlot(slot) != null) { - if(network.getStackInSlot(slot).stackSize == amount) { - final ItemStack itemStack = network.getStackInSlot(slot); - network.setStackInSlot(slot, null); - super.markDirty(); - return itemStack; - } else { - final ItemStack itemStack = network.getStackInSlot(slot).splitStack(amount); - if(network.getStackInSlot(slot).stackSize == 0) { - network.setStackInSlot(slot, null); - } - super.markDirty(); - return itemStack; - } - } - - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - if(network.getStackInSlot(slot) != null) { - final ItemStack itemStack = network.getStackInSlot(slot); - network.setStackInSlot(slot, null); - return itemStack; - } - return null; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack itemStack) { - if(itemStack == null) { - return; - } - if(itemStack.stackSize > getInventoryStackLimit()) { - itemStack.stackSize = getInventoryStackLimit(); - } - network.setStackInSlot(slot, itemStack); - super.markDirty(); - } - - @Override - public String getInventoryName() { - return network.getUUID().toString(); - } - - @Override - public boolean hasCustomInventoryName() { - return true; - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return true; - } - - @Override - public void openInventory() { - // TODO Auto-generated method stub - - } - - @Override - public void closeInventory() { - // TODO Auto-generated method stub - - } - - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemStack) { - return network.isInputSlot(slot) && network.getStackInSlot(slot).isItemEqual(itemStack); - } - -} diff --git a/src/main/java/tileentities/TE_ItemProxyCable.java b/src/main/java/tileentities/TE_ItemProxyCable.java new file mode 100644 index 0000000000..43ebc07b13 --- /dev/null +++ b/src/main/java/tileentities/TE_ItemProxyCable.java @@ -0,0 +1,77 @@ +package tileentities; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public class TE_ItemProxyCable extends TileEntity { + + private static final float THICKNESS = 0.3f; + private byte connections; + private String idCache = null; + + public TE_ItemProxyCable() { + connections = 63; // set all connections active until I have something actually control connections + } + + public static float getThickness() { + return THICKNESS; + } + + /** + * Builds a simple unique identifier for this TileEntity by appending + * the x, y, and z coordinates in a string. + * + * @return unique identifier for this TileEntity + */ + public String getIdentifier() { + if(idCache == null) { + idCache = "" + super.xCoord + super.yCoord + super.zCoord; + return idCache; + } else { + return idCache; + } + } + + /** + * 0 0 0 0 0 0 0 0 = 0 -> no connection </br> + * 0 0 0 0 0 0 0 1 = 1 -> down </br> + * 0 0 0 0 0 0 1 0 = 2 -> up </br> + * 0 0 0 0 0 1 0 0 = 4 -> north </br> + * 0 0 0 0 1 0 0 0 = 8 -> south </br> + * 0 0 0 1 0 0 0 0 = 16 -> west </br> + * 0 0 1 0 0 0 0 0 = 32 -> east </br> + * + * @param side + * The side for which to set the connection status. + * @param connected + * Whether this side should be connected or not + */ + public void setConnection(ForgeDirection side, boolean connected) { + switch(side) { + case DOWN: connections = (byte) ((connected) ? connections | 1 : connections ^ 1); break; + case UP: connections = (byte) ((connected) ? connections | 2 : connections ^ 2); break; + case NORTH: connections = (byte) ((connected) ? connections | 4 : connections ^ 4); break; + case SOUTH: connections = (byte) ((connected) ? connections | 8 : connections ^ 8); break; + case WEST: connections = (byte) ((connected) ? connections | 16 : connections ^ 16); break; + case EAST: connections = (byte) ((connected) ? connections | 32 : connections ^ 32); break; + default: break; + } + } + + public boolean isConnected(ForgeDirection side) { + switch(side) { + case DOWN: return (connections & 1) == connections; + case UP: return (connections & 2) == connections; + case NORTH: return (connections & 4) == connections; + case SOUTH: return (connections & 8) == connections; + case WEST: return (connections & 16) == connections; + case EAST: return (connections & 32) == connections; + default: return false; + } + } + + public byte getConnections() { + return connections; + } + +} diff --git a/src/main/java/tileentities/TE_ItemProxyEndpoint.java b/src/main/java/tileentities/TE_ItemProxyEndpoint.java new file mode 100644 index 0000000000..1fe32c9687 --- /dev/null +++ b/src/main/java/tileentities/TE_ItemProxyEndpoint.java @@ -0,0 +1,204 @@ +package tileentities; + +import java.util.HashSet; +import java.util.UUID; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public class TE_ItemProxyEndpoint extends TileEntity implements ISidedInventory { + + private UUID channel = null; + private int subChannel = -1; + private IInventory proxyInventory = null; + private int tickCounter = 0; + private ItemStack[] slots = new ItemStack[2]; + + public void setChannel(UUID channel) { + this.channel = channel; + } + + public void setSubChannel(int subChannel) { + this.subChannel = subChannel; + } + + @Override + public void updateEntity() { + if(tickCounter == 20) { + + if(slots[1] == null || !slots[1].getUnlocalizedName().equals("gt.integrated_circuit") || slots[1].getItemDamage() >= 16) { + setSubChannel(-1); + } + + if(slots[1] != null && slots[1].getUnlocalizedName().equals("gt.integrated_circuit") && slots[1].getItemDamage() < 16) { + setSubChannel(slots[1].getItemDamage()); + } + + if(channel != null && subChannel != -1) { + TE_ItemProxySource source = searchSource(channel); + if(source != null) { + proxyInventory = source; + } + } + tickCounter = 0; + } + tickCounter++; + } + + public TE_ItemProxySource searchSource(UUID channel) { + + final HashSet<TE_ItemProxySource> sources = new HashSet<>(); + final HashSet<String> visited = new HashSet<>(); + + for(ForgeDirection next : ForgeDirection.VALID_DIRECTIONS) { + final TileEntity te = super.getWorldObj().getTileEntity( + super.xCoord + next.offsetX, + super.yCoord + next.offsetY, + super.zCoord + next.offsetZ); + if(te instanceof TE_ItemProxyCable) { + final TE_ItemProxyCable cable = (TE_ItemProxyCable) te; + if(cable.isConnected(next.getOpposite())) { + searchSourceRecursive(sources, visited, next.getOpposite(), cable, channel); + } + } + } + + if(sources.isEmpty()) { + return null; + } else { + return sources.iterator().next(); + } + + } + + private void searchSourceRecursive(HashSet<TE_ItemProxySource> sources, HashSet<String> visited, + ForgeDirection from, TE_ItemProxyCable nextTarget, UUID channel) { + + if(visited.contains(nextTarget.getIdentifier())) { + return; + } else { + visited.add(nextTarget.getIdentifier()); + + for(ForgeDirection next : ForgeDirection.VALID_DIRECTIONS) { + if(next == from || !nextTarget.isConnected(next)) { + continue; + } + final TileEntity te = super.getWorldObj().getTileEntity( + nextTarget.xCoord + next.offsetX, + nextTarget.yCoord + next.offsetY, + nextTarget.zCoord + next.offsetZ); + if(te instanceof TE_ItemProxyCable) { + final TE_ItemProxyCable cable = (TE_ItemProxyCable) te; + if(cable.isConnected(next.getOpposite())) { + searchSourceRecursive(sources, visited, next.getOpposite(), cable, channel); + } + } else if (te instanceof TE_ItemProxySource) { + final TE_ItemProxySource source = (TE_ItemProxySource) te; + if(source.getChannel().equals(channel)) { + sources.add((TE_ItemProxySource) te); + } + } + } + } + } + + @Override + public int getSizeInventory() { + return slots.length; + } + + @Override + public ItemStack getStackInSlot(int slot) { + if(slot == 0) { + return (proxyInventory != null) ? proxyInventory.getStackInSlot(subChannel) : null; + } else { + return slots[slot]; + } + } + + @Override + public ItemStack decrStackSize(int slot, int amount) { + if(slot == 0) { + return (proxyInventory != null) ? proxyInventory.decrStackSize(subChannel, amount) : null; + } else { + final ItemStack copy = slots[1].copy(); + slots[1] = null; + super.markDirty(); + return copy; + } + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return (proxyInventory != null) ? proxyInventory.getStackInSlotOnClosing(subChannel) : null; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemStack) { + if(slot == 0 && proxyInventory != null) { + proxyInventory.setInventorySlotContents(subChannel, itemStack); + } else { + slots[slot] = itemStack; + } + } + + @Override + public String getInventoryName() { + return (proxyInventory != null) ? "Connected Proxy" : "Untethered Proxy"; + } + + @Override + public boolean hasCustomInventoryName() { + return true; + } + + @Override + public int getInventoryStackLimit() { + return (proxyInventory != null) ? proxyInventory.getInventoryStackLimit() : 1; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer player) { + return true; + } + + @Override + public void openInventory() { + + } + + @Override + public void closeInventory() { + + } + + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemStack) { + if(slot == 0 && proxyInventory != null) { + return proxyInventory.isItemValidForSlot(subChannel, itemStack); + } else { + return itemStack != null && itemStack.getUnlocalizedName().equals("gt.integrated_circuit"); + } + } + + @Override + public int[] getAccessibleSlotsFromSide(int side) { + final int[] as = {0}; + return as; + } + + @Override + public boolean canInsertItem(int slot, ItemStack itemStack, int side) { + return isItemValidForSlot(slot, itemStack); + } + + @Override + public boolean canExtractItem(int slot, ItemStack itemStack, int side) { + return (slot == 0) ? true : false; + } + +} diff --git a/src/main/java/tileentities/TE_ItemProxySource.java b/src/main/java/tileentities/TE_ItemProxySource.java new file mode 100644 index 0000000000..15ffba3090 --- /dev/null +++ b/src/main/java/tileentities/TE_ItemProxySource.java @@ -0,0 +1,101 @@ +package tileentities; + +import java.util.UUID; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +public class TE_ItemProxySource extends TileEntity implements IInventory { + + private final UUID channel = UUID.randomUUID(); + private ItemStack[] slots = new ItemStack[16]; + + public UUID getChannel() { + return channel; + } + + @Override + public int getSizeInventory() { + return slots.length; + } + + @Override + public ItemStack getStackInSlot(int slot) { + return slots[slot]; + } + + @Override + public ItemStack decrStackSize(int slot, int amount) { + if(slots[slot] != null) { + + ItemStack copy; + + if(slots[slot].stackSize == amount) { + copy = slots[slot]; + slots[slot] = null; + super.markDirty(); + return copy; + } else { + copy = slots[slot].splitStack(amount); + if(slots[slot].stackSize == 0) { + slots[slot] = null; + } + return copy; + } + + } else { + return null; + } + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return null; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemStack) { + slots[slot] = itemStack; + if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) { + itemStack.stackSize = getInventoryStackLimit(); + } + super.markDirty(); + } + + @Override + public String getInventoryName() { + return "Item Proxy Network Source"; + } + + @Override + public boolean hasCustomInventoryName() { + return true; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { + return true; + } + + @Override + public void openInventory() { + + } + + @Override + public void closeInventory() { + + } + + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemStack) { + return true; + } +} diff --git a/src/main/java/tileentities/TE_ItemServerIOPort.java b/src/main/java/tileentities/TE_ItemServerIOPort.java index 46a3a9c7bb..a8c0f25b83 100644 --- a/src/main/java/tileentities/TE_ItemServerIOPort.java +++ b/src/main/java/tileentities/TE_ItemServerIOPort.java @@ -47,15 +47,23 @@ public class TE_ItemServerIOPort extends TileEntity implements IInventory { @Override public void setInventorySlotContents(int slot, ItemStack itemStack) { + System.out.println("Set slot, MIH: " + mih); if(mih != null) { if(itemStack == null || !itemStack.isItemEqual(mih.getStackInSlot(slot))) { return; } else { - final int change = itemStack.stackSize - mih.getStackInSlot(slot).stackSize; - if(change < 0) { - mih.reduceStackInSlot(slot, change); + if(mih.getStackInSlot(slot) == null) { + System.out.println("Set slot: Allocate new"); + mih.insertStackInSlot(slot, itemStack); } else { - mih.increaseStackInSlot(slot, change); + final int change = itemStack.stackSize - mih.getStackInSlot(slot).stackSize; + if(change < 0) { + System.out.println("Set slot: reduce"); + mih.reduceStackInSlot(slot, change); + } else { + System.out.println("Set slot: increase"); + mih.increaseStackInSlot(slot, change); + } } super.markDirty(); } @@ -79,7 +87,7 @@ public class TE_ItemServerIOPort extends TileEntity implements IInventory { @Override public boolean isUseableByPlayer(EntityPlayer player) { - return false; + return true; } @Override diff --git a/src/main/resources/assets/kekztech/lang/en_US.lang b/src/main/resources/assets/kekztech/lang/en_US.lang index 2197856513..d21ed0462e 100644 --- a/src/main/resources/assets/kekztech/lang/en_US.lang +++ b/src/main/resources/assets/kekztech/lang/en_US.lang @@ -88,8 +88,9 @@ tile.kekztech_controlrod_block.name=Nuclear Reactor Control Rod tile.kekztech_reactorchamberoff_block.name=Nuclear Reactor Chamber (OFF)
tile.kekztech_reactorchamberon_block.name=Nuclear Reactor Chamber (ON)
-tile.kekztech_itemdistributioncable_block.name=Item Distribution Cable
-tile.kekztech_itemdistributionnode_block.name=Item Distribution Node
+tile.kekztech_itemproxycable_block.name=Item Proxy Network Cable
+tile.kekztech_itemproxysource_block.name=Item Proxy Network Source
+tile.kekztech_itemproxyendpoint_block.name=Item Proxy Network Endpoint
tile.kekztech_itemserverdrive_block.name=Item Server Drive
tile.kekztech_itemserverrackcasing_block.name=Item Server Rack Casing
tile.kekztech_itemserverioport_block.name=Item Server I/O Port
diff --git a/src/main/resources/assets/kekztech/textures/blocks/ItemDistributionCable.png b/src/main/resources/assets/kekztech/textures/blocks/ItemDistributionCable.png Binary files differdeleted file mode 100644 index a7b20f6614..0000000000 --- a/src/main/resources/assets/kekztech/textures/blocks/ItemDistributionCable.png +++ /dev/null diff --git a/src/main/resources/assets/kekztech/textures/blocks/ItemDistributionNode.png b/src/main/resources/assets/kekztech/textures/blocks/ItemDistributionNode.png Binary files differdeleted file mode 100644 index 5b6aa6c86e..0000000000 --- a/src/main/resources/assets/kekztech/textures/blocks/ItemDistributionNode.png +++ /dev/null diff --git a/src/main/resources/assets/kekztech/textures/blocks/ItemProxyEndpoint.png b/src/main/resources/assets/kekztech/textures/blocks/ItemProxyEndpoint.png Binary files differnew file mode 100644 index 0000000000..0bfab8cbaf --- /dev/null +++ b/src/main/resources/assets/kekztech/textures/blocks/ItemProxyEndpoint.png diff --git a/src/main/resources/assets/kekztech/textures/blocks/ItemProxySource.png b/src/main/resources/assets/kekztech/textures/blocks/ItemProxySource.png Binary files differnew file mode 100644 index 0000000000..742e562834 --- /dev/null +++ b/src/main/resources/assets/kekztech/textures/blocks/ItemProxySource.png diff --git a/src/main/resources/assets/kekztech/textures/gui/ItemTech1by1.png b/src/main/resources/assets/kekztech/textures/gui/ItemTech1by1.png Binary files differnew file mode 100644 index 0000000000..816e27a66b --- /dev/null +++ b/src/main/resources/assets/kekztech/textures/gui/ItemTech1by1.png diff --git a/src/main/resources/assets/kekztech/textures/gui/ItemDistributorNode.png b/src/main/resources/assets/kekztech/textures/gui/ItemTech4by4.png Binary files differindex b01d9b444f..b01d9b444f 100644 --- a/src/main/resources/assets/kekztech/textures/gui/ItemDistributorNode.png +++ b/src/main/resources/assets/kekztech/textures/gui/ItemTech4by4.png |