Expand FallingBlock API

- add auto expire setting
- add setter for block data
- add accessors for block state

== AT ==
public net.minecraft.world.entity.item.FallingBlockEntity blockState

Co-authored-by: Lukas Planz <lukas.planz@web.de>
This commit is contained in:
Owen1212055
2021-12-05 14:58:17 -05:00
parent 8c8e7968ab
commit dedddea65d
2 changed files with 77 additions and 7 deletions

View File

@@ -33,6 +33,31 @@ public class CraftFallingBlock extends CraftEntity implements FallingBlock {
public BlockData getBlockData() {
return CraftBlockData.fromData(this.getHandle().getBlockState());
}
// Paper start - Expand FallingBlock API
@Override
public void setBlockData(final BlockData blockData) {
Preconditions.checkArgument(blockData != null, "blockData");
final net.minecraft.world.level.block.state.BlockState oldState = this.getHandle().blockState, newState = ((CraftBlockData) blockData).getState();
this.getHandle().blockState = newState;
this.getHandle().blockData = null;
if (oldState != newState) this.update();
}
@Override
public org.bukkit.block.BlockState getBlockState() {
return org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(this.getHandle().blockState, this.getHandle().blockData);
}
@Override
public void setBlockState(final org.bukkit.block.BlockState blockState) {
Preconditions.checkArgument(blockState != null, "blockState");
// Calls #update if needed, the block data compound tag is not synced with the client and hence can be mutated after the sync with clients.
// The call also clears any potential old block data.
this.setBlockData(blockState.getBlockData());
if (blockState instanceof final org.bukkit.craftbukkit.block.CraftBlockEntityState<?> tileEntity) this.getHandle().blockData = tileEntity.getSnapshotNBT();
}
// Paper end - Expand FallingBlock API
@Override
public boolean getDropItem() {
@@ -101,4 +126,15 @@ public class CraftFallingBlock extends CraftEntity implements FallingBlock {
this.setHurtEntities(true);
}
}
// Paper start - Expand FallingBlock API
@Override
public boolean doesAutoExpire() {
return this.getHandle().autoExpire;
}
@Override
public void shouldAutoExpire(boolean autoExpires) {
this.getHandle().autoExpire = autoExpires;
}
// Paper end - Expand FallingBlock API
}