Some cleaning up, some making a mess

Changed the breakBlock method to something a bit more readable
Added some debug logging comments
This commit is contained in:
Mathijs Riezebos 2017-01-13 10:13:51 +01:00
parent 70535a50d5
commit 8eea287998
3 changed files with 14 additions and 11 deletions

View file

@ -126,6 +126,7 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
&& entity instanceof EntityPlayer && entity instanceof EntityPlayer
&& isEntityFacingDoor(state, (EntityLivingBase) entity)) { && isEntityFacingDoor(state, (EntityLivingBase) entity)) {
this.toggleDoor(world, pos, false); this.toggleDoor(world, pos, false);
//DimDoors.log("RiftID = " + getRiftTile(world, pos, world.getBlockState(pos)).riftID);
} }
} else { } else {
BlockPos up = pos.up(); BlockPos up = pos.up();
@ -133,7 +134,6 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
enterDimDoor(world, up, entity); enterDimDoor(world, up, entity);
} }
} }
DimDoors.log("RiftID = " + getRiftTile(world, pos, world.getBlockState(pos)).riftID);
} }
public boolean isUpperDoorBlock(IBlockState state) { public boolean isUpperDoorBlock(IBlockState state) {
@ -152,23 +152,23 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT
} }
@Override @Override
public void breakBlock(World world, BlockPos pos, IBlockState state) { //@todo troubleshoot this public void breakBlock(World world, BlockPos pos, IBlockState state) {
NBTTagCompound origRiftTag = new NBTTagCompound(); //might as well use NBTTags to transfer this information? DDTileEntityBase origRift;
BlockPos pos2 = pos; BlockPos pos2 = pos;
// This function runs on the server side after a block is replaced // This function runs on the server side after a block is replaced
// We MUST call super.breakBlock() since it involves removing tile entities // We MUST call super.breakBlock() since it involves removing tile entities
if (state.getValue(BlockDoor.HALF) == EnumDoorHalf.LOWER) { if (state.getValue(BlockDoor.HALF) == EnumDoorHalf.LOWER) {
pos2 = pos.up(); pos2 = pos.up();
((DDTileEntityBase) world.getTileEntity(pos2)).writeToNBT(origRiftTag); origRift = (DDTileEntityBase) world.getTileEntity(pos2);
world.setBlockToAir(pos2); world.setBlockToAir(pos2);
} else { } else {
((DDTileEntityBase) world.getTileEntity(pos)).writeToNBT(origRiftTag); origRift = (DDTileEntityBase) world.getTileEntity(pos);
} }
super.breakBlock(world, pos, state); super.breakBlock(world, pos, state);
world.setBlockState(pos2, ModBlocks.blockRift.getDefaultState()); world.setBlockState(pos2, ModBlocks.blockRift.getDefaultState());
DDTileEntityBase newRift = (DDTileEntityBase) world.getTileEntity(pos2); DDTileEntityBase newRift = (DDTileEntityBase) world.getTileEntity(pos2);
newRift.readFromNBT(origRiftTag); newRift.loadDataFrom(origRift);
//DimDoors.log("" +newRift.riftID);
} }
public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) { public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) {

View file

@ -165,6 +165,7 @@ public abstract class ItemDoorBase extends ItemDoor {
newRift.hasGennedPair = true; newRift.hasGennedPair = true;
} }
newRift.loadDataFrom(riftOrig); //take over the data from the original Rift newRift.loadDataFrom(riftOrig); //take over the data from the original Rift
//DimDoors.log("" +newRift.riftID);
if (!player.capabilities.isCreativeMode) { if (!player.capabilities.isCreativeMode) {
stack.stackSize--; stack.stackSize--;
} }

View file

@ -77,9 +77,11 @@ public abstract class DDTileEntityBase extends TileEntity {
} }
public void loadDataFrom(DDTileEntityBase rift2) { public void loadDataFrom(DDTileEntityBase rift2) {
isPaired = rift2.isPaired; if (rift2.riftID != -1) {
riftID = rift2.riftID; //should not start at 0 isPaired = rift2.isPaired;
pairedRiftID = rift2.pairedRiftID; riftID = rift2.riftID; //should not start at 0
this.markDirty(); pairedRiftID = rift2.pairedRiftID;
this.markDirty();
}
} }
} }