Fix crash with chunkloader placed by command. Closes #2349
This commit is contained in:
parent
6877f6e3f2
commit
9b47348fd3
2 changed files with 55 additions and 29 deletions
|
@ -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 CompoundTag toTag(CompoundTag tagCompound) {
|
||||
super.toTag(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.inventory).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.inventory).inventory().hotbar().addInventory()
|
||||
.blockEntity(this).sync(this::getRadius, this::setRadius).addInventory().create(this, syncID);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue