Clean up some debug prints and fix onReplaced() on InventoryTileEntity not dropping items.

This commit is contained in:
alexbegt committed 2020-04-02 21:09:07 -04:00
1 parent bbda40dea7
commit f35dbb4f99
3 files changed
+17 -17

No files matched your search

@@ -57,8 +57,7 @@ public abstract class InventoryBlock extends Block {
}
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer,
ItemStack stack) {
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
// set custom name from named stack
@@ -74,8 +73,6 @@ public abstract class InventoryBlock extends Block {
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
super.onReplaced(state, worldIn, pos, newState, isMoving);
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof InventoryTileEntity) {
@@ -83,6 +80,8 @@ public abstract class InventoryBlock extends Block {
worldIn.updateComparatorOutputLevel(pos, this);
}
}
super.onReplaced(state, worldIn, pos, newState, isMoving);
}
// BlockContainer sets this to invisible
@@ -104,6 +103,6 @@ public abstract class InventoryBlock extends Block {
@Nullable
public INamedContainerProvider getContainer(BlockState state, World worldIn, BlockPos pos) {
TileEntity tileentity = worldIn.getTileEntity(pos);
return tileentity instanceof INamedContainerProvider ? (INamedContainerProvider)tileentity : null;
return tileentity instanceof INamedContainerProvider ? (INamedContainerProvider) tileentity : null;
}
}
}
@@ -82,7 +82,9 @@ public abstract class InventoryTileEntity extends MantleTileEntity implements II
return !this.getStackInSlot(slot).isEmpty();
}
/** Same as resize, but does not call markDirty. Used on loading from NBT */
/**
* Same as resize, but does not call markDirty. Used on loading from NBT
*/
private void resizeInternal(int size) {
// save effort if the size did not change
if (size == this.inventory.size()) {
@@ -191,11 +193,10 @@ public abstract class InventoryTileEntity extends MantleTileEntity implements II
@Override
public boolean hasCustomName() {
return this.hasCustomName;
return this.getCustomName() != null;
}
public void setCustomName(ITextComponent customName) {
this.hasCustomName = true;
this.inventoryTitle = customName;
}
@@ -223,9 +224,7 @@ public abstract class InventoryTileEntity extends MantleTileEntity implements II
return false;
}
return
entityplayer.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D)
<= 64D;
return entityplayer.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64D;
}
@Override
@@ -266,7 +265,9 @@ public abstract class InventoryTileEntity extends MantleTileEntity implements II
return tags;
}
/** Writes the contents of the inventory to the tag */
/**
* Writes the contents of the inventory to the tag
*/
public void writeInventoryToNBT(CompoundNBT tag) {
IInventory inventory = this;
ListNBT nbttaglist = new ListNBT();
@@ -283,7 +284,9 @@ public abstract class InventoryTileEntity extends MantleTileEntity implements II
tag.put("Items", nbttaglist);
}
/** Reads a an inventory from the tag. Overwrites current content */
/**
* Reads a an inventory from the tag. Overwrites current content
*/
public void readInventoryFromNBT(CompoundNBT tag) {
ListNBT nbttaglist = tag.getList("Items", 10);
@@ -10,6 +10,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class TileEntityUtil {
@Nullable
public static <T extends TileEntity> T getTileEntity(@Nonnull Class<T> clazz, @Nullable IBlockReader world, @Nonnull BlockPos pos) {
return getTileEntity(clazz, world, pos, false);
@@ -17,7 +18,6 @@ public class TileEntityUtil {
@Nullable
public static <T extends TileEntity> T getTileEntity(@Nonnull Class<T> clazz, @Nullable IBlockReader world, @Nonnull BlockPos pos, boolean logWrongType) {
System.out.println("world: " + world + " pos: " + pos);
if (!isBlockLoaded(world, pos)) {
return null;
}
@@ -25,8 +25,6 @@ public class TileEntityUtil {
//TODO: This causes freezes if being called from onLoad
TileEntity tile = world.getTileEntity(pos);
System.out.println("world: " + world + " pos: " + pos + " tile: " + tile);
if (tile == null) {
return null;
}