diff --git a/kfc/src/main/java/nmd/primal/forgecraft/blocks/machine/Forge.java b/kfc/src/main/java/nmd/primal/forgecraft/blocks/machine/Forge.java index 9c2444f4..9a75a622 100644 --- a/kfc/src/main/java/nmd/primal/forgecraft/blocks/machine/Forge.java +++ b/kfc/src/main/java/nmd/primal/forgecraft/blocks/machine/Forge.java @@ -102,71 +102,68 @@ public class Forge extends CustomContainerFacing implements ITileEntityProvider, ItemStack pItem = player.inventory.getCurrentItem().copy(); ItemStack fuelItem = tile.getSlotStack(0); - if (!world.isRemote) { - /*********************** - FUEL SLOT CODE - ***********************/ - if (!tile.getSlotStack(0).isEmpty()) { - if (player.inventory.getCurrentItem().getItem() instanceof ItemSpade) { - ItemStack returnStack = tile.getSlotStack(0).copy(); - PlayerHelper.spawnItemOnPlayer(world, player, returnStack); - tile.clearSlot(0); + /*********************** + FUEL SLOT CODE + ***********************/ + if (!tile.getSlotStack(0).isEmpty()) { + if (player.inventory.getCurrentItem().getItem() instanceof ItemSpade) { + ItemStack returnStack = tile.getSlotStack(0).copy(); + PlayerHelper.spawnItemOnPlayer(world, player, returnStack); + tile.clearSlot(0); + return true; + } + } + if (pItem.isEmpty()) { + if (!player.isSneaking()) { + if (world.getBlockState(pos).getValue(PrimalAPI.States.ACTIVE) == true) { + Integer tempInt = tile.getHeat(); + String tempString = tempInt.toString(); + ITextComponent itextcomponent = new TextComponentString(tempString); + player.sendStatusMessage(itextcomponent, true); + //System.out.println(pos); return true; } } - if (pItem.isEmpty()) { - if (!player.isSneaking()) { - if (world.getBlockState(pos).getValue(PrimalAPI.States.ACTIVE) == true) { - Integer tempInt = tile.getHeat(); - String tempString = tempInt.toString(); - ITextComponent itextcomponent = new TextComponentString(tempString); - player.sendStatusMessage(itextcomponent, true); - //System.out.println(pos); - return true; - } - } - } - if ((FireSource.useSource(world, pos, facing, player, hand, pItem, hitX, hitY, hitZ))) { - world.setBlockState(pos, state.withProperty(PrimalAPI.States.ACTIVE, true), 2); - tile.setHeat(100); - tile.markDirty(); - tile.updateBlock(); - return true; - } - if ((!pItem.isEmpty()) && tile.isItemValidForSlot(0, pItem)) { - if (!fuelItem.isEmpty()) { - if (pItem.getItem() == fuelItem.getItem()) { - if (fuelItem.getCount() < 64) { - if (fuelItem.getCount() + pItem.getCount() <= 64) { - fuelItem.grow(pItem.getCount()); - player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY); - tile.markDirty(); - tile.updateBlock(); - return true; - } - if (fuelItem.getCount() + pItem.getCount() > 64) { - pItem.setCount(64 - pItem.getCount()); - fuelItem.setCount(64); - tile.markDirty(); - tile.updateBlock(); - return true; - } + } + if ((FireSource.useSource(world, pos, facing, player, hand, pItem, hitX, hitY, hitZ))) { + world.setBlockState(pos, state.withProperty(PrimalAPI.States.ACTIVE, true), 2); + tile.setHeat(100); + tile.markDirty(); + tile.updateBlock(); + return true; + } + if ((!pItem.isEmpty()) && tile.isItemValidForSlot(0, pItem)) { + if (!fuelItem.isEmpty()) { + if (pItem.getItem() == fuelItem.getItem()) { + if (fuelItem.getCount() < 64) { + if (fuelItem.getCount() + pItem.getCount() <= 64) { + fuelItem.grow(pItem.getCount()); + player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY); + tile.markDirty(); + tile.updateBlock(); + return true; + } + if (fuelItem.getCount() + pItem.getCount() > 64) { + pItem.setCount(64 - pItem.getCount()); + fuelItem.setCount(64); + tile.markDirty(); + tile.updateBlock(); + return true; } } } - if (fuelItem.isEmpty()) { - tile.setSlotStack(0, pItem); - player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY); - return true; - } } - - - if (facing == EnumFacing.UP) { - doForgeInventoryManager(pItem, world, tile, pos, hitX, hitY, hitZ, state, player); + if (fuelItem.isEmpty()) { + tile.setSlotStack(0, pItem); + player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY); + return true; } } + + if (facing == EnumFacing.UP) { + doForgeInventoryManager(pItem, world, tile, pos, hitX, hitY, hitZ, state, player); + } } } } diff --git a/kfc/src/main/java/nmd/primal/forgecraft/items/SlottedTongs.java b/kfc/src/main/java/nmd/primal/forgecraft/items/SlottedTongs.java index c40e7c7e..05cbfcd2 100644 --- a/kfc/src/main/java/nmd/primal/forgecraft/items/SlottedTongs.java +++ b/kfc/src/main/java/nmd/primal/forgecraft/items/SlottedTongs.java @@ -325,83 +325,82 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{ IBlockState state = world.getBlockState(pos); Block block = world.getBlockState(pos).getBlock(); ItemStack itemstack = player.getHeldItem(hand); + IItemHandler inventory = itemstack.getCapability(ITEM_HANDLER, null); ItemStack slotStack = inventory.getStackInSlot(0).copy(); -/* - if (block instanceof AnvilStone) { - TileAnvil tile = (TileAnvil) world.getTileEntity(pos); - doAnvilInventoryManager(itemstack, world, tile, pos, hitx, hity, hitz, state, player); - return EnumActionResult.SUCCESS; - } -*/ - if (slotStack.isEmpty()) { - if (block instanceof NBTCrucible) { - ItemStack tempStack = takeBlock(world, pos, state, face, player, block).copy(); - inventory.insertItem(0, tempStack, false); - world.setBlockState(pos, this.getReplacementBlock(world, pos, state)); - return EnumActionResult.SUCCESS; - } - } - if (!slotStack.isEmpty()) { - if (slotStack.getItem() instanceof ItemNBTCrucible) { - NBTTagCompound tag = slotStack.getSubCompound("BlockEntityTag").copy(); - if (tag != null) { - ItemBlock temp = (ItemBlock) slotStack.getItem(); - int i = this.getMetadata(slotStack.getMetadata()); - IBlockState iblockstate1 = temp.getBlock().getStateForPlacement(world, pos, face, hitx, hity, hitz, i, player, hand); - temp.placeBlockAt(slotStack, player, world, pos.up(1), face, hitx, hity, hitz, iblockstate1); - inventory.extractItem(0, 1, false); - return EnumActionResult.SUCCESS; - } - } - } - /***** - DROPS the ToolParts into the World - *****/ - if (!slotStack.isEmpty()) { - if (!(block instanceof AnvilBase)) { - if (slotStack.getItem() instanceof ToolPart) { - ItemStack tempStack = slotStack; - PlayerHelper.spawnItemOnGround(world, pos, tempStack); - inventory.extractItem(0, 1, false); - return EnumActionResult.SUCCESS; - } - } - } - - /***** - Cools the Ingots on the Tongs - *****/ - if (!slotStack.isEmpty()) { - if (world.getBlockState(pos).getBlock() == PrimalAPI.Blocks.BARREL) { - AbstractTileTank tileTank = (AbstractTileTank) world.getTileEntity(pos); - if (slotStack.getTagCompound().getBoolean("hot")) { - if (tileTank.getContainedFluid().getFluid().equals(FluidRegistry.WATER) || - tileTank.getContainedFluid().getFluid().equals(PrimalAPI.Fluids.RAIN_WATER) - ) { - ItemStack tempStack = slotStack.copy(); - tempStack.getTagCompound().setBoolean("hot", false); - inventory.extractItem(0, 1, false); - PlayerHelper.spawnItemOnGround(world, pos, tempStack); - world.playSound(null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.AMBIENT, 1.0F, PrimalAPI.getRandom().nextFloat() * 0.4F + 0.8F); + if (!(block instanceof AnvilBase)) { + if (!(block instanceof Forge)) { + System.out.println(inventory.getStackInSlot(0)); + if (slotStack.isEmpty()) { + if (block instanceof NBTCrucible) { + ItemStack tempStack = takeBlock(world, pos, state, face, player, block).copy(); + inventory.insertItem(0, tempStack, false); + world.setBlockState(pos, this.getReplacementBlock(world, pos, state)); return EnumActionResult.SUCCESS; } } - } - } + if (!slotStack.isEmpty()) { + if (slotStack.getItem() instanceof ItemNBTCrucible) { + NBTTagCompound tag = slotStack.getSubCompound("BlockEntityTag").copy(); - /***** - DROPS the Ingots into the World - *****/ - if (!slotStack.isEmpty()) { - if (!(block instanceof AnvilBase)) { - if (!(block instanceof Forge)) { + if (tag != null) { + ItemBlock temp = (ItemBlock) slotStack.getItem(); + int i = this.getMetadata(slotStack.getMetadata()); + IBlockState iblockstate1 = temp.getBlock().getStateForPlacement(world, pos, face, hitx, hity, hitz, i, player, hand); + temp.placeBlockAt(slotStack, player, world, pos.up(1), face, hitx, hity, hitz, iblockstate1); + inventory.extractItem(0, 1, false); + return EnumActionResult.SUCCESS; + } + } + } + + /***** + DROPS the ToolParts into the World + *****/ + if (!slotStack.isEmpty()) { + + if (slotStack.getItem() instanceof ToolPart) { + ItemStack tempStack = slotStack; + PlayerHelper.spawnItemOnGround(world, pos, tempStack); + inventory.extractItem(0, 1, false); + return EnumActionResult.SUCCESS; + } + + } + + /***** + Cools the Ingots on the Tongs + *****/ + if (!slotStack.isEmpty()) { + if (world.getBlockState(pos).getBlock() == PrimalAPI.Blocks.BARREL) { + AbstractTileTank tileTank = (AbstractTileTank) world.getTileEntity(pos); + if (slotStack.getTagCompound().getBoolean("hot")) { + if (tileTank.getContainedFluid().getFluid().equals(FluidRegistry.WATER) || + tileTank.getContainedFluid().getFluid().equals(PrimalAPI.Fluids.RAIN_WATER) + ) { + ItemStack tempStack = slotStack.copy(); + tempStack.getTagCompound().setBoolean("hot", false); + inventory.extractItem(0, 1, false); + PlayerHelper.spawnItemOnGround(world, pos, tempStack); + world.playSound(null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.AMBIENT, 1.0F, PrimalAPI.getRandom().nextFloat() * 0.4F + 0.8F); + return EnumActionResult.SUCCESS; + } + } + } + } + + /***** + DROPS the Ingots into the World + *****/ + if (!slotStack.isEmpty()) { + System.out.println("Tongs isn't empty"); if (slotStack.getItem() instanceof BaseMultiItem) { ItemStack tempStack = slotStack.copy(); PlayerHelper.spawnItemOnGround(world, pos, tempStack); inventory.extractItem(0, 1, false); + System.out.println(inventory.getStackInSlot(0)); return EnumActionResult.SUCCESS; } if (!(slotStack.getItem() instanceof BaseMultiItem)) { @@ -434,9 +433,7 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{ } } } - return EnumActionResult.FAIL; } - return EnumActionResult.FAIL; } return EnumActionResult.FAIL; } @@ -500,11 +497,11 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{ @Override public NBTTagCompound getNBTShareTag(ItemStack stack) { - super.getNBTShareTag(stack); - IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null); - NonNullList setList = NonNullList.withSize(1, ItemStack.EMPTY); - ItemStackHelper.saveAllItems(stack.getTagCompound(), setList); - return stack.getTagCompound(); + return super.getNBTShareTag(stack); + //IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null); + //NonNullList setList = NonNullList.withSize(1, ItemStack.EMPTY); + //ItemStackHelper.saveAllItems(stack.getTagCompound(), setList); + //return stack.getTagCompound(); } @Override @@ -512,11 +509,11 @@ public class SlottedTongs extends Item implements IPickup, AnvilHandler{ { super.readNBTShareTag(stack, nbt); - stack.deserializeNBT(nbt); - IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null); - NonNullList setList = NonNullList.withSize(1, ItemStack.EMPTY); - ItemStackHelper.loadAllItems(nbt, setList); - inventory.insertItem(0, setList.get(0), false); + //stack.deserializeNBT(nbt); + //IItemHandler inventory = stack.getCapability(ITEM_HANDLER, null); + //NonNullList setList = NonNullList.withSize(1, ItemStack.EMPTY); + //ItemStackHelper.loadAllItems(nbt, setList); + //inventory.insertItem(0, setList.get(0), false); } diff --git a/kfc/src/main/java/nmd/primal/forgecraft/util/AnvilHandler.java b/kfc/src/main/java/nmd/primal/forgecraft/util/AnvilHandler.java index f8c2270f..4d1d54e3 100644 --- a/kfc/src/main/java/nmd/primal/forgecraft/util/AnvilHandler.java +++ b/kfc/src/main/java/nmd/primal/forgecraft/util/AnvilHandler.java @@ -236,30 +236,31 @@ public interface AnvilHandler { static boolean doWork(ItemStack pItem, Integer counter, TileAnvil tile, World world, BlockPos pos, EntityPlayer player) { - if (pItem.getItem().equals(ModItems.slottedtongs)) { - - IItemHandler inventory = pItem.getCapability(ITEM_HANDLER, null); - ItemStack tongStack = inventory.getStackInSlot(0).copy(); - - if (tongStack.isEmpty()) { - if (!tile.getSlotStack(counter).isEmpty()) { - ItemStack tempStack = tile.getSlotStack(counter).copy(); - inventory.insertItem(0,tempStack, false); - tile.setSlotStack(counter, ItemStack.EMPTY); - return true; - } - } - - if (!tongStack.isEmpty()) { - if (tile.getSlotStack(counter).isEmpty()) { - ItemStack tempStack = tongStack.copy(); - tile.setSlotStack(counter, tempStack); - inventory.extractItem(0, 1, false); - return true; - } - } - } if (!world.isRemote) { + if (pItem.getItem().equals(ModItems.slottedtongs)) { + + IItemHandler inventory = pItem.getCapability(ITEM_HANDLER, null); + ItemStack tongStack = inventory.getStackInSlot(0).copy(); + + if (tongStack.isEmpty()) { + if (!tile.getSlotStack(counter).isEmpty()) { + ItemStack tempStack = tile.getSlotStack(counter).copy(); + inventory.insertItem(0,tempStack, false); + tile.setSlotStack(counter, ItemStack.EMPTY); + return true; + } + } + + if (!tongStack.isEmpty()) { + if (tile.getSlotStack(counter).isEmpty()) { + ItemStack tempStack = tongStack.copy(); + tile.setSlotStack(counter, tempStack); + inventory.extractItem(0, 1, false); + return true; + } + } + } + if (pItem.getItem().equals(Items.AIR) && player.isSneaking()) { diff --git a/kfc/src/main/java/nmd/primal/forgecraft/util/ForgeHandler.java b/kfc/src/main/java/nmd/primal/forgecraft/util/ForgeHandler.java index f0a959c1..e0853048 100644 --- a/kfc/src/main/java/nmd/primal/forgecraft/util/ForgeHandler.java +++ b/kfc/src/main/java/nmd/primal/forgecraft/util/ForgeHandler.java @@ -8,6 +8,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.IItemHandlerModifiable; import nmd.primal.core.common.helper.RecipeHelper; import nmd.primal.core.common.items.tools.Gallagher; import nmd.primal.forgecraft.init.ModItems; @@ -53,6 +54,7 @@ public interface ForgeHandler { default boolean doForgeInventoryManager(ItemStack pItem, World world, TileForge tile, BlockPos pos, float hitx, float hity, float hitz, IBlockState state, EntityPlayer player) { if (state.getValue(FACING) == EnumFacing.NORTH) { + int counter = 0; for (int z = 0; z < arraySize; z++) { for (int x = 0; x < arraySize; x++) { @@ -109,16 +111,15 @@ public interface ForgeHandler { } static boolean doWork(ItemStack pItem, Integer counter, TileForge tile, World world, BlockPos pos, EntityPlayer player) { - if (pItem.getItem().equals(ModItems.slottedtongs)) { - IItemHandler inventory = pItem.getCapability(ITEM_HANDLER, null); + IItemHandler inventory = (IItemHandlerModifiable) pItem.getCapability(ITEM_HANDLER, null); ItemStack tongsStack = inventory.getStackInSlot(0).copy(); if (tongsStack.isEmpty()) { if (!tile.getSlotStack(counter).isEmpty()) { ItemStack tempStack = tile.getSlotStack(counter).copy(); - inventory.insertItem(0, tempStack, false); tile.setSlotStack(counter, ItemStack.EMPTY); + inventory.insertItem(0, tempStack, false); return true; } }