Fix crash with chunkloader placed by command. Closes #2349

This commit is contained in:
drcrazy 2021-02-24 09:29:15 +00:00 committed by modmuss50
parent 8398139271
commit 96383ebaaf
2 changed files with 55 additions and 29 deletions

View file

@ -77,11 +77,6 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
}
}
@Override
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
return TRContent.Machine.CHUNK_LOADER.getStack();
}
private void reload() {
unloadAll();
load();
@ -102,7 +97,16 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
}
}
private void unloadAll() {
ChunkLoaderManager manager = ChunkLoaderManager.get(world);
manager.unloadChunkLoader(world, getPos());
}
public ChunkPos getChunkPos() {
return new ChunkPos(getPos());
}
// MachineBaseBlockEntity
@Override
public void onBreak(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState) {
if (world.isClient) {
@ -119,20 +123,13 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
reload();
}
private void unloadAll() {
ChunkLoaderManager manager = ChunkLoaderManager.get(world);
manager.unloadChunkLoader(world, getPos());
}
public ChunkPos getChunkPos() {
return new ChunkPos(getPos());
}
@Override
public NbtCompound writeNbt(NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tagCompound.putInt("radius", radius);
tagCompound.putString("ownerUdid", ownerUdid);
if (ownerUdid != null && !ownerUdid.isEmpty()){
tagCompound.putString("ownerUdid", ownerUdid);
}
inventory.write(tagCompound);
return tagCompound;
}
@ -148,11 +145,25 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
inventory.read(nbttagcompound);
}
// IToolDrop
@Override
public ItemStack getToolDrop(final PlayerEntity entityPlayer) {
return TRContent.Machine.CHUNK_LOADER.getStack();
}
// InventoryProvider
@Override
public RebornInventory<ChunkLoaderBlockEntity> getInventory() {
return this.inventory;
}
// BuiltScreenHandlerProvider
@Override
public BuiltScreenHandler createScreenHandler(int syncID, PlayerEntity player) {
return new ScreenHandlerBuilder("chunkloader").player(player.getInventory()).inventory().hotbar().addInventory()
.blockEntity(this).sync(this::getRadius, this::setRadius).addInventory().create(this, syncID);
}
public int getRadius() {
return radius;
}
@ -161,10 +172,5 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
this.radius = radius;
}
@Override
public BuiltScreenHandler createScreenHandler(int syncID, PlayerEntity player) {
return new ScreenHandlerBuilder("chunkloader").player(player.getInventory()).inventory().hotbar().addInventory()
.blockEntity(this).sync(this::getRadius, this::setRadius).addInventory().create(this, syncID);
}
}