From b0fd0590f9d3c2f6e8451f8634d67fb8a7120b11 Mon Sep 17 00:00:00 2001 From: Mohammad-Ali Minaie Date: Tue, 11 Apr 2017 08:10:08 -0400 Subject: [PATCH] working but not breaking --- .../nmd/primal/forgecraft/blocks/Breaker.java | 42 ++++++++++--------- .../renders/blocks/TileBreakerRender.java | 3 +- .../primal/forgecraft/tiles/TileBreaker.java | 30 +++++-------- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/1.11/src/main/java/nmd/primal/forgecraft/blocks/Breaker.java b/1.11/src/main/java/nmd/primal/forgecraft/blocks/Breaker.java index dad005c1..3ae6832c 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/blocks/Breaker.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/blocks/Breaker.java @@ -62,12 +62,12 @@ public class Breaker extends CustomContainerFacing { if(!world.isRemote){ TileBreaker tile = (TileBreaker) world.getTileEntity(pos); ItemStack pItem = player.inventory.getCurrentItem(); - System.out.println(tile.getSlotStack(0)); + if(state.getValue(ACTIVE) == true && player.isSneaking() && pItem.isEmpty()){ world.setBlockState(pos, state.withProperty(FACING, state.getValue(FACING)).withProperty(ACTIVE, false)); - tile.setCharge(0.0F); + tile.charge = 0.0f; if (state.getValue(FACING) == EnumFacing.EAST) { - if(tile.getCharge() > world.getBlockState(pos.east()).getBlockHardness(world, pos.east())) { + if(tile.charge > world.getBlockState(pos.east()).getBlockHardness(world, pos.east())) { if (world.getBlockState(pos.east()).getBlock() == Blocks.IRON_ORE) { world.setBlockToAir(pos.east()); CommonUtils.spawnItemEntityFromWorld(world, pos.east(), new ItemStack(PrimalItems.IRON_DUST, ThreadLocalRandom.current().nextInt(1, 2))); @@ -79,7 +79,7 @@ public class Breaker extends CustomContainerFacing { } } if (state.getValue(FACING) == EnumFacing.WEST) { - if(tile.getCharge() > world.getBlockState(pos.west()).getBlockHardness(world, pos.west())) { + if(tile.charge > world.getBlockState(pos.west()).getBlockHardness(world, pos.west())) { if (world.getBlockState(pos.west()).getBlock() == Blocks.IRON_ORE) { world.setBlockToAir(pos.west()); CommonUtils.spawnItemEntityFromWorld(world, pos.east(), new ItemStack(PrimalItems.IRON_DUST, ThreadLocalRandom.current().nextInt(1, 2))); @@ -91,7 +91,7 @@ public class Breaker extends CustomContainerFacing { } } if (state.getValue(FACING) == EnumFacing.SOUTH) { - if(tile.getCharge() > world.getBlockState(pos.south()).getBlockHardness(world, pos.south())) { + if(tile.charge > world.getBlockState(pos.south()).getBlockHardness(world, pos.south())) { if (world.getBlockState(pos.south()).getBlock() == Blocks.IRON_ORE) { world.setBlockToAir(pos.south()); CommonUtils.spawnItemEntityFromWorld(world, pos.east(), new ItemStack(PrimalItems.IRON_DUST, ThreadLocalRandom.current().nextInt(1, 2))); @@ -104,35 +104,39 @@ public class Breaker extends CustomContainerFacing { } if (state.getValue(FACING) == EnumFacing.NORTH) { - if(tile.getCharge() > world.getBlockState(pos.north()).getBlockHardness(world, pos.north())) { + System.out.println(tile.charge + ":" + world.getBlockState(pos.north()).getBlockHardness(world, pos.north())); + if(tile.charge > world.getBlockState(pos.north()).getBlockHardness(world, pos.north())) { if (world.getBlockState(pos.north()).getBlock() == Blocks.IRON_ORE) { world.setBlockToAir(pos.north()); CommonUtils.spawnItemEntityFromWorld(world, pos.east(), new ItemStack(PrimalItems.IRON_DUST, ThreadLocalRandom.current().nextInt(1, 2))); return true; } } else { - tile.getSlotStack(0).damageItem(10, null); + //tile.getSlotStack(0).damageItem(10, (EntityPlayer) null); + tile.getSlotStack(0).setItemDamage(tile.getSlotStack(0).getItemDamage()-10); return true; } } } - if(state.getValue(ACTIVE) == false && !player.isSneaking() && pItem.isEmpty()){ - world.setBlockState(pos, state.withProperty(FACING, state.getValue(FACING)).withProperty(ACTIVE, true), 2); - tile.setCharge(tile.getCharge() + 2.0f); + if(!player.isSneaking() && pItem.isEmpty()) { + if (!state.getValue(ACTIVE)) { + world.setBlockState(pos, state.withProperty(FACING, state.getValue(FACING)).withProperty(ACTIVE, true), 2); + } + tile.charge = tile.charge + 2.0f; + tile.updateBlock(); + System.out.println(tile.charge); return true; } + /*if(state.getValue(ACTIVE) == true && !player.isSneaking() && pItem.isEmpty()){ + //world.setBlockState(pos, state.withProperty(FACING, state.getValue(FACING)).withProperty(ACTIVE, true), 2); + tile.setCharge(tile.getCharge() + 2.0f); + return true; + }*/ if(pItem.getItem() instanceof WorkMallet){ - //System.out.println(pItem); - for(int i = 0; i < tile.getSlotListSize(); i++) { - tile.setSlotStack(i, pItem); - System.out.println(tile.getSlotStack(i)); - tile.update(); - tile.updateBlock(); - tile.updateContainingBlockInfo(); - } - pItem.shrink(1); + tile.setSlotStack(0, player.inventory.getCurrentItem()); + player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY); return true; } diff --git a/1.11/src/main/java/nmd/primal/forgecraft/renders/blocks/TileBreakerRender.java b/1.11/src/main/java/nmd/primal/forgecraft/renders/blocks/TileBreakerRender.java index c58541b8..2984cadb 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/renders/blocks/TileBreakerRender.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/renders/blocks/TileBreakerRender.java @@ -44,7 +44,8 @@ public class TileBreakerRender extends TileEntitySpecialRenderer if(state.getValue(Breaker.FACING) == EnumFacing.NORTH) { GL11.glPushMatrix(); - GL11.glRotatef(tile.getCharge(), 1.0f, 0.0f, 0.0f); + GL11.glRotated(90, 0.0f, 1.0f, 0.0f); + GL11.glRotatef(tile.charge, 0.0f, 0.0f, 1.0f); renderItem.renderItem(tile.getSlotStack(0), ItemCameraTransforms.TransformType.FIXED); GL11.glPopMatrix(); } diff --git a/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileBreaker.java b/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileBreaker.java index 224c8bf2..d6c5d80d 100644 --- a/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileBreaker.java +++ b/1.11/src/main/java/nmd/primal/forgecraft/tiles/TileBreaker.java @@ -13,30 +13,20 @@ import java.util.List; /** * Created by mminaie on 4/9/17. */ -public class TileBreaker extends TileBaseSlot implements ITickable { +public class TileBreaker extends TileBaseSlot { - private float charge; + public float charge = 0.0f; - public float getCharge() { + /*public float getCharge() { return charge; } - public void setCharge(float charge) { - this.charge = charge; - } + public void setCharge(float a) { + this.charge = a; + this.updateBlock(); + }*/ - public NonNullList slotList = NonNullList.withSize(10, ItemStack.EMPTY); - - @Override - public void update () { - World world = this.getWorld(); - if (!world.isRemote) { - IBlockState state = world.getBlockState(this.pos); - for(int i =0; i < this.getSlotListSize(); i++) { - //System.out.println(this.getSlotStack(i)); - } - } - } + public NonNullList slotList = NonNullList.withSize(1, ItemStack.EMPTY); @Override public int getSlotLimit() { @@ -46,7 +36,7 @@ public class TileBreaker extends TileBaseSlot implements ITickable { // ***************************************************************************** // // NBT // ***************************************************************************** // - /*@Override + @Override public NBTTagCompound readNBT(NBTTagCompound nbt) { super.readNBT(nbt); @@ -60,6 +50,6 @@ public class TileBreaker extends TileBaseSlot implements ITickable { nbt.setFloat("charge", this.charge); super.writeNBT(nbt); return nbt; - }*/ + } }