aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower-stripped/net/minecraft/world/item/BlockItem.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower-stripped/net/minecraft/world/item/BlockItem.java.patch')
-rw-r--r--patch-remap/mache-vineflower-stripped/net/minecraft/world/item/BlockItem.java.patch159
1 files changed, 159 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower-stripped/net/minecraft/world/item/BlockItem.java.patch b/patch-remap/mache-vineflower-stripped/net/minecraft/world/item/BlockItem.java.patch
new file mode 100644
index 0000000000..d8963fdd26
--- /dev/null
+++ b/patch-remap/mache-vineflower-stripped/net/minecraft/world/item/BlockItem.java.patch
@@ -0,0 +1,159 @@
+--- a/net/minecraft/world/item/BlockItem.java
++++ b/net/minecraft/world/item/BlockItem.java
+@@ -29,6 +32,10 @@
+ import net.minecraft.world.level.block.state.properties.Property;
+ import net.minecraft.world.level.gameevent.GameEvent;
+ import net.minecraft.world.phys.shapes.CollisionContext;
++import org.bukkit.craftbukkit.block.CraftBlock;
++import org.bukkit.craftbukkit.block.data.CraftBlockData;
++import org.bukkit.event.block.BlockCanBuildEvent;
++// CraftBukkit end
+
+ public class BlockItem extends Item {
+ public static final String BLOCK_ENTITY_TAG = "BlockEntityTag";
+@@ -62,38 +74,53 @@
+ if (blockPlaceContext == null) {
+ return InteractionResult.FAIL;
+ } else {
+- BlockState placementState = this.getPlacementState(blockPlaceContext);
+- if (placementState == null) {
++ IBlockData iblockdata = this.getPlacementState(blockactioncontext1);
++ // CraftBukkit start - special case for handling block placement with water lilies and snow buckets
++ org.bukkit.block.BlockState blockstate = null;
++ if (this instanceof PlaceOnWaterBlockItem || this instanceof SolidBucketItem) {
++ blockstate = org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockactioncontext1.getLevel(), blockactioncontext1.getClickedPos());
++ }
++ // CraftBukkit end
++
++ if (iblockdata == null) {
+ return InteractionResult.FAIL;
+ } else if (!this.placeBlock(blockPlaceContext, placementState)) {
+ return InteractionResult.FAIL;
+ } else {
+- BlockPos clickedPos = blockPlaceContext.getClickedPos();
+- Level level = blockPlaceContext.getLevel();
+- Player player = blockPlaceContext.getPlayer();
+- ItemStack itemInHand = blockPlaceContext.getItemInHand();
+- BlockState blockState = level.getBlockState(clickedPos);
+- if (blockState.is(placementState.getBlock())) {
+- blockState = this.updateBlockStateFromTag(clickedPos, level, itemInHand, blockState);
+- this.updateCustomBlockEntityTag(clickedPos, level, player, itemInHand, blockState);
+- blockState.getBlock().setPlacedBy(level, clickedPos, blockState, player, itemInHand);
+- if (player instanceof ServerPlayer) {
+- CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer)player, clickedPos, itemInHand);
++ BlockPos blockposition = blockactioncontext1.getClickedPos();
++ Level world = blockactioncontext1.getLevel();
++ Player entityhuman = blockactioncontext1.getPlayer();
++ ItemStack itemstack = blockactioncontext1.getItemInHand();
++ IBlockData iblockdata1 = world.getBlockState(blockposition);
++
++ if (iblockdata1.is(iblockdata.getBlock())) {
++ iblockdata1 = this.updateBlockStateFromTag(blockposition, world, itemstack, iblockdata1);
++ this.updateCustomBlockEntityTag(blockposition, world, entityhuman, itemstack, iblockdata1);
++ iblockdata1.getBlock().setPlacedBy(world, blockposition, iblockdata1, entityhuman, itemstack);
++ // CraftBukkit start
++ if (blockstate != null) {
++ org.bukkit.event.block.BlockPlaceEvent placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent((ServerLevel) world, entityhuman, blockactioncontext1.getHand(), blockstate, blockposition.getX(), blockposition.getY(), blockposition.getZ());
++ if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) {
++ blockstate.update(true, false);
++
++ if (this instanceof SolidBucketItem) {
++ ((ServerPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
++ }
++ return InteractionResult.FAIL;
++ }
+ }
++ // CraftBukkit end
++ if (entityhuman instanceof ServerPlayer) {
++ CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer) entityhuman, blockposition, itemstack);
++ }
+ }
+
+- SoundType soundType = blockState.getSoundType();
+- level.playSound(
+- player,
+- clickedPos,
+- this.getPlaceSound(blockState),
+- SoundSource.BLOCKS,
+- (soundType.getVolume() + 1.0F) / 2.0F,
+- soundType.getPitch() * 0.8F
+- );
+- level.gameEvent(GameEvent.BLOCK_PLACE, clickedPos, GameEvent.Context.of(player, blockState));
+- if (player == null || !player.getAbilities().instabuild) {
+- itemInHand.shrink(1);
++ SoundType soundeffecttype = iblockdata1.getSoundType();
++
++ // world.playSound(entityhuman, blockposition, this.getPlaceSound(iblockdata1), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F);
++ world.gameEvent(GameEvent.BLOCK_PLACE, blockposition, GameEvent.Context.of(entityhuman, iblockdata1));
++ if ((entityhuman == null || !entityhuman.getAbilities().instabuild) && itemstack != ItemStack.EMPTY) { // CraftBukkit
++ itemstack.shrink(1);
+ }
+
+ return InteractionResult.sidedSuccess(level.isClientSide);
+@@ -128,13 +153,10 @@
+ CompoundTag compound = tag.getCompound("BlockStateTag");
+ StateDefinition<Block, BlockState> stateDefinition = state.getBlock().getStateDefinition();
+
+- for (String string : compound.getAllKeys()) {
+- Property<?> property = stateDefinition.getProperty(string);
+- if (property != null) {
+- String asString = compound.get(string).getAsString();
+- blockState = updateState(blockState, property, asString);
+- }
+- }
++ if (nbttagcompound != null) {
++ CompoundTag nbttagcompound1 = nbttagcompound.getCompound("BlockStateTag");
++ // CraftBukkit start
++ iblockdata1 = getBlockState(iblockdata1, nbttagcompound1);
+ }
+
+ if (blockState != state) {
+@@ -144,8 +166,25 @@
+ return blockState;
+ }
+
+- private static <T extends Comparable<T>> BlockState updateState(BlockState state, Property<T> property, String valueIdentifier) {
+- return property.getValue(valueIdentifier).map(comparable -> state.setValue(property, comparable)).orElse(state);
++ public static IBlockData getBlockState(IBlockData iblockdata, CompoundTag nbttagcompound1) {
++ IBlockData iblockdata1 = iblockdata;
++ {
++ // CraftBukkit end
++ StateDefinition<Block, IBlockData> blockstatelist = iblockdata.getBlock().getStateDefinition();
++ Iterator iterator = nbttagcompound1.getAllKeys().iterator();
++
++ while (iterator.hasNext()) {
++ String s = (String) iterator.next();
++ Property<?> iblockstate = blockstatelist.getProperty(s);
++
++ if (iblockstate != null) {
++ String s1 = nbttagcompound1.get(s).getAsString();
++
++ iblockdata1 = updateState(iblockdata1, iblockstate, s1);
++ }
++ }
++ }
++ return iblockdata1;
+ }
+
+ protected boolean canPlace(BlockPlaceContext context, BlockState state) {
+@@ -155,6 +193,20 @@
+ && context.getLevel().isUnobstructed(state, context.getClickedPos(), collisionContext);
+ }
+
++ protected boolean canPlace(BlockPlaceContext context, IBlockData state) {
++ Player entityhuman = context.getPlayer();
++ CollisionContext voxelshapecollision = entityhuman == null ? CollisionContext.empty() : CollisionContext.of(entityhuman);
++ // CraftBukkit start - store default return
++ boolean defaultReturn = (!this.mustSurvive() || state.canSurvive(context.getLevel(), context.getClickedPos())) && context.getLevel().isUnobstructed(state, context.getClickedPos(), voxelshapecollision);
++ org.bukkit.entity.Player player = (context.getPlayer() instanceof ServerPlayer) ? (org.bukkit.entity.Player) context.getPlayer().getBukkitEntity() : null;
++
++ BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(context.getLevel(), context.getClickedPos()), player, CraftBlockData.fromData(state), defaultReturn);
++ context.getLevel().getCraftServer().getPluginManager().callEvent(event);
++
++ return event.isBuildable();
++ // CraftBukkit end
++ }
++
+ protected boolean mustSurvive() {
+ return true;
+ }