diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/item/BlockItem.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/item/BlockItem.java.patch | 345 |
1 files changed, 345 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/item/BlockItem.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/item/BlockItem.java.patch new file mode 100644 index 0000000000..5230934354 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/item/BlockItem.java.patch @@ -0,0 +1,345 @@ +--- a/net/minecraft/world/item/BlockItem.java ++++ b/net/minecraft/world/item/BlockItem.java +@@ -1,7 +1,10 @@ + package net.minecraft.world.item; + ++import java.util.Iterator; + import java.util.List; + import java.util.Map; ++import java.util.Objects; ++import java.util.stream.Stream; + import javax.annotation.Nullable; + import net.minecraft.advancements.CriteriaTriggers; + import net.minecraft.core.BlockPos; +@@ -9,9 +12,9 @@ + import net.minecraft.nbt.ListTag; + import net.minecraft.network.chat.Component; + import net.minecraft.server.MinecraftServer; ++import net.minecraft.server.level.ServerLevel; + import net.minecraft.server.level.ServerPlayer; + import net.minecraft.sounds.SoundEvent; +-import net.minecraft.sounds.SoundSource; + import net.minecraft.world.InteractionResult; + import net.minecraft.world.entity.item.ItemEntity; + import net.minecraft.world.entity.player.Player; +@@ -24,15 +27,21 @@ + import net.minecraft.world.level.block.SoundType; + import net.minecraft.world.level.block.entity.BlockEntity; + import net.minecraft.world.level.block.entity.BlockEntityType; +-import net.minecraft.world.level.block.state.BlockState; ++import net.minecraft.world.level.block.state.IBlockData; + import net.minecraft.world.level.block.state.StateDefinition; + 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"; + public static final String BLOCK_STATE_TAG = "BlockStateTag"; ++ /** @deprecated */ + @Deprecated + private final Block block; + +@@ -43,12 +52,14 @@ + + @Override + public InteractionResult useOn(UseOnContext context) { +- InteractionResult interactionResult = this.place(new BlockPlaceContext(context)); +- if (!interactionResult.consumesAction() && this.isEdible()) { +- InteractionResult result = this.use(context.getLevel(), context.getPlayer(), context.getHand()).getResult(); +- return result == InteractionResult.CONSUME ? InteractionResult.CONSUME_PARTIAL : result; ++ InteractionResult enuminteractionresult = this.place(new BlockPlaceContext(context)); ++ ++ if (!enuminteractionresult.consumesAction() && this.isEdible()) { ++ InteractionResult enuminteractionresult1 = this.use(context.getLevel(), context.getPlayer(), context.getHand()).getResult(); ++ ++ return enuminteractionresult1 == InteractionResult.CONSUME ? InteractionResult.CONSUME_PARTIAL : enuminteractionresult1; + } else { +- return interactionResult; ++ return enuminteractionresult; + } + } + +@@ -58,51 +69,67 @@ + } else if (!context.canPlace()) { + return InteractionResult.FAIL; + } else { +- BlockPlaceContext blockPlaceContext = this.updatePlacementContext(context); +- if (blockPlaceContext == null) { ++ BlockPlaceContext blockactioncontext1 = this.updatePlacementContext(context); ++ ++ if (blockactioncontext1 == 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)) { ++ } else if (!this.placeBlock(blockactioncontext1, iblockdata)) { + 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); ++ return InteractionResult.sidedSuccess(world.isClientSide); + } + } + } + } + +- protected SoundEvent getPlaceSound(BlockState state) { ++ protected SoundEvent getPlaceSound(IBlockData state) { + return state.getSoundType().getPlaceSound(); + } + +@@ -111,77 +138,106 @@ + return context; + } + +- protected boolean updateCustomBlockEntityTag(BlockPos pos, Level level, @Nullable Player player, ItemStack stack, BlockState state) { ++ protected boolean updateCustomBlockEntityTag(BlockPos pos, Level level, @Nullable Player player, ItemStack stack, IBlockData state) { + return updateCustomBlockEntityTag(level, player, pos, stack); + } + + @Nullable +- protected BlockState getPlacementState(BlockPlaceContext context) { +- BlockState stateForPlacement = this.getBlock().getStateForPlacement(context); +- return stateForPlacement != null && this.canPlace(context, stateForPlacement) ? stateForPlacement : null; ++ protected IBlockData getPlacementState(BlockPlaceContext context) { ++ IBlockData iblockdata = this.getBlock().getStateForPlacement(context); ++ ++ return iblockdata != null && this.canPlace(context, iblockdata) ? iblockdata : null; + } + +- private BlockState updateBlockStateFromTag(BlockPos pos, Level level, ItemStack stack, BlockState state) { +- BlockState blockState = state; +- CompoundTag tag = stack.getTag(); +- if (tag != null) { +- CompoundTag compound = tag.getCompound("BlockStateTag"); +- StateDefinition<Block, BlockState> stateDefinition = state.getBlock().getStateDefinition(); ++ private IBlockData updateBlockStateFromTag(BlockPos pos, Level level, ItemStack stack, IBlockData state) { ++ IBlockData iblockdata1 = state; ++ CompoundTag nbttagcompound = stack.getTag(); + +- 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) { +- level.setBlock(pos, blockState, 2); ++ if (iblockdata1 != state) { ++ level.setBlock(pos, iblockdata1, 2); + } + +- return blockState; ++ return iblockdata1; + } + +- 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) { +- Player player = context.getPlayer(); +- CollisionContext collisionContext = player == null ? CollisionContext.empty() : CollisionContext.of(player); +- return (!this.mustSurvive() || state.canSurvive(context.getLevel(), context.getClickedPos())) +- && context.getLevel().isUnobstructed(state, context.getClickedPos(), collisionContext); ++ private static <T extends Comparable<T>> IBlockData updateState(IBlockData state, Property<T> property, String valueIdentifier) { ++ return (IBlockData) property.getValue(valueIdentifier).map((comparable) -> { ++ return (IBlockData) state.setValue(property, comparable); ++ }).orElse(state); + } + ++ 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; + } + +- protected boolean placeBlock(BlockPlaceContext context, BlockState state) { ++ protected boolean placeBlock(BlockPlaceContext context, IBlockData state) { + return context.getLevel().setBlock(context.getClickedPos(), state, 11); + } + + public static boolean updateCustomBlockEntityTag(Level level, @Nullable Player player, BlockPos pos, ItemStack stack) { +- MinecraftServer server = level.getServer(); +- if (server == null) { ++ MinecraftServer minecraftserver = level.getServer(); ++ ++ if (minecraftserver == null) { + return false; + } else { +- CompoundTag blockEntityData = getBlockEntityData(stack); +- if (blockEntityData != null) { +- BlockEntity blockEntity = level.getBlockEntity(pos); +- if (blockEntity != null) { +- if (!level.isClientSide && blockEntity.onlyOpCanSetNbt() && (player == null || !player.canUseGameMasterBlocks())) { ++ CompoundTag nbttagcompound = getBlockEntityData(stack); ++ ++ if (nbttagcompound != null) { ++ BlockEntity tileentity = level.getBlockEntity(pos); ++ ++ if (tileentity != null) { ++ if (!level.isClientSide && tileentity.onlyOpCanSetNbt() && (player == null || !player.canUseGameMasterBlocks())) { + return false; + } + +- CompoundTag compoundTag = blockEntity.saveWithoutMetadata(); +- CompoundTag compoundTag1 = compoundTag.copy(); +- compoundTag.merge(blockEntityData); +- if (!compoundTag.equals(compoundTag1)) { +- blockEntity.load(compoundTag); +- blockEntity.setChanged(); ++ CompoundTag nbttagcompound1 = tileentity.saveWithoutMetadata(); ++ CompoundTag nbttagcompound2 = nbttagcompound1.copy(); ++ ++ nbttagcompound1.merge(nbttagcompound); ++ if (!nbttagcompound1.equals(nbttagcompound2)) { ++ tileentity.load(nbttagcompound1); ++ tileentity.setChanged(); + return true; + } + } +@@ -218,13 +274,18 @@ + @Override + public void onDestroyed(ItemEntity itemEntity) { + if (this.block instanceof ShulkerBoxBlock) { +- ItemStack item = itemEntity.getItem(); +- CompoundTag blockEntityData = getBlockEntityData(item); +- if (blockEntityData != null && blockEntityData.contains("Items", 9)) { +- ListTag list = blockEntityData.getList("Items", 10); +- ItemUtils.onContainerDestroyed(itemEntity, list.stream().map(CompoundTag.class::cast).map(ItemStack::of)); ++ ItemStack itemstack = itemEntity.getItem(); ++ CompoundTag nbttagcompound = getBlockEntityData(itemstack); ++ ++ if (nbttagcompound != null && nbttagcompound.contains("Items", 9)) { ++ ListTag nbttaglist = nbttagcompound.getList("Items", 10); ++ Stream<net.minecraft.nbt.Tag> stream = nbttaglist.stream(); // CraftBukkit - decompile error ++ ++ Objects.requireNonNull(CompoundTag.class); ++ ItemUtils.onContainerDestroyed(itemEntity, stream.map(CompoundTag.class::cast).map(ItemStack::of)); + } + } ++ + } + + @Nullable +@@ -239,6 +300,7 @@ + BlockEntity.addEntityType(blockEntityData, blockEntityType); + stack.addTagElement("BlockEntityTag", blockEntityData); + } ++ + } + + @Override |