diff --git a/resources/tinkertextures/gui/smeltery.png b/resources/tinkertextures/gui/smeltery.png new file mode 100644 index 00000000..14b5c13d Binary files /dev/null and b/resources/tinkertextures/gui/smeltery.png differ diff --git a/tinker/common/InventoryBlock.java b/tinker/common/InventoryBlock.java index 9fc19ace..cbb4a4c9 100644 --- a/tinker/common/InventoryBlock.java +++ b/tinker/common/InventoryBlock.java @@ -1,12 +1,5 @@ package tinker.common; -import inficraft.api.machines.BlockLogicBase; -import inficraft.infiblocks.tech.FurnaceLogic; - -import java.util.Random; - -import tinker.tconstruct.TConstruct; - import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLiving; @@ -18,6 +11,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import tinker.tconstruct.TConstruct; public abstract class InventoryBlock extends BlockContainer { diff --git a/tinker/tconstruct/AbilityHelper.java b/tinker/tconstruct/AbilityHelper.java index 2fa20c38..e59a6053 100644 --- a/tinker/tconstruct/AbilityHelper.java +++ b/tinker/tconstruct/AbilityHelper.java @@ -60,7 +60,6 @@ public class AbilityHelper { int damage = tags.getCompoundTag("InfiTool").getInteger("Damage"); int maxDamage = tags.getCompoundTag("InfiTool").getInteger("TotalDurability"); - if ((damage + dam) > maxDamage) { breakTool(stack, tags, entity); @@ -238,7 +237,8 @@ public class AbilityHelper else mob.attackEntityFrom(DamageSource.causeMobDamage(player), attack); } - if (mob.hurtResistantTime <= 0) + System.out.println("Hit entity"); + //if (mob.hurtResistantTime <= 0) damageTool(stack, 1, tags, player); } diff --git a/tinker/tconstruct/PHConstruct.java b/tinker/tconstruct/PHConstruct.java index cea14295..19a8980e 100644 --- a/tinker/tconstruct/PHConstruct.java +++ b/tinker/tconstruct/PHConstruct.java @@ -14,9 +14,9 @@ public class PHConstruct { * Second: Create the actual config file * Note: Configs are a pain, but absolutely necessary for every mod. */ - File file = new File(TConstruct.proxy.getLocation() + "/config/TinkersWorkshop"); + File file = new File(TConstruct.proxy.getLocation() + "/config"); file.mkdir(); - File newFile = new File(TConstruct.proxy.getLocation() + "/config/TinkersWorkshop/TConstruct.txt"); + File newFile = new File(TConstruct.proxy.getLocation() + "/config/TinkersWorkshop.txt"); /* Some basic debugging will go a long way */ try @@ -69,7 +69,7 @@ public class PHConstruct { frypanHead = config.getItem("Tool Parts", "Frypan Head", 14035).getInt(14035); signHead = config.getItem("Tool Parts", "Sign Head", 14036).getInt(14036); - lumberHead = config.getItem("Tool Parts", "Lumber Axe Head", 14036).getInt(14036); + lumberHead = config.getItem("Tool Parts", "Lumber Axe Head", 14037).getInt(14037); pickaxe = config.getItem("Tools", "Pickaxe", 14051).getInt(14051); shovel = config.getItem("Tools", "Shovel", 14052).getInt(14052); diff --git a/tinker/tconstruct/TConstruct.java b/tinker/tconstruct/TConstruct.java index 3683e7cb..c317b22a 100644 --- a/tinker/tconstruct/TConstruct.java +++ b/tinker/tconstruct/TConstruct.java @@ -18,12 +18,12 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; -/** TConstruct, the successor to InfiTools - * Now with many much more combinations and many much less IDs! +/** TConstruct, the tool mod. + * Craft your tools with style, then modify until the original is gone! * @author: mDiyo */ -@Mod(modid = "TConstruct", name = "TConstruct", version = "A16") +@Mod(modid = "TConstruct", name = "TConstruct", version = "A17") @NetworkMod(serverSideRequired = false, clientSideRequired = true) public class TConstruct { @@ -41,12 +41,12 @@ public class TConstruct { MinecraftForge.EVENT_BUS.register(this); PHConstruct.initProps(); - materialTab = new TabTools("TConMaterials"); - toolTab = new TabTools("TConstruct"); + materialTab = new TabTools("TConstructMaterials"); + toolTab = new TabTools("TConstructTools"); blockTab = new TabTools("TConstructBlocks"); content = new TConstructContent(); - NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler()); + NetworkRegistry.instance().registerGuiHandler(instance, new TConstructGuiHandler()); addToolButtons(); } diff --git a/tinker/tconstruct/TConstructContent.java b/tinker/tconstruct/TConstructContent.java index 2d1f596f..c6472aa2 100644 --- a/tinker/tconstruct/TConstructContent.java +++ b/tinker/tconstruct/TConstructContent.java @@ -4,6 +4,7 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.oredict.ShapedOreRecipe; @@ -122,15 +123,15 @@ public class TConstructContent GameRegistry.registerBlock(smeltery, "Smeltery"); GameRegistry.registerTileEntity(tinker.tconstruct.logic.SmelteryLogic.class, "TConstruct.Smeltery"); - craftedSoil = new TConstructBlock(PHConstruct.craftedSoil, 96, Material.sand, 3.0F); + craftedSoil = new TConstructBlock(PHConstruct.craftedSoil, 96, Material.sand, 3.0F, 2); craftedSoil.stepSound = Block.soundGravelFootstep; GameRegistry.registerBlock(craftedSoil, tinker.tconstruct.blocks.CraftedSoilItemBlock.class, "CraftedSoil"); - searedBrick = new TConstructBlock(PHConstruct.searedBrick, 80, Material.iron, 10.0F); + searedBrick = new TConstructBlock(PHConstruct.searedBrick, 80, Material.iron, 10.0F, 1); GameRegistry.registerBlock(searedBrick, tinker.tconstruct.blocks.SearedBrickItemBlock.class, "SearedBrick"); MinecraftForge.setBlockHarvestLevel(searedBrick, 0, "pickaxe", 2); - materials = new Materials(PHConstruct.materials, 64, craftingTexture).setItemName("tconstruct.Materials"); + materials = new Materials(PHConstruct.materials, 128, craftingTexture).setItemName("tconstruct.Materials"); toolRod = new ToolPart(PHConstruct.toolRod, 0, craftingTexture).setItemName("tconstruct.ToolRod"); toolShard = new ToolPart(PHConstruct.toolShard, 64, craftingTexture).setItemName("tconstruct.ToolShard"); woodPattern = new Pattern(PHConstruct.woodPattern, 0, patternTexture).setItemName("tconstruct.Pattern"); @@ -176,8 +177,8 @@ public class TConstructContent pb.registerFullMaterial(Item.bone, 2, "bone", new ItemStack(toolShard, 1, 5), new ItemStack(Item.bone), 5); pb.registerFullMaterial(Block.obsidian, 2, "obsidian", 6); pb.registerFullMaterial(Block.netherrack, 2, "netherrack", 7); - pb.registerFullMaterial(Item.slimeBall, 2, "slime", 8); //TODO: Register a better material - pb.registerFullMaterial(Item.paper, 2, "paper", new ItemStack(Item.paper), new ItemStack(toolRod, 1, 9), 9); //TODO: Register a better material + pb.registerFullMaterial(new ItemStack(materials, 1, 1), 2, "slime", new ItemStack(toolShard, 1, 8), new ItemStack(toolRod, 1, 8), 8); + pb.registerFullMaterial(new ItemStack(materials, 1, 0), 2, "paper", new ItemStack(Item.paper), new ItemStack(toolRod, 1, 9), 9); Item[] items = { toolRod, pickaxeHead, shovelHead, axeHead, swordBlade, largeGuard, medGuard, crossbar, binding, frypanHead, signHead, lumberHead }; for (int iter = 0; iter < items.length; iter++) @@ -241,6 +242,14 @@ public class TConstructContent GameRegistry.addRecipe(new ItemStack(stonePattern, 1, 0), "ps", "sp", 'p', Block.stone, 's', new ItemStack(toolRod, 1, 1)); GameRegistry.addRecipe(new ItemStack(netherPattern, 1, 0), "ps", "sp", 'p', Block.netherrack, 's', new ItemStack(toolRod, 1, 7));*/ + GameRegistry.addRecipe(new ItemStack(materials, 1, 0), "pp", "pp", 'p', Item.paper); + GameRegistry.addShapelessRecipe(new ItemStack(craftedSoil, 1, 0), Item.slimeBall, Item.slimeBall, Item.slimeBall, Item.slimeBall, Block.sand, Block.dirt); + GameRegistry.addShapelessRecipe(new ItemStack(craftedSoil, 1, 1), Item.clay, Block.sand, Block.dirt); //Add stone dust? + + FurnaceRecipes.smelting().addSmelting(craftedSoil.blockID, 0, new ItemStack(materials, 1, 1), 2f); //Slime + FurnaceRecipes.smelting().addSmelting(craftedSoil.blockID, 1, new ItemStack(materials, 1, 2), 2f); //Seared brick item + GameRegistry.addRecipe(new ItemStack(searedBrick, 1, 0), "pp", "pp", 'p', new ItemStack(materials, 1, 2)); //Seared brick block + for (int i = 0; i < 12; i++) { GameRegistry.addRecipe(new ItemStack(TConstructContent.woodPattern, 1, i + 1), "s", 's', new ItemStack(TConstructContent.woodPattern, 1, i)); diff --git a/tinker/tconstruct/GuiHandler.java b/tinker/tconstruct/TConstructGuiHandler.java similarity index 70% rename from tinker/tconstruct/GuiHandler.java rename to tinker/tconstruct/TConstructGuiHandler.java index 9b4acb60..38a9028d 100644 --- a/tinker/tconstruct/GuiHandler.java +++ b/tinker/tconstruct/TConstructGuiHandler.java @@ -4,23 +4,17 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import tinker.common.InventoryLogic; -import tinker.tconstruct.client.gui.FrypanGui; -import tinker.tconstruct.client.gui.PartCrafterGui; -import tinker.tconstruct.client.gui.PatternChestGui; -import tinker.tconstruct.client.gui.ToolStationGui; -import tinker.tconstruct.logic.FrypanLogic; -import tinker.tconstruct.logic.PartCrafterLogic; -import tinker.tconstruct.logic.PatternChestLogic; -import tinker.tconstruct.logic.ToolStationLogic; +import tinker.tconstruct.client.gui.*; +import tinker.tconstruct.logic.*; import cpw.mods.fml.common.network.IGuiHandler; -public class GuiHandler implements IGuiHandler +public class TConstructGuiHandler implements IGuiHandler { - int stationID = 0; - int partID = 1; - int pchestID = 2; - int smeltery = 3; - int frypanID = 4; + public static int stationID = 0; + public static int partID = 1; + public static int pchestID = 2; + public static int smeltery = 3; + public static int frypanID = 4; @Override public Object getServerGuiElement (int ID, EntityPlayer player, World world, int x, int y, int z) @@ -40,6 +34,8 @@ public class GuiHandler implements IGuiHandler return new PartCrafterGui(player.inventory, (PartCrafterLogic) world.getBlockTileEntity(x, y, z), world, x, y, z); if (ID == pchestID) return new PatternChestGui(player.inventory, (PatternChestLogic) world.getBlockTileEntity(x, y, z), world, x, y, z); + if (ID == smeltery) + return new SmelteryGui(player.inventory, (SmelteryLogic) world.getBlockTileEntity(x, y, z), world, x, y, z); if (ID == frypanID) return new FrypanGui(player.inventory, (FrypanLogic) world.getBlockTileEntity(x, y, z), world, x, y, z); return null; diff --git a/tinker/tconstruct/blocks/EquipBlock.java b/tinker/tconstruct/blocks/EquipBlock.java index 4f87635f..9963dcda 100644 --- a/tinker/tconstruct/blocks/EquipBlock.java +++ b/tinker/tconstruct/blocks/EquipBlock.java @@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import tinker.common.InventoryBlock; +import tinker.tconstruct.TConstructGuiHandler; import tinker.tconstruct.TConstruct; import tinker.tconstruct.logic.FrypanLogic; @@ -90,8 +91,8 @@ public class EquipBlock extends InventoryBlock @Override public Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer) { - int md = world.getBlockMetadata(x, y, z); - return 3; + //int md = world.getBlockMetadata(x, y, z); + return TConstructGuiHandler.frypanID; } @Override diff --git a/tinker/tconstruct/blocks/LavaTankBlock.java b/tinker/tconstruct/blocks/LavaTankBlock.java index e2906b16..5926dcd1 100644 --- a/tinker/tconstruct/blocks/LavaTankBlock.java +++ b/tinker/tconstruct/blocks/LavaTankBlock.java @@ -1,5 +1,6 @@ package tinker.tconstruct.blocks; +import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; @@ -18,6 +19,7 @@ public class LavaTankBlock extends BlockContainer super(id, 49, Material.iron); setCreativeTab(TConstruct.blockTab); setBlockName("TConstruct.LavaTank"); + setStepSound(Block.soundGlassFootstep); } @Override @@ -51,7 +53,7 @@ public class LavaTankBlock extends BlockContainer if (liquid != null) { LavaTankLogic logic = (LavaTankLogic) world.getBlockTileEntity(x, y, z); - int amount = logic.fill(0, liquid, true); + int amount = logic.fill(liquid, true); if (amount > 0) return true; else diff --git a/tinker/tconstruct/blocks/SmelteryBlock.java b/tinker/tconstruct/blocks/SmelteryBlock.java index c6cfddc0..1151675c 100644 --- a/tinker/tconstruct/blocks/SmelteryBlock.java +++ b/tinker/tconstruct/blocks/SmelteryBlock.java @@ -27,6 +27,7 @@ public class SmelteryBlock extends InventoryBlock setStepSound(soundMetalFootstep); rand = new Random(); this.setCreativeTab(TConstruct.blockTab); + this.setBlockName("tconstruct.Smeltery"); } public String getTextureFile () @@ -166,6 +167,12 @@ public class SmelteryBlock extends InventoryBlock public void onBlockPlacedElsewhere(World world, int x, int y, int z, EntityLiving entityliving) { SmelteryLogic logic = (SmelteryLogic) world.getBlockTileEntity(x, y, z); - logic.scanWorld(); + logic.checkValidPlacement(); + } + + @Override + public void breakBlock (World world, int x, int y, int z, int par5, int par6) //Don't drop inventory + { + world.removeBlockTileEntity(x, y, z); } } diff --git a/tinker/tconstruct/blocks/TConstructBlock.java b/tinker/tconstruct/blocks/TConstructBlock.java index b6edbfb9..965aba9a 100644 --- a/tinker/tconstruct/blocks/TConstructBlock.java +++ b/tinker/tconstruct/blocks/TConstructBlock.java @@ -1,16 +1,23 @@ package tinker.tconstruct.blocks; -import tinker.tconstruct.TConstructContent; +import java.util.List; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.ItemStack; +import tinker.tconstruct.TConstruct; +import tinker.tconstruct.TConstructContent; public class TConstructBlock extends Block { - - public TConstructBlock(int id, int tex, Material material, float hardness) + int subblocks; + public TConstructBlock(int id, int tex, Material material, float hardness, int sub) { super(id, tex, material); setHardness(hardness); + this.setCreativeTab(TConstruct.blockTab); + subblocks = sub; } @Override @@ -31,4 +38,12 @@ public class TConstructBlock extends Block return TConstructContent.blockTexture; } + @Override + public void getSubBlocks (int id, CreativeTabs tab, List list) + { + for (int iter = 0; iter < subblocks; iter++) + { + list.add(new ItemStack(id, 1, iter)); + } + } } diff --git a/tinker/tconstruct/client/TProxyClient.java b/tinker/tconstruct/client/TProxyClient.java index c9419988..8e44f724 100644 --- a/tinker/tconstruct/client/TProxyClient.java +++ b/tinker/tconstruct/client/TProxyClient.java @@ -42,18 +42,24 @@ public class TProxyClient extends TProxyCommon public void addNames() { LanguageRegistry.addName(TConstructContent.lavaTank, "Lava Tank"); - LanguageRegistry.instance().addStringLocalization("itemGroup.TConstruct", "TConstruct Tools"); - LanguageRegistry.instance().addStringLocalization("itemGroup.TConMaterials", "TConstruct Materials"); + LanguageRegistry.instance().addStringLocalization("itemGroup.TConstructTools", "TConstruct Tools"); + LanguageRegistry.instance().addStringLocalization("itemGroup.TConstructMaterials", "TConstruct Materials"); + LanguageRegistry.instance().addStringLocalization("itemGroup.TConstructBlocks", "TConstruct Blocks"); LanguageRegistry.instance().addStringLocalization("crafters.ToolStation", "Tool Station"); LanguageRegistry.instance().addStringLocalization("crafters.PartBuilder", "Part Builder"); LanguageRegistry.instance().addStringLocalization("inventory.PatternChest", "Pattern Chest"); + LanguageRegistry.instance().addStringLocalization("crafters.Smeltery", "Smeltery"); LanguageRegistry.instance().addStringLocalization("crafters.Frypan", "Frying Pan"); LanguageRegistry.instance().addStringLocalization("ToolStation.Crafter.name", "Tool Station"); LanguageRegistry.instance().addStringLocalization("ToolStation.Parts.name", "Part Crafting"); LanguageRegistry.instance().addStringLocalization("ToolStation.PatternChest.name", "Pattern Chest"); + LanguageRegistry.instance().addStringLocalization("CraftedSoil.Slime.name", "Slimy Mud"); + LanguageRegistry.instance().addStringLocalization("CraftedSoil.Grout.name", "Grout"); + LanguageRegistry.instance().addStringLocalization("SearedBrick.Brick.name", "Seared Bricks"); + for (int mat = 0; mat < materialTypes.length; mat++) { for (int type = 0; type < toolMaterialNames.length; type++) @@ -64,6 +70,13 @@ public class TProxyClient extends TProxyCommon } } + for (int i = 0; i < materialItemNames.length; i++) + { + String internalName = "item.tconstruct.Materials."+materialItemInternalNames[i]+".name"; + String visibleName = materialItemNames[i]; + LanguageRegistry.instance().addStringLocalization(internalName, "en_US", visibleName); + } + for (int i = 0; i < patterns.length; i++) { String internalName = "item.tconstruct.Pattern."+patterns[i]+".name"; @@ -71,6 +84,8 @@ public class TProxyClient extends TProxyCommon LanguageRegistry.instance().addStringLocalization(internalName, "en_US", visibleName); } + LanguageRegistry.addName(TConstructContent.smeltery, "Smeltery"); + LanguageRegistry.addName(TConstructContent.pickaxe, "Pickaxe"); LanguageRegistry.addName(TConstructContent.shovel, "Shovel"); LanguageRegistry.addName(TConstructContent.axe, "Axe"); @@ -89,6 +104,11 @@ public class TProxyClient extends TProxyCommon return Minecraft.getMinecraftDir(); } + public static final String[] materialItemInternalNames = new String[] { + "PaperStack", "SlimeCrystal", "SearedBrick", "CobaltIngot", "ArditeIngot", "ManyullynIngot" }; + + public static final String[] materialItemNames = new String[] { + "Paper Stack", "Slime Crystal", "Seared Brick", "Cobalt Ingot", "Ardite Ingot", "Manyullyn Ingot" }; public static final String[] toolMaterialNames = new String[] { "Wood", "Stone", "Iron", "Flint", "Cactus", "Bone", "Obsidian", "Netherrack", "Slime", "Paper", "Cobalt", "Ardite", "Manyullyn" }; diff --git a/tinker/tconstruct/client/TankRender.java b/tinker/tconstruct/client/TankRender.java index e15c7caf..0459b4e3 100644 --- a/tinker/tconstruct/client/TankRender.java +++ b/tinker/tconstruct/client/TankRender.java @@ -30,12 +30,12 @@ public class TankRender implements ISimpleBlockRenderingHandler { renderer.renderStandardBlock(block, x, y, z); LavaTankLogic logic = (LavaTankLogic) world.getBlockTileEntity(x, y, z); - if (logic.amount > 0) + if (logic.getLiquidAmount() > 0) { Block liquidBlock = Block.blocksList[logic.liquid.itemID]; if (liquidBlock != null) { - renderer.setRenderBounds(0.03, 0.03, 0.03, 0.97, logic.amount/1020f, 0.97); + renderer.setRenderBounds(0.03, 0.03, 0.03, 0.97, logic.getLiquidAmount()/1020f, 0.97); renderer.renderStandardBlock(liquidBlock, x, y, z); } } diff --git a/tinker/tconstruct/client/gui/SmelteryContainer.java b/tinker/tconstruct/client/gui/SmelteryContainer.java new file mode 100644 index 00000000..b4c79315 --- /dev/null +++ b/tinker/tconstruct/client/gui/SmelteryContainer.java @@ -0,0 +1,123 @@ +package tinker.tconstruct.client.gui; + +import tinker.tconstruct.logic.SmelteryLogic; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.Slot; +import net.minecraft.inventory.SlotFurnace; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.FurnaceRecipes; +import net.minecraft.tileentity.TileEntityFurnace; + +public class SmelteryContainer extends Container +{ + public SmelteryLogic logic; + public int fuel = 0; + + public SmelteryContainer(InventoryPlayer inventoryplayer, SmelteryLogic frypan) + { + logic = frypan; + for (int y = 0; y < 3; y++) + for (int x = 0; x < 3; x++) + this.addSlotToContainer(new Slot(frypan, x + y*3, 62 + x*18, 15 + y*18)); + + /* Player inventory */ + for (int column = 0; column < 3; column++) + { + for (int row = 0; row < 9; row++) + { + this.addSlotToContainer(new Slot(inventoryplayer, row + column * 9 + 9, 8 + row * 18, 84 + column * 18)); + } + } + + for (int column = 0; column < 9; column++) + { + this.addSlotToContainer(new Slot(inventoryplayer, column, 8 + column * 18, 142)); + } + } + + @Override + public void detectAndSendChanges() + { + super.detectAndSendChanges(); + /*for (int i = 0; i < crafters.size(); i++) + { + ICrafting icrafting = (ICrafting)crafters.get(i); + if (progress != logic.progress) + { + icrafting.sendProgressBarUpdate(this, 0, logic.progress); + } + if (fuel != logic.fuel) + { + icrafting.sendProgressBarUpdate(this, 1, logic.fuel); + } + if (fuelGague != logic.fuelGague) + { + icrafting.sendProgressBarUpdate(this, 2, logic.fuelGague); + } + } + + progress = logic.progress; + fuel = logic.fuel; + fuelGague = logic.fuelGague;*/ + } + + public void updateProgressBar(int id, int value) + { + if (id == 0) + { + logic.fuelGague = value; + } + /* if (id == 1) + { + logic.fuel = value; + }*/ + /*if (id == 2) + { + logic.fuelGague = value; + }*/ + } + + @Override + public boolean canInteractWith(EntityPlayer entityplayer) + { + return logic.isUseableByPlayer(entityplayer); + } + + public ItemStack transferStackInSlot(EntityPlayer player, int slotID) + { + ItemStack stack = null; + Slot slot = (Slot)this.inventorySlots.get(slotID); + + if (slot != null && slot.getHasStack()) + { + ItemStack slotStack = slot.getStack(); + stack = slotStack.copy(); + + if (slotID < logic.getSizeInventory()) + { + if (!this.mergeItemStack(slotStack, logic.getSizeInventory(), this.inventorySlots.size(), true)) + { + return null; + } + } + else if (!this.mergeItemStack(slotStack, 0, logic.getSizeInventory(), false)) + { + return null; + } + + if (slotStack.stackSize == 0) + { + slot.putStack((ItemStack)null); + } + else + { + slot.onSlotChanged(); + } + } + + return stack; + } +} diff --git a/tinker/tconstruct/client/gui/SmelteryGui.java b/tinker/tconstruct/client/gui/SmelteryGui.java new file mode 100644 index 00000000..f1394a50 --- /dev/null +++ b/tinker/tconstruct/client/gui/SmelteryGui.java @@ -0,0 +1,58 @@ +package tinker.tconstruct.client.gui; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +import org.lwjgl.opengl.GL11; + +import tinker.tconstruct.logic.SmelteryLogic; + +public class SmelteryGui extends GuiContainer +{ + public SmelteryLogic logic; + + public SmelteryGui(InventoryPlayer inventoryplayer, SmelteryLogic smeltery, World world, int x, int y, int z) + { + super(smeltery.getGuiContainer(inventoryplayer, world, x, y, z)); + logic = smeltery; + } + + protected void drawGuiContainerForegroundLayer (int par1, int par2) + { + fontRenderer.drawString(StatCollector.translateToLocal("crafters.Smeltery"), 60, 5, 0x404040); + fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0x404040); + drawStats(); + } + + void drawStats () + { + fontRenderer.drawString("Temp: " + logic.getInternalTemperature(), xSize + 6, 6, 0xffffff); + for (int iter = 0; iter < 9; iter++) + fontRenderer.drawString("Slot "+iter+" temp: " + logic.getTempForSlot(iter), xSize + 6, 15+iter*9, 0xffffff); + } + + protected void drawGuiContainerBackgroundLayer (float f, int i, int j) + { + int texID = mc.renderEngine.getTexture("/tinkertextures/gui/smeltery.png"); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.renderEngine.bindTexture(texID); + int cornerX = (width - xSize) / 2; + int cornerY = (height - ySize) / 2; + drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize); + if (logic.fuelGague > 0) + { + int fuel = logic.getScaledFuelGague(52); + drawTexturedModalRect(cornerX + 146, (cornerY + 67) - fuel, 176, 52 - fuel, 14, fuel + 2); + } + + // Draw description + texID = this.mc.renderEngine.getTexture("/tinkertextures/gui/description.png"); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.renderEngine.bindTexture(texID); + cornerX = (this.width + this.xSize) / 2; + cornerY = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(cornerX, cornerY, 0, 0, this.xSize, this.ySize); + } +} diff --git a/tinker/tconstruct/client/gui/ToolStationGui.java b/tinker/tconstruct/client/gui/ToolStationGui.java index b937c1ca..ceff8329 100644 --- a/tinker/tconstruct/client/gui/ToolStationGui.java +++ b/tinker/tconstruct/client/gui/ToolStationGui.java @@ -40,7 +40,7 @@ public class ToolStationGui extends GuiContainer this.text.setVisible(true); this.text.setCanLoseFocus(false); this.text.setFocused(true); - this.text.setTextColor(16777215); + this.text.setTextColor(0xffffff); resetGui(); } @@ -145,7 +145,7 @@ public class ToolStationGui extends GuiContainer ItemStack stack = logic.getStackInSlot(0); ToolCore tool = (ToolCore) stack.getItem(); NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); - this.drawCenteredString(fontRenderer, "\u00A7n"+tool.getToolName(), xSize + 63, 8, 16777215); + this.drawCenteredString(fontRenderer, "\u00A7n"+tool.getToolName(), xSize + 63, 8, 0xffffff); if (tool instanceof Weapon) drawWeaponStats(stack, tool, tags); else if (tool.getHeadType() == 3) @@ -159,13 +159,13 @@ public class ToolStationGui extends GuiContainer int dur = tags.getInteger("Damage"); int maxDur = tags.getInteger("TotalDurability"); dur = maxDur - dur; - fontRenderer.drawString("Durability: " + dur + "/" + maxDur, xSize + 8, 24, 16777215); + fontRenderer.drawString("Durability: " + dur + "/" + maxDur, xSize + 8, 24, 0xffffff); int damage = tags.getInteger("Attack"); - fontRenderer.drawString("Damage: " + damage, xSize + 8, 35, 16777215); + fontRenderer.drawString("Damage: " + damage, xSize + 8, 35, 0xffffff); - fontRenderer.drawString("Modifiers remaining: " + tags.getInteger("Modifiers"), xSize + 8, 57, 16777215); + fontRenderer.drawString("Modifiers remaining: " + tags.getInteger("Modifiers"), xSize + 8, 57, 0xffffff); if (tags.hasKey("Tooltip1")); - fontRenderer.drawString("Modifiers:", xSize + 8, 68, 16777215); + fontRenderer.drawString("Modifiers:", xSize + 8, 68, 0xffffff); boolean displayToolTips = true; int tipNum = 0; @@ -176,7 +176,7 @@ public class ToolStationGui extends GuiContainer if (tags.hasKey(tooltip)) { String tipName = tags.getString(tooltip); - fontRenderer.drawString("- "+tipName, xSize + 8, 68 + tipNum*11, 16777215); + fontRenderer.drawString("- "+tipName, xSize + 8, 68 + tipNum*11, 0xffffff); } else displayToolTips = false; @@ -188,16 +188,16 @@ public class ToolStationGui extends GuiContainer int dur = tags.getInteger("Damage"); int maxDur = tags.getInteger("TotalDurability"); dur = maxDur - dur; - fontRenderer.drawString("Durability: " + dur + "/" + maxDur, xSize + 8, 24, 16777215); + fontRenderer.drawString("Durability: " + dur + "/" + maxDur, xSize + 8, 24, 0xffffff); int damage = tags.getInteger("Attack"); - fontRenderer.drawString("Damage: " + damage, xSize + 8, 35, 16777215); + fontRenderer.drawString("Damage: " + damage, xSize + 8, 35, 0xffffff); float mineSpeed = tags.getInteger("MiningSpeed") / 100f; - fontRenderer.drawString("Mining Speed: " + mineSpeed, xSize + 8, 46, 16777215); - fontRenderer.drawString("Mining Level: " + getHarvestLevelName(tags.getInteger("HarvestLevel")), xSize + 8, 57, 16777215); + fontRenderer.drawString("Mining Speed: " + mineSpeed, xSize + 8, 46, 0xffffff); + fontRenderer.drawString("Mining Level: " + getHarvestLevelName(tags.getInteger("HarvestLevel")), xSize + 8, 57, 0xffffff); - fontRenderer.drawString("Modifiers remaining: " + tags.getInteger("Modifiers"), xSize + 8, 79, 16777215); + fontRenderer.drawString("Modifiers remaining: " + tags.getInteger("Modifiers"), xSize + 8, 79, 0xffffff); if (tags.hasKey("Tooltip1")); - fontRenderer.drawString("Modifiers:", xSize + 8, 90, 16777215); + fontRenderer.drawString("Modifiers:", xSize + 8, 90, 0xffffff); boolean displayToolTips = true; int tipNum = 0; @@ -208,7 +208,7 @@ public class ToolStationGui extends GuiContainer if (tags.hasKey(tooltip)) { String tipName = tags.getString(tooltip); - fontRenderer.drawString("- "+tipName, xSize + 8, 90 + tipNum*11, 16777215); + fontRenderer.drawString("- "+tipName, xSize + 8, 90 + tipNum*11, 0xffffff); } else displayToolTips = false; @@ -220,18 +220,18 @@ public class ToolStationGui extends GuiContainer int dur = tags.getInteger("Damage"); int maxDur = tags.getInteger("TotalDurability"); dur = maxDur - dur; - fontRenderer.drawString("Durability: " + dur + "/" + maxDur, xSize + 8, 24, 16777215); + fontRenderer.drawString("Durability: " + dur + "/" + maxDur, xSize + 8, 24, 0xffffff); float mineSpeed = tags.getInteger("MiningSpeed") / 100f; float mineSpeed2 = tags.getInteger("MiningSpeed2") / 100f; - fontRenderer.drawString("Mining Speeds: ", xSize + 8, 35, 16777215); - fontRenderer.drawString("- "+mineSpeed+", "+mineSpeed2, xSize + 8, 46, 16777215); - fontRenderer.drawString("Harvest Levels:", xSize + 8, 57, 16777215); - fontRenderer.drawString("- " + getHarvestLevelName(tags.getInteger("HarvestLevel")), xSize + 8, 68, 16777215); - fontRenderer.drawString("- " + getHarvestLevelName(tags.getInteger("HarvestLevel2")), xSize + 8, 79, 16777215); + fontRenderer.drawString("Mining Speeds: ", xSize + 8, 35, 0xffffff); + fontRenderer.drawString("- "+mineSpeed+", "+mineSpeed2, xSize + 8, 46, 0xffffff); + fontRenderer.drawString("Harvest Levels:", xSize + 8, 57, 0xffffff); + fontRenderer.drawString("- " + getHarvestLevelName(tags.getInteger("HarvestLevel")), xSize + 8, 68, 0xffffff); + fontRenderer.drawString("- " + getHarvestLevelName(tags.getInteger("HarvestLevel2")), xSize + 8, 79, 0xffffff); - fontRenderer.drawString("Modifiers remaining: " + tags.getInteger("Modifiers"), xSize + 8, 90, 16777215); + fontRenderer.drawString("Modifiers remaining: " + tags.getInteger("Modifiers"), xSize + 8, 90, 0xffffff); if (tags.hasKey("Tooltip1")); - fontRenderer.drawString("Modifiers:", xSize + 8, 101, 16777215); + fontRenderer.drawString("Modifiers:", xSize + 8, 101, 0xffffff); boolean displayToolTips = true; int tipNum = 0; @@ -242,7 +242,7 @@ public class ToolStationGui extends GuiContainer if (tags.hasKey(tooltip)) { String tipName = tags.getString(tooltip); - fontRenderer.drawString("- "+tipName, xSize + 8, 101 + tipNum*11, 16777215); + fontRenderer.drawString("- "+tipName, xSize + 8, 101 + tipNum*11, 0xffffff); } else displayToolTips = false; @@ -251,8 +251,8 @@ public class ToolStationGui extends GuiContainer void drawToolInformation () { - this.drawCenteredString(fontRenderer, title, xSize + 63, 8, 16777215); - fontRenderer.drawSplitString(body, xSize + 8, 24, 115, 16777215); + this.drawCenteredString(fontRenderer, title, xSize + 63, 8, 0xffffff); + fontRenderer.drawSplitString(body, xSize + 8, 24, 115, 0xffffff); } String getHarvestLevelName (int num) diff --git a/tinker/tconstruct/crafting/PatternBuilder.java b/tinker/tconstruct/crafting/PatternBuilder.java index 6d4a8d35..341a219a 100644 --- a/tinker/tconstruct/crafting/PatternBuilder.java +++ b/tinker/tconstruct/crafting/PatternBuilder.java @@ -1,6 +1,6 @@ package tinker.tconstruct.crafting; - +/** How to build tool parts? With patterns! */ import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/tinker/tconstruct/crafting/Smeltery.java b/tinker/tconstruct/crafting/Smeltery.java new file mode 100644 index 00000000..06d90402 --- /dev/null +++ b/tinker/tconstruct/crafting/Smeltery.java @@ -0,0 +1,81 @@ +package tinker.tconstruct.crafting; + +import java.util.*; +import net.minecraft.item.ItemStack; + +/** Melting and hacking, churn and burn */ +public class Smeltery +{ + public static Smeltery instance = new Smeltery(); + + private HashMap, ItemStack> smeltingList = new HashMap, ItemStack>(); + private HashMap, Integer> temperatureList = new HashMap, Integer>(); + + /** Adds a mapping between an input and an itemstack + * + * @param itemID The block or item's main ID + * @param metadata Damage or use + * @param itemstack + */ + public static void addSmelting(int itemID, int metadata, int temperature, ItemStack itemstack) + { + instance.smeltingList.put(Arrays.asList(itemID, metadata), itemstack); + instance.temperatureList.put(Arrays.asList(itemID, metadata), temperature); + } + + /** + * Used to get the resulting temperature from a source ItemStack + * @param item The Source ItemStack + * @return The result temperature + */ + public static Integer getSmeltingTemperature(ItemStack item) + { + if (item == null) + return null; + + return instance.temperatureList.get(Arrays.asList(item.itemID, item.getItemDamage())); + } + + public static Integer getSmeltingTemperature(int blockID) + { + return getSmeltingTemperature(blockID, 0); + } + + /** + * Used to get the resulting temperature from a source Block + * @param item The Source ItemStack + * @return The result ItemStack + */ + public static Integer getSmeltingTemperature(int blockID, int metadata) + { + return instance.temperatureList.get(Arrays.asList(blockID, metadata)); + } + + /** + * Used to get the resulting ItemStack from a source ItemStack + * @param item The Source ItemStack + * @return The result ItemStack + */ + public static ItemStack getSmeltingResult(ItemStack item) + { + if (item == null) + return null; + + return (ItemStack) instance.smeltingList.get(Arrays.asList(item.itemID, item.getItemDamage())).copy(); + } + + public static ItemStack getSmeltingResult(int blockID) + { + return getSmeltingResult(blockID, 0); + } + + /** + * Used to get the resulting ItemStack from a source Block + * @param item The Source ItemStack + * @return The result ItemStack + */ + public static ItemStack getSmeltingResult(int blockID, int metadata) + { + return (ItemStack) instance.smeltingList.get(Arrays.asList(blockID, metadata)).copy(); + } +} diff --git a/tinker/tconstruct/crafting/ToolBuilder.java b/tinker/tconstruct/crafting/ToolBuilder.java index 5e54f6fa..b03cc791 100644 --- a/tinker/tconstruct/crafting/ToolBuilder.java +++ b/tinker/tconstruct/crafting/ToolBuilder.java @@ -1,6 +1,6 @@ package tinker.tconstruct.crafting; - +/** Once upon a time, too many tools to count. Let's put them together automatically */ import java.util.*; import tinker.tconstruct.EnumMaterial; diff --git a/tinker/tconstruct/items/Materials.java b/tinker/tconstruct/items/Materials.java index 7e7e0f51..ec273fa5 100644 --- a/tinker/tconstruct/items/Materials.java +++ b/tinker/tconstruct/items/Materials.java @@ -39,5 +39,5 @@ public class Materials extends Item } public static final String[] materialNames = new String[] { - "PaperStack", "SlimeCrystal", "HardenedBrick", "CobaltIngot", "ArditeIngot", "ManyullynIngot" }; + "PaperStack", "SlimeCrystal", "SearedBrick", "CobaltIngot", "ArditeIngot", "ManyullynIngot" }; } diff --git a/tinker/tconstruct/logic/LavaTankLogic.java b/tinker/tconstruct/logic/LavaTankLogic.java index b2be005b..c47499e8 100644 --- a/tinker/tconstruct/logic/LavaTankLogic.java +++ b/tinker/tconstruct/logic/LavaTankLogic.java @@ -7,81 +7,86 @@ import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.liquids.ILiquidTank; -import net.minecraftforge.liquids.ITankContainer; import net.minecraftforge.liquids.LiquidContainerRegistry; import net.minecraftforge.liquids.LiquidStack; import net.minecraftforge.liquids.LiquidTank; public class LavaTankLogic extends TileEntity - implements ITankContainer + implements ILiquidTank { public LiquidTank tank; - public int amount; public int max; + public int pressure; public LiquidStack liquid; public LavaTankLogic() { tank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME); - max = 1; - amount = 0; + max = LiquidContainerRegistry.BUCKET_VOLUME; } - + @Override - public int fill (ForgeDirection from, LiquidStack resource, boolean doFill) + public LiquidStack getLiquid () { - return fill(0, resource, doFill); + return liquid; + } + + public int getLiquidAmount () + { + if (liquid == null) + return 0; + else + return liquid.amount; } @Override - public int fill (int tankIndex, LiquidStack resource, boolean doFill) + public int getCapacity () + { + return max; + } + + @Override + public int fill (LiquidStack resource, boolean doFill) { if (resource == null) - return 0; - + return 0; if (liquid == null) { - liquid = resource; - amount = resource.amount; + liquid = resource.copy(); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - return amount; + return liquid.amount; } - else if (resource.amount + amount > max*1000) + else if (resource.amount + liquid.amount > max) { if (doFill) { worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - amount = 4000; + liquid.amount = max; } - return resource.amount + amount - 4000; + return max - resource.amount; } else { if (doFill) { worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - amount += resource.amount; + liquid.amount += resource.amount; } - return amount; + return resource.amount; } } @Override - public LiquidStack drain (ForgeDirection from, int maxDrain, boolean doDrain) + public LiquidStack drain (int maxDrain, boolean doDrain) { - return drain(0, maxDrain, doDrain); - } - - @Override - public LiquidStack drain (int tankIndex, int maxDrain, boolean doDrain) - { - if (amount - maxDrain < 0) + if (liquid == null) + return null; + if (liquid.amount - maxDrain < 0) { - LiquidStack liq = new LiquidStack(liquid.itemID, 0, liquid.itemMeta); + LiquidStack liq = liquid.copy(); if (doDrain) { - amount = 0; liquid = null; worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } @@ -91,29 +96,22 @@ public class LavaTankLogic extends TileEntity { if (doDrain) { - amount -= maxDrain; + liquid.amount -= maxDrain; worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } - return new LiquidStack(liquid.itemID, amount - maxDrain, liquid.itemMeta); + return new LiquidStack(liquid.itemID, maxDrain, liquid.itemMeta); } } @Override - public ILiquidTank[] getTanks (ForgeDirection direction) + public int getTankPressure () { - return new ILiquidTank[] { (ILiquidTank) this }; - } - - @Override - public ILiquidTank getTank (ForgeDirection direction, LiquidStack type) - { - return (ILiquidTank) this; + return 0; } public void readFromNBT(NBTTagCompound par1NBTTagCompound) { - this.amount = par1NBTTagCompound.getInteger("amount"); - this.liquid = new LiquidStack(par1NBTTagCompound.getInteger("itemID"), amount, par1NBTTagCompound.getInteger("itemMeta")); + this.liquid = new LiquidStack(par1NBTTagCompound.getInteger("itemID"), par1NBTTagCompound.getInteger("amount"), par1NBTTagCompound.getInteger("itemMeta")); super.readFromNBT(par1NBTTagCompound); } @@ -122,7 +120,7 @@ public class LavaTankLogic extends TileEntity if (liquid != null) { par1NBTTagCompound.setInteger("itemID", liquid.itemID); - par1NBTTagCompound.setInteger("amount", this.amount); + par1NBTTagCompound.setInteger("amount", liquid.amount); par1NBTTagCompound.setInteger("itemMeta", liquid.itemMeta); } else diff --git a/tinker/tconstruct/logic/SmelteryLogic.java b/tinker/tconstruct/logic/SmelteryLogic.java index 508f5035..33e83664 100644 --- a/tinker/tconstruct/logic/SmelteryLogic.java +++ b/tinker/tconstruct/logic/SmelteryLogic.java @@ -3,10 +3,22 @@ package tinker.tconstruct.logic; import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.INetworkManager; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.Packet132TileEntityData; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraftforge.liquids.ILiquidTank; +import net.minecraftforge.liquids.LiquidStack; import tinker.common.IActiveLogic; import tinker.common.IFacingLogic; import tinker.common.InventoryLogic; +import tinker.tconstruct.TConstructContent; +import tinker.tconstruct.client.gui.SmelteryContainer; +import tinker.tconstruct.crafting.Smeltery; /* Simple class for storing items in the block */ @@ -14,15 +26,25 @@ import tinker.common.InventoryLogic; public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFacingLogic { - int temperature; - int useTime; + boolean validStructure; byte direction; + int internalTemp; + int maxTemp; + int useTime; + public int fuelGague; + int[] tankCoords; + int[] bottomTemps; + int tick; public SmelteryLogic() { - super(5); + super(9); + bottomTemps = new int[9]; + for (int i = 0; i < 9; i++) + bottomTemps[i] = 20; } + /* Misc */ @Override public String getInvName () { @@ -32,7 +54,7 @@ public class SmelteryLogic extends InventoryLogic @Override public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z) { - return null; + return new SmelteryContainer(inventoryplayer, this); } @Override @@ -50,7 +72,7 @@ public class SmelteryLogic extends InventoryLogic @Override public boolean getActive() { - return false; + return validStructure; } @Override @@ -65,40 +87,313 @@ public class SmelteryLogic extends InventoryLogic return false; } - public void scanWorld() + public int getScaledFuelGague (int scale) + { + return (fuelGague * scale) / 52; + } + + public int getInternalTemperature () + { + return internalTemp; + } + + public int getTempForSlot (int slot) + { + return bottomTemps[slot]; + } + + /* Updating */ + public void updateEntity () + { + tick++; + if (tick % 4 == 0) + updateTemperatures(); + + if (tick == 20) + { + tick = 0; + checkValidPlacement(); + updateFuelGague(); + + if (useTime > 0) + useTime--; + if (!worldObj.isRemote) + matchInventoryToWorld(); + + if (validStructure && useTime == 0) + { + TileEntity tank = worldObj.getBlockTileEntity(tankCoords[0], tankCoords[1], tankCoords[2]); + if (tank instanceof ILiquidTank) + { + LiquidStack liquid = ((ILiquidTank)tank).drain(10, true); + if (liquid != null) + { + System.out.println("Drained "+liquid.amount); + useTime += liquid.amount; + } + } + } + } + } + + void updateTemperatures() + { + for (int i = 0; i < 9; i++) + { + if (this.isStackInSlot(i) && bottomTemps[i] < internalTemp) + bottomTemps[i] += 1; + else + bottomTemps[i] = 20; + } + } + + void updateFuelGague() + { + if (tankCoords == null || tankCoords.length < 3) + return; + + TileEntity tank = worldObj.getBlockTileEntity(tankCoords[0], tankCoords[1], tankCoords[2]); + if (tank == null) + { + fuelGague = 0; + } + if (tank instanceof ILiquidTank) + { + LiquidStack liquid = ((ILiquidTank)tank).getLiquid(); + int capacity = ((ILiquidTank)tank).getCapacity(); + if (liquid != null) + fuelGague = liquid.amount * 52 / capacity; + else + fuelGague = 0; + } + } + + public ItemStack getResultFor (ItemStack stack) + { + ItemStack result = Smeltery.instance.getSmeltingResult(stack); + if (result != null) + return result; + + return null; + } + + /* Inventory */ + public int getInventoryStackLimit () + { + return 1; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemstack) + { + super.setInventorySlotContents(slot, itemstack); + setWorldToInventory(); + } + + @Override + public ItemStack decrStackSize(int slot, int quantity) + { + ItemStack stack = super.decrStackSize(slot, quantity); + setWorldToInventory(); + return stack; + } + + /* World-inventory matching */ + void matchInventoryToWorld() { switch(getDirection()) { case 2: // +z - //worldObj.setBlockWithNotify(xCoord, yCoord, zCoord+1, Block.dirt.blockID); - placeBlockRing(xCoord, yCoord, zCoord+2); + grabWorldBlocks(xCoord, yCoord, zCoord+2); break; case 3: // -z - //worldObj.setBlockWithNotify(xCoord, yCoord, zCoord-1, Block.dirt.blockID); - placeBlockRing(xCoord, yCoord, zCoord-2); + grabWorldBlocks(xCoord, yCoord, zCoord-2); break; case 4: // +x - //worldObj.setBlockWithNotify(xCoord+1, yCoord, zCoord, Block.dirt.blockID); - placeBlockRing(xCoord+2, yCoord, zCoord); + grabWorldBlocks(xCoord+2, yCoord, zCoord); break; case 5: // -x - //worldObj.setBlockWithNotify(xCoord-1, yCoord, zCoord, Block.dirt.blockID); - placeBlockRing(xCoord-2, yCoord, zCoord); + grabWorldBlocks(xCoord-2, yCoord, zCoord); break; } } - public void placeBlockRing(int x, int y, int z) + void setWorldToInventory() { + switch(getDirection()) + { + case 2: // +z + setWorldToInventory(xCoord, yCoord, zCoord+2); + break; + case 3: // -z + setWorldToInventory(xCoord, yCoord, zCoord-2); + break; + case 4: // +x + setWorldToInventory(xCoord+2, yCoord, zCoord); + break; + case 5: // -x + setWorldToInventory(xCoord-2, yCoord, zCoord); + break; + } + } + + public void grabWorldBlocks(int x, int y, int z) + { + for (int xPos = 0; xPos <= 2; xPos++) + { + for (int zPos = 0; zPos <= 2; zPos++) + { + int bID = worldObj.getBlockId(xPos+x-1, y, zPos+z-1); + + ItemStack stack = inventory[xPos+zPos*3]; + if (bID == 0) + inventory[xPos+zPos*3] = null; + else if (stack == null || stack.itemID != bID) + inventory[xPos+zPos*3] = new ItemStack(bID, 1, worldObj.getBlockMetadata(xPos+x-1, y, zPos+z-1)); + } + } + } + + public void setWorldToInventory(int x, int y, int z) + { + for (int xPos = 0; xPos <= 2; xPos++) + { + for (int zPos = 0; zPos <= 2; zPos++) + { + ItemStack stack = inventory[xPos+zPos*3]; + if (stack == null) + worldObj.setBlockWithNotify(xPos+x-1, y, zPos+z-1, 0); + + else if (stack.itemID < Block.blocksList.length && Block.blocksList[stack.itemID] != null) + worldObj.setBlockAndMetadataWithNotify(xPos+x-1, y, zPos+z-1, stack.itemID, stack.getItemDamage()); + } + } + } + + public void checkValidPlacement() + { + switch(getDirection()) + { + case 2: // +z + checkValidStructure(xCoord, yCoord, zCoord+2); + break; + case 3: // -z + checkValidStructure(xCoord, yCoord, zCoord-2); + break; + case 4: // +x + checkValidStructure(xCoord+2, yCoord, zCoord); + break; + case 5: // -x + checkValidStructure(xCoord-2, yCoord, zCoord); + break; + } + } + + public void checkValidStructure(int x, int y, int z) + { + int numBricks = 0; + boolean lavaTank = false; + + //Check outer layer for (int xPos = x-1; xPos <= x+1; xPos++) { - worldObj.setBlockWithNotify(xPos, y, z-2, Block.dirt.blockID); - worldObj.setBlockWithNotify(xPos, y, z+2, Block.dirt.blockID); + int southID = worldObj.getBlockId(xPos, y, z-2); + int northID = worldObj.getBlockId(xPos, y, z+2); + if (southID == TConstructContent.searedBrick.blockID) + numBricks++; + else if (southID == TConstructContent.lavaTank.blockID) + { + tankCoords = new int[] {xPos, y, z-2}; + lavaTank = true; + } + + if (northID == TConstructContent.searedBrick.blockID) + numBricks++; + else if (northID == TConstructContent.lavaTank.blockID) + { + tankCoords = new int[] {xPos, y, z+2}; + lavaTank = true; + } } for (int zPos = z-1; zPos <= z+1; zPos++) { - worldObj.setBlockWithNotify(x-2, y, zPos, Block.dirt.blockID); - worldObj.setBlockWithNotify(x+2, y, zPos, Block.dirt.blockID); + int westID = worldObj.getBlockId(x-2, y, zPos); + int eastID = worldObj.getBlockId(x+2, y, zPos); + if (westID == TConstructContent.searedBrick.blockID) + numBricks++; + else if (westID == TConstructContent.lavaTank.blockID) + { + tankCoords = new int[] {x-2, y, zPos}; + lavaTank = true; + } + + if (eastID == TConstructContent.searedBrick.blockID) + numBricks++; + else if (eastID == TConstructContent.lavaTank.blockID) + { + tankCoords = new int[] {x+2, y, zPos}; + lavaTank = true; + } + } + + //Check floor + for (int xPos = x-1; xPos <= x+1; xPos++) + { + for (int zPos = z-1; zPos <= z+1; zPos++) + { + if (worldObj.getBlockId(xPos, y-1, zPos) == TConstructContent.searedBrick.blockID) + numBricks++; + } + } + + if (numBricks == 19 && lavaTank) + { + validStructure = true; + internalTemp = 550; + } + else + { + validStructure = false; + internalTemp = 20; } } + + /* NBT */ + @Override + public void readFromNBT(NBTTagCompound tags) + { + super.readFromNBT(tags); + validStructure = tags.getBoolean("ValidStructure"); + direction = tags.getByte("Direction"); + useTime = tags.getInteger("UseTime"); + internalTemp = tags.getInteger("Temp"); + tankCoords = tags.getIntArray("TankCoords"); + } + + @Override + public void writeToNBT(NBTTagCompound tags) + { + super.writeToNBT(tags); + tags.setBoolean("ValidStructure", validStructure); + tags.setByte("Direction", direction); + tags.setInteger("UseTime", useTime); + tags.setInteger("Temp", internalTemp); + tags.setIntArray("TankCoords", tankCoords); + } + + /* Packets */ + @Override + public Packet getDescriptionPacket () + { + NBTTagCompound tag = new NBTTagCompound(); + writeToNBT(tag); + return new Packet132TileEntityData(xCoord, yCoord, zCoord, 1, tag); + } + + @Override + public void onDataPacket (INetworkManager net, Packet132TileEntityData packet) + { + worldObj.getBlockTileEntity(xCoord, yCoord, zCoord).readFromNBT(packet.customParam1); + worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); + } } diff --git a/tinker/tconstruct/modifiers/ModRepair.java b/tinker/tconstruct/modifiers/ModRepair.java index 8bbaedda..954c6384 100644 --- a/tinker/tconstruct/modifiers/ModRepair.java +++ b/tinker/tconstruct/modifiers/ModRepair.java @@ -63,6 +63,8 @@ public class ModRepair extends ToolMod damage = 0; tags.setInteger("Damage", damage); + tool.setItemDamage(damage * 100 / dur); + int repair = tags.getInteger("RepairCount"); repair += 1; tags.setInteger("RepairCount", repair); diff --git a/tinker/tconstruct/tools/Axe.java b/tinker/tconstruct/tools/Axe.java index 1950b497..d07f7ab1 100644 --- a/tinker/tconstruct/tools/Axe.java +++ b/tinker/tconstruct/tools/Axe.java @@ -1,9 +1,11 @@ package tinker.tconstruct.tools; import tinker.tconstruct.AbilityHelper; +import tinker.tconstruct.TConstructContent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLiving; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -44,4 +46,16 @@ public class Axe extends HarvestTool } static Material[] materials = { Material.wood, Material.circuits, Material.cactus, Material.pumpkin }; + + @Override + protected Item getHeadItem () + { + return TConstructContent.axeHead; + } + + @Override + protected Item getAccessoryItem () + { + return null; + } } diff --git a/tinker/tconstruct/tools/BattleSign.java b/tinker/tconstruct/tools/BattleSign.java index 3f930ba8..37fbcb5c 100644 --- a/tinker/tconstruct/tools/BattleSign.java +++ b/tinker/tconstruct/tools/BattleSign.java @@ -1,6 +1,7 @@ package tinker.tconstruct.tools; import tinker.tconstruct.AbilityHelper; +import tinker.tconstruct.TConstructContent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; @@ -8,6 +9,7 @@ import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.MathHelper; @@ -28,6 +30,11 @@ public class BattleSign extends Weapon return stack; } + public String getToolName () + { + return "Battle Sign"; + } + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer player, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { if (par7 == 0 || !player.isSneaking()) @@ -97,4 +104,16 @@ public class BattleSign extends Weapon } } } + + @Override + protected Item getHeadItem () + { + return TConstructContent.signHead; + } + + @Override + protected Item getAccessoryItem () + { + return null; + } } diff --git a/tinker/tconstruct/tools/Broadsword.java b/tinker/tconstruct/tools/Broadsword.java index 7ca4fa93..c1457d61 100644 --- a/tinker/tconstruct/tools/Broadsword.java +++ b/tinker/tconstruct/tools/Broadsword.java @@ -1,9 +1,11 @@ package tinker.tconstruct.tools; import tinker.tconstruct.AbilityHelper; +import tinker.tconstruct.TConstructContent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLiving; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -14,4 +16,16 @@ public class Broadsword extends Weapon super(itemID, 4, tex); this.setItemName("InfiTool.Broadsword"); } + + @Override + protected Item getHeadItem () + { + return TConstructContent.swordBlade; + } + + @Override + protected Item getAccessoryItem () + { + return TConstructContent.largeGuard; + } } diff --git a/tinker/tconstruct/tools/FryingPan.java b/tinker/tconstruct/tools/FryingPan.java index d7bdfdc4..c5d8d484 100644 --- a/tinker/tconstruct/tools/FryingPan.java +++ b/tinker/tconstruct/tools/FryingPan.java @@ -2,6 +2,7 @@ package tinker.tconstruct.tools; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; @@ -90,4 +91,16 @@ public class FryingPan extends Weapon } } } + + @Override + protected Item getHeadItem () + { + return TConstructContent.frypanHead; + } + + @Override + protected Item getAccessoryItem () + { + return null; + } } diff --git a/tinker/tconstruct/tools/Hammer.java b/tinker/tconstruct/tools/Hammer.java index fac2acc3..c6f0bb48 100644 --- a/tinker/tconstruct/tools/Hammer.java +++ b/tinker/tconstruct/tools/Hammer.java @@ -6,6 +6,7 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import tinker.tconstruct.AbilityHelper; @@ -82,4 +83,16 @@ public class Hammer extends HarvestTool } return AbilityHelper.onBlockChanged(itemstack, world, bID, x, y, z, living, random); } + + @Override + protected Item getHeadItem () + { + return null; + } + + @Override + protected Item getAccessoryItem () + { + return null; + } } diff --git a/tinker/tconstruct/tools/Longsword.java b/tinker/tconstruct/tools/Longsword.java index 1e0c42b9..7f27930e 100644 --- a/tinker/tconstruct/tools/Longsword.java +++ b/tinker/tconstruct/tools/Longsword.java @@ -1,11 +1,13 @@ package tinker.tconstruct.tools; import tinker.tconstruct.AbilityHelper; +import tinker.tconstruct.TConstructContent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; @@ -37,6 +39,18 @@ public class Longsword extends Weapon AbilityHelper.thrust(stack, world, player); player.swingItem(); } + + @Override + protected Item getHeadItem () + { + return TConstructContent.swordBlade; + } + + @Override + protected Item getAccessoryItem () + { + return TConstructContent.medGuard; + } /*@Override public boolean hitEntity(ItemStack stack, EntityLiving mob, EntityLiving player) diff --git a/tinker/tconstruct/tools/LumberAxe.java b/tinker/tconstruct/tools/LumberAxe.java index 6a5ac4c2..c8175d36 100644 --- a/tinker/tconstruct/tools/LumberAxe.java +++ b/tinker/tconstruct/tools/LumberAxe.java @@ -7,10 +7,12 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import tinker.tconstruct.AbilityHelper; +import tinker.tconstruct.TConstructContent; public class LumberAxe extends HarvestTool { @@ -157,4 +159,16 @@ public class LumberAxe extends HarvestTool } } } + + @Override + protected Item getHeadItem () + { + return TConstructContent.lumberHead; + } + + @Override + protected Item getAccessoryItem () + { + return null; + } } diff --git a/tinker/tconstruct/tools/Mattock.java b/tinker/tconstruct/tools/Mattock.java index 6248b43a..44e03079 100644 --- a/tinker/tconstruct/tools/Mattock.java +++ b/tinker/tconstruct/tools/Mattock.java @@ -1,9 +1,11 @@ package tinker.tconstruct.tools; import tinker.tconstruct.AbilityHelper; +import tinker.tconstruct.TConstructContent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; @@ -52,4 +54,16 @@ public class Mattock extends DualHarvestTool { return AbilityHelper.hoeGround(stack, player, world, x, y, z, side, random); } + + @Override + protected Item getHeadItem () + { + return TConstructContent.axeHead; + } + + @Override + protected Item getAccessoryItem () + { + return TConstructContent.shovelHead; + } } \ No newline at end of file diff --git a/tinker/tconstruct/tools/Pickaxe.java b/tinker/tconstruct/tools/Pickaxe.java index 0f372550..5b30f04a 100644 --- a/tinker/tconstruct/tools/Pickaxe.java +++ b/tinker/tconstruct/tools/Pickaxe.java @@ -3,6 +3,7 @@ package tinker.tconstruct.tools; import tinker.tconstruct.TConstructContent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.item.Item; public class Pickaxe extends HarvestTool { @@ -31,4 +32,16 @@ public class Pickaxe extends HarvestTool } static Material[] materials = new Material[] { Material.rock, Material.iron, Material.ice, Material.glass, Material.piston, Material.anvil }; + + @Override + protected Item getHeadItem () + { + return TConstructContent.pickaxeHead; + } + + @Override + protected Item getAccessoryItem () + { + return TConstructContent.binding; + } } diff --git a/tinker/tconstruct/tools/Rapier.java b/tinker/tconstruct/tools/Rapier.java index 2439f40c..5f8261ee 100644 --- a/tinker/tconstruct/tools/Rapier.java +++ b/tinker/tconstruct/tools/Rapier.java @@ -1,11 +1,13 @@ package tinker.tconstruct.tools; import tinker.tconstruct.AbilityHelper; +import tinker.tconstruct.TConstructContent; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; @@ -15,7 +17,7 @@ public class Rapier extends Weapon public Rapier(int itemID, String tex) { super(itemID, 2, tex); - this.setItemName("InfiTool.FencingSword"); + this.setItemName("InfiTool.Rapier"); } public EnumAction getItemUseAction(ItemStack par1ItemStack) @@ -43,4 +45,16 @@ public class Rapier extends Weapon { return 0.7f; } + + @Override + protected Item getHeadItem () + { + return TConstructContent.swordBlade; + } + + @Override + protected Item getAccessoryItem () + { + return TConstructContent.crossbar; + } } diff --git a/tinker/tconstruct/tools/Shovel.java b/tinker/tconstruct/tools/Shovel.java index 5121bd49..22775cdc 100644 --- a/tinker/tconstruct/tools/Shovel.java +++ b/tinker/tconstruct/tools/Shovel.java @@ -1,6 +1,8 @@ package tinker.tconstruct.tools; +import tinker.tconstruct.TConstructContent; import net.minecraft.block.material.Material; +import net.minecraft.item.Item; public class Shovel extends HarvestTool { @@ -29,4 +31,16 @@ public class Shovel extends HarvestTool } static Material[] materials = { Material.grass, Material.ground, Material.sand, Material.snow, Material.craftedSnow, Material.clay }; + + @Override + protected Item getHeadItem () + { + return TConstructContent.shovelHead; + } + + @Override + protected Item getAccessoryItem () + { + return null; + } } diff --git a/tinker/tconstruct/tools/ToolCore.java b/tinker/tconstruct/tools/ToolCore.java index 0ab6504a..c7510665 100644 --- a/tinker/tconstruct/tools/ToolCore.java +++ b/tinker/tconstruct/tools/ToolCore.java @@ -18,6 +18,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import tinker.tconstruct.AbilityHelper; import tinker.tconstruct.TConstruct; +import tinker.tconstruct.TConstructContent; +import tinker.tconstruct.crafting.ToolBuilder; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -307,31 +309,30 @@ public abstract class ToolCore extends Item return ""; } } + + static String[] toolMaterialNames = { + "Wooden ", "Stone ", "Iron ", "Flint ", "Cactus ", "Bone ", "Obsidian ", "Nethrrack ", "Slime ", "Paper ", "Cobalt ", "Ardite ", "Manyullyn " + }; /* Creative mode tools */ public void getSubItems (int id, CreativeTabs tab, List list) { - /*for (int i = 0; i < 13; i++) - list.add(getDefaultItem(id, i));*/ + for (int i = 0; i < 13; i++) + { + Item accessory = getAccessoryItem(); + ItemStack accessoryStack = accessory != null ? new ItemStack(getAccessoryItem(), 1, i) : null; + ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, i), new ItemStack(getHandleItem(), 1, i), accessoryStack, toolMaterialNames[i]+getToolName()); + tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true); + list.add( tool ); + } } - ItemStack getDefaultItem (int id, int type) + protected abstract Item getHeadItem(); + protected abstract Item getAccessoryItem(); + + protected Item getHandleItem() { - ItemStack tool = new ItemStack(id, 1, 0); - - NBTTagCompound compound = new NBTTagCompound(); - compound.setCompoundTag("InfiTool", new NBTTagCompound()); - compound.getCompoundTag("InfiTool").setInteger("Head", type); - compound.getCompoundTag("InfiTool").setInteger("Handle", 0); - compound.getCompoundTag("InfiTool").setInteger("Accessory", type); - - compound.getCompoundTag("InfiTool").setInteger("Damage", 0); - compound.getCompoundTag("InfiTool").setInteger("MaxDamage", 20); - compound.getCompoundTag("InfiTool").setBoolean("Broken", false); - - //compound.getCompoundTag("display").setString("Name", "Sword of Testing"); - tool.setTagCompound(compound); - return tool; + return TConstructContent.toolRod; } /* Tool uses */ diff --git a/tinker/tconstruct/tools/Weapon.java b/tinker/tconstruct/tools/Weapon.java index 407f27e0..d930f963 100644 --- a/tinker/tconstruct/tools/Weapon.java +++ b/tinker/tconstruct/tools/Weapon.java @@ -10,7 +10,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; -public class Weapon extends ToolCore +public abstract class Weapon extends ToolCore { public Weapon(int itemID, int baseDamage, String texture)