diff --git a/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockAutosmith.java b/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockAutosmith.java new file mode 100644 index 0000000..0f9da23 --- /dev/null +++ b/src/main/java/com/oitsjustjose/criss_cross/Blocks/BlockAutosmith.java @@ -0,0 +1,122 @@ +package com.oitsjustjose.criss_cross.Blocks; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import java.util.Random; + +import com.oitsjustjose.criss_cross.CrissCross; +import com.oitsjustjose.criss_cross.GUI.GUIHandler; +import com.oitsjustjose.criss_cross.TileEntity.TileEntityAutosmith; +import com.oitsjustjose.criss_cross.TileEntity.TileEntityAutosmith; +import com.oitsjustjose.criss_cross.Util.Reference; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.item.EntityItem; +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; + +public class BlockAutosmith extends BlockMachineBase +{ + private static String unlocName = "autosmith"; + public BlockAutosmith() + { + super(unlocName); + + GameRegistry.registerTileEntity(TileEntityAutosmith.class, unlocName); + GameRegistry.registerBlock(this, unlocName); + } + + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister register) + { + blockTextures[0] = register.registerIcon(Reference.modid + ":" + this.unlocName + "/" + unlocName + "_Bottom"); + blockTextures[1] = register.registerIcon(Reference.modid + ":" + this.unlocName + "/" + unlocName + "_Top"); + blockTextures[2] = register.registerIcon(Reference.modid + ":" + this.unlocName + "/" + unlocName + "_Front"); + blockTextures[3] = register.registerIcon(Reference.modid + ":" + this.unlocName + "/" + unlocName + "_Sides"); + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block block, int meta) + { + Random random = new Random(); + TileEntityAutosmith tile = (TileEntityAutosmith) world.getTileEntity(x, y, z); + + if(tile != null) + { + for(int i = 0; i < tile.getSizeInventory(); ++i) + { + ItemStack itemstack = tile.getStackInSlot(i); + + if(itemstack != null) + { + float f = random.nextFloat() * 0.8F + 0.1F; + float f1 = random.nextFloat() * 0.8F + 0.1F; + float f2 = random.nextFloat() * 0.8F + 0.1F; + + while(itemstack.stackSize > 0) + { + int j = random.nextInt(21) + 10; + + if(j > itemstack.stackSize) + { + j = itemstack.stackSize; + } + + itemstack.stackSize -= j; + EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), + (double) ((float) y + f1), (double) ((float) z + f2), + new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage())); + + if(itemstack.hasTagCompound()) + { + entityitem.getEntityItem() + .setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); + } + + float f3 = 0.05F; + entityitem.motionX = (double) ((float) random.nextGaussian() * f3); + entityitem.motionY = (double) ((float) random.nextGaussian() * f3 + 0.2F); + entityitem.motionZ = (double) ((float) random.nextGaussian() * f3); + world.spawnEntityInWorld(entityitem); + } + } + } + + world.func_147453_f(x, y, z, block); + + } + + super.breakBlock(world, x, y, z, block, meta); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) + { + return new TileEntityAutosmith(); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, + float hitY, float hitZ) + { + if(world.isRemote) + { + return true; + } + else + { + TileEntityAutosmith tileentityautosmith = (TileEntityAutosmith) world.getTileEntity(x, y, z); + if(tileentityautosmith != null) + player.openGui(CrissCross.instance, GUIHandler.Autosmith, world, x, y, z); + return true; + } + } +} diff --git a/src/main/java/com/oitsjustjose/criss_cross/Blocks/CCBlocks.java b/src/main/java/com/oitsjustjose/criss_cross/Blocks/CCBlocks.java index 0762bb4..5f17ae6 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Blocks/CCBlocks.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Blocks/CCBlocks.java @@ -22,12 +22,14 @@ public class CCBlocks public static Block cropomator; public static Block electroextractor; public static Block woodchipper; + public static Block autosmith; public static void init() { cropomator = new BlockCropomator(); electroextractor = new BlockElectroextractor(); woodchipper = new BlockWoodchipper(); + autosmith = new BlockAutosmith(); NetworkRegistry.INSTANCE.registerGuiHandler(CrissCross.instance, new GUIHandler()); } diff --git a/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerAutosmith.java b/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerAutosmith.java new file mode 100644 index 0000000..5e1a04c --- /dev/null +++ b/src/main/java/com/oitsjustjose/criss_cross/Container/ContainerAutosmith.java @@ -0,0 +1,155 @@ +package com.oitsjustjose.criss_cross.Container; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import com.oitsjustjose.criss_cross.TileEntity.TileEntityAutosmith; +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.item.ItemStack; + +public class ContainerAutosmith extends Container +{ + TileEntityAutosmith autosmith; + EntityPlayer player; + + private int lastUseTime; + private int lastChopTime; + private int lastFuelTime; + + public ContainerAutosmith(EntityPlayer player, TileEntityAutosmith autosmith) + { + this.player = player; + this.autosmith = autosmith; + + lastUseTime = 0; + lastChopTime = 0; + lastFuelTime = 0; + + this.addSlotToContainer(new Slot(autosmith, 0, 56, 17)); // tool + this.addSlotToContainer(new Slot(autosmith, 1, 56, 53)); // repairItem + this.addSlotToContainer(new MachineOutputSlot(player, autosmith, 2, 116, 35)); + this.addSlotToContainer(new Slot(autosmith, 3, 140, 35)); + this.addInventorySlots(); + } + + @SideOnly(Side.CLIENT) + public void updateProgressBar(int timeType1, int timeType2) + { + switch(timeType1) + { + case 0: + this.autosmith.processTime = timeType2; + break; + case 1: + this.autosmith.fuelTime = timeType2; + break; + case 2: + this.autosmith.fuelUsetime = timeType2; + break; + } + } + + @Override + public void addCraftingToCrafters(ICrafting crafting) + { + super.addCraftingToCrafters(crafting); + crafting.sendProgressBarUpdate(this, 0, this.autosmith.processTime); + crafting.sendProgressBarUpdate(this, 1, this.autosmith.fuelTime); + crafting.sendProgressBarUpdate(this, 2, this.autosmith.fuelUsetime); + } + + @Override + public void detectAndSendChanges() + { + super.detectAndSendChanges(); + for(int i = 0; i < this.crafters.size(); ++i) + { + ICrafting crafting = (ICrafting) this.crafters.get(i); + + if(this.lastUseTime != this.autosmith.processTime) + crafting.sendProgressBarUpdate(this, 0, this.autosmith.processTime); + if(this.lastChopTime != this.autosmith.fuelTime) + crafting.sendProgressBarUpdate(this, 1, this.autosmith.fuelTime); + if(this.lastFuelTime != this.autosmith.fuelUsetime) + crafting.sendProgressBarUpdate(this, 2, this.autosmith.fuelUsetime); + } + this.lastUseTime = this.autosmith.processTime; + this.lastChopTime = this.autosmith.fuelTime; + this.lastFuelTime = this.autosmith.fuelUsetime; + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotID) + { + ItemStack itemstack = null; + Slot slot = (Slot) this.inventorySlots.get(slotID); + + if (slot != null && slot.getHasStack()) + { + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + if (slotID < 4) + { + if (!this.mergeItemStack(itemstack1, 4, 40, true)) + return null; + } + else if (TileEntityAutosmith.isItemFuel(itemstack1)) + { + if (!this.mergeItemStack(itemstack1, 1, 2, false)) + return null; + } + else if (slotID >= 3 && slotID < 31) + { + if (!this.mergeItemStack(itemstack1, 31, 40, false)) + return null; + } + else if (slotID >= 30 && slotID < 40) + { + if (!this.mergeItemStack(itemstack1, 4, 31, false)) + return null; + } + + if (itemstack1.stackSize == 0) + { + slot.putStack(null); + } + else + { + slot.onSlotChanged(); + } + + if (itemstack1.stackSize == itemstack.stackSize) + return null; + + slot.onPickupFromSlot(player, itemstack); + } + + return itemstack; + } + + @Override + public boolean canInteractWith(EntityPlayer player) + { + return this.autosmith.isUseableByPlayer(this.player); + } + + public final void addInventorySlots() + { + this.addInventorySlots(8, 84, 142); + } + + public final void addInventorySlots(int xOffset, int yOffset, int yHotbar) + { + InventoryPlayer inventory = this.player.inventory; + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 9; ++j) + this.addSlotToContainer(new Slot(inventory, 9 + j + i * 9, xOffset + j * 18, yOffset + i * 18)); + + for(int i = 0; i < 9; ++i) + this.addSlotToContainer(new Slot(inventory, i, xOffset + i * 18, yHotbar)); + } +} diff --git a/src/main/java/com/oitsjustjose/criss_cross/CrissCross.java b/src/main/java/com/oitsjustjose/criss_cross/CrissCross.java index 85844ae..ec0e83e 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/CrissCross.java +++ b/src/main/java/com/oitsjustjose/criss_cross/CrissCross.java @@ -11,7 +11,6 @@ import com.oitsjustjose.criss_cross.Util.OreDictionaryAdder; import com.oitsjustjose.criss_cross.Util.Reference; import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; diff --git a/src/main/java/com/oitsjustjose/criss_cross/GUI/GUIAutosmith.java b/src/main/java/com/oitsjustjose/criss_cross/GUI/GUIAutosmith.java new file mode 100644 index 0000000..56b9139 --- /dev/null +++ b/src/main/java/com/oitsjustjose/criss_cross/GUI/GUIAutosmith.java @@ -0,0 +1,48 @@ +package com.oitsjustjose.criss_cross.GUI; + +import org.lwjgl.opengl.GL11; + +import com.oitsjustjose.criss_cross.TileEntity.TileEntityAutosmith; + +import com.oitsjustjose.criss_cross.Container.ContainerAutosmith; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +public class GUIAutosmith extends GuiContainer +{ + public static final ResourceLocation texture = new ResourceLocation("crisscross", "textures/gui/autosmith.png"); + + private TileEntityAutosmith autosmith; + + public GUIAutosmith(EntityPlayer player, TileEntityAutosmith autosmith) + { + super(new ContainerAutosmith(player, autosmith)); + this.autosmith = autosmith; + } + + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) + { + this.fontRendererObj.drawString(StatCollector.translateToLocal("container.autosmith"), 55, 7, 4210752); + this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, this.ySize - 92, + 4210752); + } + + protected void drawGuiContainerBackgroundLayer(float partialTickTime, int mouseX, int mouseY) + { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.renderEngine.bindTexture(texture); + int k = (this.width - this.xSize) / 2; + int l = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); + + if(this.autosmith.isUsingFuel()) + { + int i1 = this.autosmith.getBurnTimeRemainingScaled(13); + this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 1); + i1 = this.autosmith.getProgressScaled(24); + this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/GUI/GUIHandler.java b/src/main/java/com/oitsjustjose/criss_cross/GUI/GUIHandler.java index c34df9c..856add6 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/GUI/GUIHandler.java +++ b/src/main/java/com/oitsjustjose/criss_cross/GUI/GUIHandler.java @@ -1,8 +1,10 @@ package com.oitsjustjose.criss_cross.GUI; +import com.oitsjustjose.criss_cross.Container.ContainerAutosmith; import com.oitsjustjose.criss_cross.Container.ContainerCropomator; import com.oitsjustjose.criss_cross.Container.ContainerElectroextractor; import com.oitsjustjose.criss_cross.Container.ContainerWoodchipper; +import com.oitsjustjose.criss_cross.TileEntity.TileEntityAutosmith; import com.oitsjustjose.criss_cross.TileEntity.TileEntityCropomator; import com.oitsjustjose.criss_cross.TileEntity.TileEntityElectroextractor; import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper; @@ -17,6 +19,7 @@ public class GUIHandler implements IGuiHandler public static final int Cropomator = 1; public static final int Electroextractor = 2; public static final int Woodchipper = 3; + public static final int Autosmith = 4; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) @@ -41,6 +44,12 @@ public class GUIHandler implements IGuiHandler return new ContainerWoodchipper(player, TE); } + if(tile instanceof TileEntityAutosmith) + { + TileEntityAutosmith TE = (TileEntityAutosmith) tile; + + return new ContainerAutosmith(player, TE); + } return null; } @@ -68,6 +77,12 @@ public class GUIHandler implements IGuiHandler return new GUIWoodchipper(player, TE); } + if(tile instanceof TileEntityAutosmith) + { + TileEntityAutosmith TE = (TileEntityAutosmith) tile; + + return new GUIAutosmith(player, TE); + } return null; } } \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Items/CCItems.java b/src/main/java/com/oitsjustjose/criss_cross/Items/CCItems.java index 28c14e7..afc4263 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Items/CCItems.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Items/CCItems.java @@ -1,16 +1,21 @@ package com.oitsjustjose.criss_cross.Items; +import com.oitsjustjose.criss_cross.Recipes.ForgingHammerRecipes; + import net.minecraft.init.Blocks; import net.minecraft.item.Item; public class CCItems { public static Item dusts; - public static Item infiniBucket; + public static Item magicBucket; + public static Item forgingHammer; public static void init() { dusts = new ItemDust(); - infiniBucket = new ItemInfibucket(); + magicBucket = new ItemMagicBuckets(); + forgingHammer = new ItemForgingHammer(); + ForgingHammerRecipes.init(); } } \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Items/ItemForgingHammer.java b/src/main/java/com/oitsjustjose/criss_cross/Items/ItemForgingHammer.java new file mode 100644 index 0000000..c75b431 --- /dev/null +++ b/src/main/java/com/oitsjustjose/criss_cross/Items/ItemForgingHammer.java @@ -0,0 +1,52 @@ +package com.oitsjustjose.criss_cross.Items; + +import java.util.List; + +import com.oitsjustjose.criss_cross.CrissCross; +import com.oitsjustjose.criss_cross.Util.Reference; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; + +public class ItemForgingHammer extends Item +{ + @SideOnly(Side.CLIENT) + IIcon icon; + + private String unlocName; + + public ItemForgingHammer() + { + unlocName = "forgingHammer"; + this.setContainerItem(this); + this.maxStackSize = 1; + this.setMaxDamage(3); + this.setCreativeTab(CrissCross.CCTab); + GameRegistry.registerItem(this, unlocName); + } + + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamage(int meta) + { + return this.icon; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister register) + { + icon = register.registerIcon(Reference.modid + ":" + this.unlocName); + } +} \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Items/ItemInfibucket.java b/src/main/java/com/oitsjustjose/criss_cross/Items/ItemMagicBuckets.java similarity index 98% rename from src/main/java/com/oitsjustjose/criss_cross/Items/ItemInfibucket.java rename to src/main/java/com/oitsjustjose/criss_cross/Items/ItemMagicBuckets.java index 65f0888..ca204b9 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Items/ItemInfibucket.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Items/ItemMagicBuckets.java @@ -20,7 +20,7 @@ import net.minecraft.util.IIcon; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; -public class ItemInfibucket extends Item +public class ItemMagicBuckets extends Item { String[] types = new String[] { @@ -29,7 +29,7 @@ public class ItemInfibucket extends Item @SideOnly(Side.CLIENT) IIcon[] icons = new IIcon[types.length]; - public ItemInfibucket() + public ItemMagicBuckets() { this.setHasSubtypes(true); this.maxStackSize = 1; diff --git a/src/main/java/com/oitsjustjose/criss_cross/Recipes/AutosmithRecipes.java b/src/main/java/com/oitsjustjose/criss_cross/Recipes/AutosmithRecipes.java new file mode 100644 index 0000000..30bbd91 --- /dev/null +++ b/src/main/java/com/oitsjustjose/criss_cross/Recipes/AutosmithRecipes.java @@ -0,0 +1,169 @@ +package com.oitsjustjose.criss_cross.Recipes; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import com.google.common.collect.Maps; + +import net.minecraft.item.ItemStack; + +public class AutosmithRecipes +{ + private Map stack1Size = Maps.newHashMap(); + private Map stack2Size = Maps.newHashMap(); + + public class RepairRecipe + { + private final ItemStack toolItem; + private final ItemStack repairItem; + private final ItemStack repairedTool; + + public RepairRecipe(final ItemStack repairItem, final ItemStack toolItem) + { + this.repairItem = repairItem; + this.toolItem = toolItem; + this.repairedTool = toolItem.copy(); + this.repairedTool.setItemDamage(0); + } + + public ItemStack getCraftingResult() + { + return this.repairedTool.copy(); + } + + public ItemStack[] getIngredients() + { + return new ItemStack[] + { + this.repairItem, this.toolItem + }; + } + + public boolean uses(final ItemStack ingredient) + { + if(ingredient == null) + { + return false; + } + + if((this.repairItem != null) && this.repairItem.isItemEqual(ingredient)) + { + return true; + } + else if((this.toolItem != null) && this.toolItem.isItemEqual(ingredient)) + { + return true; + } + + return false; + } + + @SuppressWarnings("unused") + public boolean matches(ItemStack toolItem, ItemStack repairItem) + { + if(toolItem.isItemEqual(repairItem)) + { + return false; + } + + if(this.uses(toolItem) && this.uses(repairItem)) + { + return true; + } + + if(this.uses(toolItem) && (repairItem == null)) + { + return true; + } + + if(this.uses(repairItem) && (toolItem == null)) + { + return true; + } + return false; + } + } + + private static AutosmithRecipes instance = new AutosmithRecipes(); + private final ArrayList recipes = new ArrayList(); + + public static AutosmithRecipes getInstance() + { + return AutosmithRecipes.instance; + } + + public void addRecipe(ItemStack itemStack, ItemStack otherItemStack) + { + this.recipes.add(new RepairRecipe(itemStack, otherItemStack)); + + this.stack1Size.put(itemStack, itemStack.stackSize); + this.stack2Size.put(otherItemStack, otherItemStack.stackSize); + + this.stack1Size.put(otherItemStack, otherItemStack.stackSize); + this.stack2Size.put(itemStack, itemStack.stackSize); + } + + public ItemStack getResult(ItemStack toolItem, ItemStack repairItem) + { + for(int j = 0; j < this.recipes.size(); ++j) + { + RepairRecipe irecipe = this.recipes.get(j); + + if(irecipe.matches(toolItem, repairItem)) + { + if((ItemStack.areItemStacksEqual(toolItem, irecipe.toolItem) && ItemStack.areItemStacksEqual(repairItem, irecipe.repairItem))) + { + return irecipe.getCraftingResult(); + } + } + } + + return null; + } + + public boolean hasUsage(ItemStack itemStack) + { + for(int j = 0; j < this.recipes.size(); ++j) + { + RepairRecipe irecipe = this.recipes.get(j); + + if(irecipe.uses(itemStack)) + { + return true; + } + } + return false; + } + + public ArrayList getRecipesFor(ItemStack output) + { + ArrayList list = new ArrayList(); + + for(RepairRecipe recipe : this.recipes) + { + if(recipe.repairedTool.isItemEqual(output) + && recipe.repairedTool.getTagCompound() == output.getTagCompound()) + { + list.add(recipe); + } + } + return list; + } + + public ArrayList getRecipesUsing(ItemStack ingredient) + { + ArrayList list = new ArrayList(); + + for(RepairRecipe recipe : this.recipes) + { + if(recipe.uses(ingredient)) + { + list.add(recipe); + continue; + } + } + return list; + } +} \ No newline at end of file diff --git a/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCCraftingRecipes.java b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCCraftingRecipes.java index 934df37..a48ba4f 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCCraftingRecipes.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCCraftingRecipes.java @@ -23,11 +23,11 @@ public class CCCraftingRecipes static void initBucketRecipes() { - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(CCItems.infiniBucket, 1, 0), + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(CCItems.magicBucket, 1, 0), "DFD", "WBW", "DFD", 'W', Items.water_bucket, 'B', Items.bucket, 'D', "gemDiamond", 'F', "blockDiamond" )); - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(CCItems.infiniBucket, 1, 1), + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(CCItems.magicBucket, 1, 1), "OGO", "GBG", "OGO", diff --git a/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCMachineRecipes.java b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCMachineRecipes.java index 0a30a60..84e03cb 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCMachineRecipes.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Recipes/CCMachineRecipes.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import com.oitsjustjose.criss_cross.Items.CCItems; import com.oitsjustjose.criss_cross.Items.ItemDust; +import com.oitsjustjose.criss_cross.TileEntity.TileEntityAutosmith; import com.oitsjustjose.criss_cross.TileEntity.TileEntityCropomator; import com.oitsjustjose.criss_cross.TileEntity.TileEntityElectroextractor; import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper; @@ -17,6 +18,8 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.Item.ToolMaterial; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; @@ -35,6 +38,9 @@ public class CCMachineRecipes initWoodchipperFuels(); initWoodchipperOreDictionary(); + AutosmithRecipes.getInstance().addRecipe(new ItemStack(Items.iron_pickaxe, 1, Short.MAX_VALUE), new ItemStack(Items.iron_ingot)); + TileEntityAutosmith.addFuel(new ItemStack(Items.redstone)); + ElectroextractorRecipes.getInstance().addRecipe(new ItemStack(Blocks.diamond_ore), new ItemStack(Items.diamond, electroQTY)); ElectroextractorRecipes.getInstance().addRecipe(new ItemStack(Blocks.emerald_ore), @@ -43,6 +49,24 @@ public class CCMachineRecipes new ItemStack(Items.coal, electroQTY)); } + //TODO: Finish this, it's pretty important + + public static void initAutosmithRecipes() + { + for(int i = 0; i < Item.itemRegistry.getKeys().size(); i++) + { + Item item = Item.getItemById(i); + if(item != null && item.isItemTool(new ItemStack(item, 1, Short.MAX_VALUE)) && item.isRepairable()) + { + for(int j = 0; j < Item.ToolMaterial.values().length; j++) + { + ItemStack repairItem = Item.ToolMaterial.values()[j].getRepairItemStack(); + if(repairItem.getDisplayName().contains("")); + } + } + } + } + public static void initCropomatorRecipes() { for(int i = 0; i < ConfigHandler.cropomatorInputs.length; i++) diff --git a/src/main/java/com/oitsjustjose/criss_cross/Recipes/ForgingHammerRecipes.java b/src/main/java/com/oitsjustjose/criss_cross/Recipes/ForgingHammerRecipes.java new file mode 100644 index 0000000..a7165be --- /dev/null +++ b/src/main/java/com/oitsjustjose/criss_cross/Recipes/ForgingHammerRecipes.java @@ -0,0 +1,41 @@ +package com.oitsjustjose.criss_cross.Recipes; + +import com.oitsjustjose.criss_cross.Items.CCItems; + +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.item.Item; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemTool; + +public class ForgingHammerRecipes +{ + public static void init() + { + for(int i = 0; i < Item.itemRegistry.getKeys().size(); i++) + { + ItemStack toolStack = new ItemStack(Item.getItemById(i)); + if(toolStack != null && (toolStack.getItem() instanceof ItemTool || toolStack.getItem() instanceof ItemArmor)) + { + for(int toolMat = 0; toolMat < Item.ToolMaterial.values().length; toolMat++) + { + ItemStack repairItem = Item.ToolMaterial.values()[toolMat].getRepairItemStack(); + String[] toolName = toolStack.getDisplayName().split(" "); + if(repairItem == null) + return; + for(int name = 0; name < toolName.length; name++) + { + if(repairItem.getDisplayName().contains(toolName[name])) + { + ItemStack repairedTool = toolStack.copy(); + toolStack.setItemDamage(0); + GameRegistry.addShapelessRecipe(repairedTool, new Object[] { + toolStack, repairItem, CCItems.forgingHammer + }); + } + } + } + } + } + } +} diff --git a/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityAutosmith.java b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityAutosmith.java new file mode 100644 index 0000000..a96ed5e --- /dev/null +++ b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityAutosmith.java @@ -0,0 +1,400 @@ +package com.oitsjustjose.criss_cross.TileEntity; + +import java.util.ArrayList; + +import com.oitsjustjose.criss_cross.Util.ConfigHandler; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import com.oitsjustjose.criss_cross.Blocks.BlockAutosmith; +import com.oitsjustjose.criss_cross.Recipes.AutosmithRecipes; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; + +public class TileEntityAutosmith extends TileEntity implements ISidedInventory +{ + private static int proTicks = ConfigHandler.autosmithProcessTime; + private static final int[] slotsTop = new int[] + { + 0 + }; + private static final int[] slotsBottom = new int[] + { + 3 + }; + private static final int[] slotsSides = new int[] + { + 2, 1 + }; + private static ArrayList fuelItems = new ArrayList(); + + private ItemStack[] ItemStacks = new ItemStack[4]; + //Slot [0] is the tool Item + //Slot [1] is the tool repair Item + //Slot [2] is the output + //Slot [3] is the fuel + + public int fuelTime; + public int processTime; + public int fuelUsetime; + + public static ArrayList getFuels() + { + return fuelItems; + } + + @Override + public int getSizeInventory() + { + return this.ItemStacks.length; + } + + @Override + public ItemStack getStackInSlot(int slot) + { + return this.ItemStacks[slot]; + } + + @Override + public ItemStack decrStackSize(int slot, int qtyToDecr) + { + if(this.ItemStacks[slot] != null) + { + ItemStack itemstack; + + if(this.ItemStacks[slot].stackSize <= qtyToDecr) + { + itemstack = this.ItemStacks[slot]; + this.ItemStacks[slot] = null; + return itemstack; + } + else + { + itemstack = this.ItemStacks[slot].splitStack(qtyToDecr); + + if(this.ItemStacks[slot].stackSize == 0) + { + this.ItemStacks[slot] = null; + } + + return itemstack; + } + } + else + { + return null; + } + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) + { + if(this.ItemStacks[slot] != null) + { + ItemStack itemstack = this.ItemStacks[slot]; + this.ItemStacks[slot] = null; + return itemstack; + } + else + { + return null; + } + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemstack) + { + this.ItemStacks[slot] = itemstack; + + if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) + { + itemstack.stackSize = this.getInventoryStackLimit(); + } + } + + @Override + public String getInventoryName() + { + return "container.autosmith"; + } + + @Override + public boolean hasCustomInventoryName() + { + return true; + } + + @Override + public void readFromNBT(NBTTagCompound tag) + { + super.readFromNBT(tag); + NBTTagList nbttaglist = tag.getTagList("Items", 10); + this.ItemStacks = new ItemStack[this.getSizeInventory()]; + + for(int i = 0; i < nbttaglist.tagCount(); ++i) + { + NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); + byte b0 = nbttagcompound1.getByte("Slot"); + + if(b0 >= 0 && b0 < this.ItemStacks.length) + { + this.ItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); + } + } + + this.fuelTime = tag.getShort("FuelTime"); + this.processTime = tag.getShort("WorkTime"); + this.fuelUsetime = getItemBurnTime(this.ItemStacks[3]); + } + + @Override + public void writeToNBT(NBTTagCompound tag) + { + super.writeToNBT(tag); + tag.setShort("FuelTime", (short) this.fuelTime); + tag.setShort("WorkTime", (short) this.processTime); + NBTTagList nbttaglist = new NBTTagList(); + + for(int i = 0; i < this.ItemStacks.length; ++i) + { + if(this.ItemStacks[i] != null) + { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("Slot", (byte) i); + this.ItemStacks[i].writeToNBT(nbttagcompound1); + nbttaglist.appendTag(nbttagcompound1); + } + } + + tag.setTag("Items", nbttaglist); + } + + @Override + public int getInventoryStackLimit() + { + return 64; + } + + @SideOnly(Side.CLIENT) + public int getProgressScaled(int par1) + { + return this.processTime * par1 / proTicks; + } + + @SideOnly(Side.CLIENT) + public int getBurnTimeRemainingScaled(int par1) + { + if(this.fuelUsetime == 0) + { + this.fuelUsetime = proTicks; + } + + return this.fuelTime * par1 / this.fuelUsetime; + } + + public boolean isUsingFuel() + { + return this.fuelTime > 0; + } + + public void updateEntity() + { + boolean flag = this.fuelTime > 0; + boolean flag1 = false; + + if(this.fuelTime > 0) + { + --this.fuelTime; + } + + if(!this.worldObj.isRemote) + { + if(this.fuelTime != 0 || this.ItemStacks[3] != null && this.ItemStacks[0] != null) + { + if(this.fuelTime == 0 && this.canProcess()) + { + this.fuelUsetime = this.fuelTime = getItemBurnTime(this.ItemStacks[3]); + + if(this.fuelTime > 0) + { + flag1 = true; + + if(this.ItemStacks[3] != null) + { + --this.ItemStacks[3].stackSize; + + if(this.ItemStacks[3].stackSize == 0) + { + this.ItemStacks[3] = ItemStacks[3].getItem().getContainerItem(ItemStacks[3]); + } + } + } + } + + if(this.isUsingFuel() && this.canProcess()) + { + ++this.processTime; + + if(this.processTime == proTicks) + { + this.processTime = 0; + this.processItem(); + flag1 = true; + } + } + else + { + this.processTime = 0; + } + } + + if(flag != this.fuelTime > 0) + { + flag1 = true; + BlockAutosmith.updateBlockState(this.fuelTime > 0, this.worldObj, this.xCoord, this.yCoord, + this.zCoord); + } + } + + if(flag1) + { + this.markDirty(); + } + } + + private boolean canProcess() + { + ItemStack tool = this.ItemStacks[0]; + ItemStack repair = this.ItemStacks[1]; + if(tool != null && repair != null) + { + ItemStack output = AutosmithRecipes.getInstance().getResult(tool, repair); + if(output == null) + return false; + ItemStack outputSlot = this.ItemStacks[2]; + if(outputSlot == null) + return true; + if(!outputSlot.isItemEqual(output)) + return false; + int result = outputSlot.stackSize + output.stackSize; + return result <= output.getMaxStackSize(); + } + return false; + } + + public static void addFuel(ItemStack itemstack) + { + fuelItems.add(itemstack); + } + + public static boolean removeFuel(ItemStack itemstack) + { + for(int i = 0; i < fuelItems.size(); i++) + { + if(fuelItems.get(i) == itemstack) + { + fuelItems.remove(i); + return true; + } + } + return false; + } + + public static boolean isValidForRepair(ItemStack tool, ItemStack item) + { + if(AutosmithRecipes.getInstance().getResult(tool, item) != null) + return true; + return false; + } + + public void processItem() + { + if(this.canProcess()) + { + + ItemStack tool = ItemStacks[0]; + ItemStack item = ItemStacks[1]; + ItemStack output = AutosmithRecipes.getInstance().getResult(tool, item); + ItemStack outputSlot = ItemStacks[2]; + if(outputSlot == null) + { + ItemStacks[2] = output.copy(); + } + else if(outputSlot.isItemEqual(output)) + { + outputSlot.stackSize += output.stackSize; + } + + --tool.stackSize; + if(tool.stackSize <= 0) + { + ItemStacks[0] = null; + } + } + } + + public static int getItemBurnTime(ItemStack itemstack) + { + return isItemFuel(itemstack) ? proTicks : 0; + } + + public static boolean isItemFuel(ItemStack itemstack) + { + for(int i = 0; i < fuelItems.size(); i++) + { + ItemStack temp = fuelItems.get(i); + if(temp.getItem() == itemstack.getItem() && temp.getItemDamage() == itemstack.getItemDamage()) + return true; + } + return false; + } + + public boolean isUseableByPlayer(EntityPlayer player) + { + + return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false + : player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, + (double) this.zCoord + 0.5D) <= 64.0D; + } + + public void openInventory() + { + } + + public void closeInventory() + { + } + + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemstack) + { + return slot == 2 ? false : (slot == 1 ? isItemFuel(itemstack) : true); + } + + @Override + public int[] getAccessibleSlotsFromSide(int slot) + { + return slot == 0 ? slotsBottom : (slot == 1 ? slotsTop : slotsSides); + } + + @Override + public boolean canInsertItem(int slot, ItemStack itemstack, int side) + { + return this.isItemValidForSlot(slot, itemstack); + } + + @Override + public boolean canExtractItem(int slot, ItemStack itemstack, int side) + { + return side != 0 || slot != 1; + } + + @Override + public void markDirty() + { + } +} diff --git a/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityWoodchipper.java b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityWoodchipper.java index 12d5091..7c7e72e 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityWoodchipper.java +++ b/src/main/java/com/oitsjustjose/criss_cross/TileEntity/TileEntityWoodchipper.java @@ -392,28 +392,4 @@ public class TileEntityWoodchipper extends TileEntity implements ISidedInventory public void markDirty() { } - - public static class WoodchipperRecipe - { - public final int time; - public final ItemStack input; - public final ItemStack result; - - public WoodchipperRecipe(ItemStack input, ItemStack result) - { - this.time = ConfigHandler.woodchipperProcessTime; - this.input = input; - this.result = result; - } - - public boolean matches(ItemStack input) - { - return ItemStack.areItemStacksEqual(this.input, input); - } - - public ItemStack getResult() - { - return result.copy(); - } - } } diff --git a/src/main/java/com/oitsjustjose/criss_cross/Util/ConfigHandler.java b/src/main/java/com/oitsjustjose/criss_cross/Util/ConfigHandler.java index d9221c5..02cd153 100644 --- a/src/main/java/com/oitsjustjose/criss_cross/Util/ConfigHandler.java +++ b/src/main/java/com/oitsjustjose/criss_cross/Util/ConfigHandler.java @@ -52,6 +52,9 @@ public class ConfigHandler "minecraft:water_bucket", "minecraft:potion:0", "CrissCross:magicBucket:0" }; + public static int autosmithProcessTime; + public static String autosmithRecipeItem; + public static void init(File configFile) { // Create the configuration object from the given configuration file @@ -129,6 +132,15 @@ public class ConfigHandler "minecraft:diamond_block", "This is the item located in the center of the crafting recipe for the Woodchipper. Formatted as: :: or :."); + + //Autosmith's Configs + autosmithProcessTime = config.getInt("Autosmith Process Time", config.CATEGORY_GENERAL, 200, 0, Short.MAX_VALUE, + "Control how many ticks it takes the Autosmith to process an item. Default is 200; furnaces are also 200."); + + autosmithRecipeItem = config.getString("Autosmith Crafting Item", config.CATEGORY_GENERAL, + "minecraft:diamond_block", + "This is the item located in the center of the crafting recipe for the Autosmith. Formatted as: :: or :."); + if(config.hasChanged()) config.save(); } diff --git a/src/main/resources/assets/crisscross/lang/en_US.lang b/src/main/resources/assets/crisscross/lang/en_US.lang index 76abf62..3e85894 100644 --- a/src/main/resources/assets/crisscross/lang/en_US.lang +++ b/src/main/resources/assets/crisscross/lang/en_US.lang @@ -1,15 +1,14 @@ -#Tiles +#Blocks tile.CrissCross.Cropomator.name=Cropomator tile.CrissCross.ElectroExtractor.name=ElectroExtractor tile.CrissCross.WoodChipper.name=Wood Chipper #Items -item.CrissCross.Iron.name=Electrolytic Iron Dust - +#Dust Name Components item.CrissCross.trash.name=This is a bad item, please trash it. item.CrissCross.dustPrefix=Electrolytic item.CrissCross.dustPostfix=Dust - +#Buckets item.CrissCross.everfulBucket.name=Everful Bucket item.CrissCross.voidBucket.name=Insatiable Bucket