mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 15:00:13 +01:00
net.minecraft.world.level.block.state
This commit is contained in:
parent
f252b67a97
commit
f0e7d7e5f7
2 changed files with 63 additions and 73 deletions
|
@ -1,6 +1,6 @@
|
|||
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java
|
||||
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
|
||||
@@ -46,6 +46,7 @@
|
||||
@@ -46,6 +_,7 @@
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
|
@ -8,111 +8,100 @@
|
|||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.EmptyBlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
@@ -83,6 +84,8 @@
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
+import net.minecraft.world.level.ServerExplosion;
|
||||
+// CraftBukkit end
|
||||
@@ -167,16 +_,24 @@
|
||||
}
|
||||
|
||||
public abstract class BlockBehaviour implements FeatureElement {
|
||||
|
||||
@@ -156,9 +159,18 @@
|
||||
|
||||
protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, @Nullable Orientation wireOrientation, boolean notify) {}
|
||||
|
||||
- protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {}
|
||||
+ protected void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
|
||||
protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
|
||||
- }
|
||||
+ org.spigotmc.AsyncCatcher.catchOp("block onPlace"); // Spigot
|
||||
+ }
|
||||
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ protected void onPlace(BlockState iblockdata, Level world, BlockPos blockposition, BlockState iblockdata1, boolean flag, @Nullable UseOnContext context) {
|
||||
+ this.onPlace(iblockdata, world, blockposition, iblockdata1, flag);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
protected void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean moved) {
|
||||
|
||||
protected void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
|
||||
+ org.spigotmc.AsyncCatcher.catchOp("block remove"); // Spigot
|
||||
if (state.hasBlockEntity() && !state.is(newState.getBlock())) {
|
||||
world.removeBlockEntity(pos);
|
||||
level.removeBlockEntity(pos);
|
||||
}
|
||||
@@ -166,7 +178,7 @@
|
||||
}
|
||||
|
||||
protected void onExplosionHit(BlockState state, ServerLevel world, BlockPos pos, Explosion explosion, BiConsumer<ItemStack, BlockPos> stackMerger) {
|
||||
protected void onExplosionHit(BlockState state, ServerLevel level, BlockPos pos, Explosion explosion, BiConsumer<ItemStack, BlockPos> dropConsumer) {
|
||||
- if (!state.isAir() && explosion.getBlockInteraction() != Explosion.BlockInteraction.TRIGGER_BLOCK) {
|
||||
+ if (!state.isAir() && explosion.getBlockInteraction() != Explosion.BlockInteraction.TRIGGER_BLOCK && state.isDestroyable()) { // Paper - Protect Bedrock and End Portal/Frames from being destroyed
|
||||
Block block = state.getBlock();
|
||||
boolean flag = explosion.getIndirectSourceEntity() instanceof Player;
|
||||
|
||||
@@ -174,8 +186,10 @@
|
||||
BlockEntity tileentity = state.hasBlockEntity() ? world.getBlockEntity(pos) : null;
|
||||
LootParams.Builder lootparams_a = (new LootParams.Builder(world)).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParams.THIS_ENTITY, explosion.getDirectSourceEntity());
|
||||
|
||||
if (block.dropFromExplosion(explosion)) {
|
||||
@@ -186,8 +_,10 @@
|
||||
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY)
|
||||
.withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockEntity)
|
||||
.withOptionalParameter(LootContextParams.THIS_ENTITY, explosion.getDirectSourceEntity());
|
||||
- if (explosion.getBlockInteraction() == Explosion.BlockInteraction.DESTROY_WITH_DECAY) {
|
||||
- lootparams_a.withParameter(LootContextParams.EXPLOSION_RADIUS, explosion.radius());
|
||||
- builder.withParameter(LootContextParams.EXPLOSION_RADIUS, explosion.radius());
|
||||
+ // CraftBukkit start - add yield
|
||||
+ if (explosion instanceof ServerExplosion serverExplosion && serverExplosion.yield < 1.0F) {
|
||||
+ lootparams_a.withParameter(LootContextParams.EXPLOSION_RADIUS, 1.0F / serverExplosion.yield);
|
||||
+ if (explosion instanceof net.minecraft.world.level.ServerExplosion serverExplosion && serverExplosion.yield < 1.0F) {
|
||||
+ builder.withParameter(LootContextParams.EXPLOSION_RADIUS, 1.0F / serverExplosion.yield);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
state.spawnAfterBreak(world, pos, ItemStack.EMPTY, flag);
|
||||
@@ -243,7 +257,7 @@
|
||||
state.spawnAfterBreak(level, pos, ItemStack.EMPTY, flag);
|
||||
@@ -255,7 +_,7 @@
|
||||
}
|
||||
|
||||
protected boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
|
||||
- return state.canBeReplaced() && (context.getItemInHand().isEmpty() || !context.getItemInHand().is(this.asItem()));
|
||||
+ return state.canBeReplaced() && (context.getItemInHand().isEmpty() || !context.getItemInHand().is(this.asItem())) && (state.isDestroyable() || (context.getPlayer() != null && context.getPlayer().getAbilities().instabuild)); // Paper - Protect Bedrock and End Portal/Frames from being destroyed
|
||||
protected boolean canBeReplaced(BlockState state, BlockPlaceContext useContext) {
|
||||
- return state.canBeReplaced() && (useContext.getItemInHand().isEmpty() || !useContext.getItemInHand().is(this.asItem()));
|
||||
+ return state.canBeReplaced() && (useContext.getItemInHand().isEmpty() || !useContext.getItemInHand().is(this.asItem()))&& (state.isDestroyable() || (useContext.getPlayer() != null && useContext.getPlayer().getAbilities().instabuild)); // Paper - Protect Bedrock and End Portal/Frames from being destroyed
|
||||
}
|
||||
|
||||
protected boolean canBeReplaced(BlockState state, Fluid fluid) {
|
||||
@@ -851,7 +865,15 @@
|
||||
this.spawnTerrainParticles = blockbase_info.spawnTerrainParticles;
|
||||
this.instrument = blockbase_info.instrument;
|
||||
this.replaceable = blockbase_info.replaceable;
|
||||
+ }
|
||||
@@ -468,6 +_,16 @@
|
||||
this.instrument = properties.instrument;
|
||||
this.replaceable = properties.replaceable;
|
||||
}
|
||||
+ // Paper start - Perf: impl cached craft block data, lazy load to fix issue with loading at the wrong time
|
||||
+ @Nullable
|
||||
+ private org.bukkit.craftbukkit.block.data.CraftBlockData cachedCraftBlockData;
|
||||
+
|
||||
+ public org.bukkit.craftbukkit.block.data.CraftBlockData createCraftBlockData() {
|
||||
+ if (cachedCraftBlockData == null) cachedCraftBlockData = org.bukkit.craftbukkit.block.data.CraftBlockData.createData(asState());
|
||||
+ return (org.bukkit.craftbukkit.block.data.CraftBlockData) cachedCraftBlockData.clone();
|
||||
}
|
||||
+ if (this.cachedCraftBlockData == null) this.cachedCraftBlockData = org.bukkit.craftbukkit.block.data.CraftBlockData.createData(this.asState());
|
||||
+ return (org.bukkit.craftbukkit.block.data.CraftBlockData) this.cachedCraftBlockData.clone();
|
||||
+ }
|
||||
+ // Paper end - Perf: impl cached craft block data, lazy load to fix issue with loading at the wrong time
|
||||
+
|
||||
|
||||
private boolean calculateSolid() {
|
||||
if (((Block) this.owner).properties.forceSolidOn) {
|
||||
@@ -873,12 +895,14 @@
|
||||
if (this.owner.properties.forceSolidOn) {
|
||||
@@ -487,12 +_,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ protected boolean shapeExceedsCube = true; // Paper - moved from actual method to here
|
||||
public void initCache() {
|
||||
this.fluidState = ((Block) this.owner).getFluidState(this.asState());
|
||||
this.isRandomlyTicking = ((Block) this.owner).isRandomlyTicking(this.asState());
|
||||
this.fluidState = this.owner.getFluidState(this.asState());
|
||||
this.isRandomlyTicking = this.owner.isRandomlyTicking(this.asState());
|
||||
if (!this.getBlock().hasDynamicShape()) {
|
||||
this.cache = new BlockBehaviour.BlockStateBase.Cache(this.asState());
|
||||
}
|
||||
+ this.shapeExceedsCube = this.cache == null || this.cache.largeCollisionShape; // Paper - moved from actual method to here
|
||||
|
||||
this.legacySolid = this.calculateSolid();
|
||||
this.occlusionShape = this.canOcclude ? ((Block) this.owner).getOcclusionShape(this.asState()) : Shapes.empty();
|
||||
@@ -925,6 +949,12 @@
|
||||
this.occlusionShape = this.canOcclude ? this.owner.getOcclusionShape(this.asState()) : Shapes.empty();
|
||||
@@ -531,6 +_,11 @@
|
||||
public boolean isSolid() {
|
||||
return this.legacySolid;
|
||||
}
|
||||
|
||||
+ // Paper start - Protect Bedrock and End Portal/Frames from being destroyed
|
||||
+ public final boolean isDestroyable() {
|
||||
+ return getBlock().isDestroyable();
|
||||
+ }
|
||||
+ // Paper end - Protect Bedrock and End Portal/Frames from being destroyed
|
||||
+
|
||||
public boolean isValidSpawn(BlockGetter world, BlockPos pos, EntityType<?> type) {
|
||||
return this.getBlock().properties.isValidSpawn.test(this.asState(), world, pos, type);
|
||||
}
|
||||
@@ -945,19 +975,19 @@
|
||||
|
||||
public boolean isValidSpawn(BlockGetter level, BlockPos pos, EntityType<?> entityType) {
|
||||
return this.getBlock().properties.isValidSpawn.test(this.asState(), level, pos, entityType);
|
||||
@@ -552,19 +_,19 @@
|
||||
return this.occlusionShape;
|
||||
}
|
||||
|
||||
|
@ -137,7 +126,7 @@
|
|||
return this.isAir;
|
||||
}
|
||||
|
||||
@@ -1028,14 +1058,14 @@
|
||||
@@ -634,14 +_,14 @@
|
||||
}
|
||||
|
||||
public PushReaction getPistonPushReaction() {
|
||||
|
@ -154,31 +143,31 @@
|
|||
return this.canOcclude;
|
||||
}
|
||||
|
||||
@@ -1125,7 +1155,13 @@
|
||||
@@ -725,7 +_,13 @@
|
||||
}
|
||||
|
||||
public void onPlace(Level world, BlockPos pos, BlockState state, boolean notify) {
|
||||
- this.getBlock().onPlace(this.asState(), world, pos, state, notify);
|
||||
public void onPlace(Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
|
||||
- this.getBlock().onPlace(this.asState(), level, pos, oldState, movedByPiston);
|
||||
+ // CraftBukkit start
|
||||
+ this.onPlace(world, pos, state, notify, null);
|
||||
+ this.onPlace(level, pos, oldState, movedByPiston, null);
|
||||
+ }
|
||||
+
|
||||
+ public void onPlace(Level world, BlockPos blockposition, BlockState iblockdata, boolean flag, @Nullable UseOnContext context) {
|
||||
+ this.getBlock().onPlace(this.asState(), world, blockposition, iblockdata, flag, context);
|
||||
+ public void onPlace(Level level, BlockPos pos, BlockState oldState, boolean movedByPiston, @Nullable UseOnContext context) {
|
||||
+ this.getBlock().onPlace(this.asState(), level, pos, oldState, movedByPiston, context);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
public void onRemove(Level world, BlockPos pos, BlockState state, boolean moved) {
|
||||
@@ -1154,6 +1190,7 @@
|
||||
public void onRemove(Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
|
||||
@@ -754,6 +_,7 @@
|
||||
|
||||
public void spawnAfterBreak(ServerLevel world, BlockPos pos, ItemStack tool, boolean dropExperience) {
|
||||
this.getBlock().spawnAfterBreak(this.asState(), world, pos, tool, dropExperience);
|
||||
+ if (dropExperience) {getBlock().popExperience(world, pos, this.getBlock().getExpDrop(asState(), world, pos, tool, true));} // Paper - Properly handle xp dropping
|
||||
public void spawnAfterBreak(ServerLevel level, BlockPos pos, ItemStack stack, boolean dropExperience) {
|
||||
this.getBlock().spawnAfterBreak(this.asState(), level, pos, stack, dropExperience);
|
||||
+ if (dropExperience) {this.getBlock().popExperience(level, pos, this.getBlock().getExpDrop(this.asState(), level, pos, stack, true));} // Paper - Properly handle xp dropping
|
||||
}
|
||||
|
||||
public List<ItemStack> getDrops(LootParams.Builder builder) {
|
||||
@@ -1250,11 +1287,11 @@
|
||||
return this.getBlock().builtInRegistryHolder().is(key);
|
||||
public List<ItemStack> getDrops(LootParams.Builder lootParams) {
|
||||
@@ -858,11 +_,11 @@
|
||||
return this.getBlock().builtInRegistryHolder().is(block);
|
||||
}
|
||||
|
||||
- public FluidState getFluidState() {
|
|
@ -1,11 +1,11 @@
|
|||
--- a/net/minecraft/world/level/block/state/BlockState.java
|
||||
+++ b/net/minecraft/world/level/block/state/BlockState.java
|
||||
@@ -10,6 +10,16 @@
|
||||
@@ -10,6 +_,17 @@
|
||||
public class BlockState extends BlockBehaviour.BlockStateBase {
|
||||
public static final Codec<BlockState> CODEC = codec(BuiltInRegistries.BLOCK.byNameCodec(), Block::defaultBlockState).stable();
|
||||
|
||||
+ // Paper start - optimise getType calls
|
||||
+ org.bukkit.Material cachedMaterial;
|
||||
+ org.bukkit.@org.jspecify.annotations.Nullable Material cachedMaterial;
|
||||
+
|
||||
+ public final org.bukkit.Material getBukkitMaterial() {
|
||||
+ if (this.cachedMaterial == null) {
|
||||
|
@ -14,6 +14,7 @@
|
|||
+ return this.cachedMaterial;
|
||||
+ }
|
||||
+ // Paper end - optimise getType calls
|
||||
public BlockState(Block block, Reference2ObjectArrayMap<Property<?>, Comparable<?>> propertyMap, MapCodec<BlockState> codec) {
|
||||
super(block, propertyMap, codec);
|
||||
+
|
||||
public BlockState(Block owner, Reference2ObjectArrayMap<Property<?>, Comparable<?>> values, MapCodec<BlockState> propertiesCodec) {
|
||||
super(owner, values, propertiesCodec);
|
||||
}
|
Loading…
Reference in a new issue