working but not breaking

This commit is contained in:
Mohammad-Ali Minaie
2017-04-11 08:10:08 -04:00
parent e34f1fdc11
commit b0fd0590f9
3 changed files with 35 additions and 40 deletions

View File

@@ -62,12 +62,12 @@ public class Breaker extends CustomContainerFacing {
if(!world.isRemote){ if(!world.isRemote){
TileBreaker tile = (TileBreaker) world.getTileEntity(pos); TileBreaker tile = (TileBreaker) world.getTileEntity(pos);
ItemStack pItem = player.inventory.getCurrentItem(); ItemStack pItem = player.inventory.getCurrentItem();
System.out.println(tile.getSlotStack(0));
if(state.getValue(ACTIVE) == true && player.isSneaking() && pItem.isEmpty()){ if(state.getValue(ACTIVE) == true && player.isSneaking() && pItem.isEmpty()){
world.setBlockState(pos, state.withProperty(FACING, state.getValue(FACING)).withProperty(ACTIVE, false)); 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 (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) { if (world.getBlockState(pos.east()).getBlock() == Blocks.IRON_ORE) {
world.setBlockToAir(pos.east()); world.setBlockToAir(pos.east());
CommonUtils.spawnItemEntityFromWorld(world, pos.east(), new ItemStack(PrimalItems.IRON_DUST, ThreadLocalRandom.current().nextInt(1, 2))); 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 (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) { if (world.getBlockState(pos.west()).getBlock() == Blocks.IRON_ORE) {
world.setBlockToAir(pos.west()); world.setBlockToAir(pos.west());
CommonUtils.spawnItemEntityFromWorld(world, pos.east(), new ItemStack(PrimalItems.IRON_DUST, ThreadLocalRandom.current().nextInt(1, 2))); 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 (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) { if (world.getBlockState(pos.south()).getBlock() == Blocks.IRON_ORE) {
world.setBlockToAir(pos.south()); world.setBlockToAir(pos.south());
CommonUtils.spawnItemEntityFromWorld(world, pos.east(), new ItemStack(PrimalItems.IRON_DUST, ThreadLocalRandom.current().nextInt(1, 2))); 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 (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) { if (world.getBlockState(pos.north()).getBlock() == Blocks.IRON_ORE) {
world.setBlockToAir(pos.north()); world.setBlockToAir(pos.north());
CommonUtils.spawnItemEntityFromWorld(world, pos.east(), new ItemStack(PrimalItems.IRON_DUST, ThreadLocalRandom.current().nextInt(1, 2))); CommonUtils.spawnItemEntityFromWorld(world, pos.east(), new ItemStack(PrimalItems.IRON_DUST, ThreadLocalRandom.current().nextInt(1, 2)));
return true; return true;
} }
} else { } 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; return true;
} }
} }
} }
if(state.getValue(ACTIVE) == false && !player.isSneaking() && pItem.isEmpty()){ if(!player.isSneaking() && pItem.isEmpty()) {
world.setBlockState(pos, state.withProperty(FACING, state.getValue(FACING)).withProperty(ACTIVE, true), 2); if (!state.getValue(ACTIVE)) {
tile.setCharge(tile.getCharge() + 2.0f); 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; 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){ 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; return true;
} }

View File

@@ -44,7 +44,8 @@ public class TileBreakerRender extends TileEntitySpecialRenderer<TileBreaker>
if(state.getValue(Breaker.FACING) == EnumFacing.NORTH) { if(state.getValue(Breaker.FACING) == EnumFacing.NORTH) {
GL11.glPushMatrix(); 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); renderItem.renderItem(tile.getSlotStack(0), ItemCameraTransforms.TransformType.FIXED);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }

View File

@@ -13,30 +13,20 @@ import java.util.List;
/** /**
* Created by mminaie on 4/9/17. * 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; return charge;
} }
public void setCharge(float charge) { public void setCharge(float a) {
this.charge = charge; this.charge = a;
} this.updateBlock();
}*/
public NonNullList<ItemStack> slotList = NonNullList.<ItemStack>withSize(10, ItemStack.EMPTY); public NonNullList<ItemStack> slotList = NonNullList.<ItemStack>withSize(1, 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));
}
}
}
@Override @Override
public int getSlotLimit() { public int getSlotLimit() {
@@ -46,7 +36,7 @@ public class TileBreaker extends TileBaseSlot implements ITickable {
// ***************************************************************************** // // ***************************************************************************** //
// NBT // NBT
// ***************************************************************************** // // ***************************************************************************** //
/*@Override @Override
public NBTTagCompound readNBT(NBTTagCompound nbt) public NBTTagCompound readNBT(NBTTagCompound nbt)
{ {
super.readNBT(nbt); super.readNBT(nbt);
@@ -60,6 +50,6 @@ public class TileBreaker extends TileBaseSlot implements ITickable {
nbt.setFloat("charge", this.charge); nbt.setFloat("charge", this.charge);
super.writeNBT(nbt); super.writeNBT(nbt);
return nbt; return nbt;
}*/ }
} }