aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/world/item/BlockItem.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/item/BlockItem.java.patch')
-rw-r--r--patch-remap/mache-spigotflower/net/minecraft/world/item/BlockItem.java.patch398
1 files changed, 398 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/item/BlockItem.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/item/BlockItem.java.patch
new file mode 100644
index 0000000000..fff559072b
--- /dev/null
+++ b/patch-remap/mache-spigotflower/net/minecraft/world/item/BlockItem.java.patch
@@ -0,0 +1,398 @@
+--- a/net/minecraft/world/item/BlockItem.java
++++ b/net/minecraft/world/item/BlockItem.java
+@@ -12,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;
+@@ -27,11 +27,15 @@
+ 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 {
+
+@@ -41,164 +45,199 @@
+ @Deprecated
+ private final Block block;
+
+- public BlockItem(Block block, Item.Properties item_properties) {
+- super(item_properties);
++ public BlockItem(Block block, Item.Properties properties) {
++ super(properties);
+ this.block = block;
+ }
+
+ @Override
+- @Override
+- public InteractionResult useOn(UseOnContext useoncontext) {
+- InteractionResult interactionresult = this.place(new BlockPlaceContext(useoncontext));
++ public InteractionResult useOn(UseOnContext context) {
++ InteractionResult enuminteractionresult = this.place(new BlockPlaceContext(context));
+
+- if (!interactionresult.consumesAction() && this.isEdible()) {
+- InteractionResult interactionresult1 = this.use(useoncontext.getLevel(), useoncontext.getPlayer(), useoncontext.getHand()).getResult();
++ if (!enuminteractionresult.consumesAction() && this.isEdible()) {
++ InteractionResult enuminteractionresult1 = this.use(context.getLevel(), context.getPlayer(), context.getHand()).getResult();
+
+- return interactionresult1 == InteractionResult.CONSUME ? InteractionResult.CONSUME_PARTIAL : interactionresult1;
++ return enuminteractionresult1 == InteractionResult.CONSUME ? InteractionResult.CONSUME_PARTIAL : enuminteractionresult1;
+ } else {
+- return interactionresult;
++ return enuminteractionresult;
+ }
+ }
+
+- public InteractionResult place(BlockPlaceContext blockplacecontext) {
+- if (!this.getBlock().isEnabled(blockplacecontext.getLevel().enabledFeatures())) {
++ public InteractionResult place(BlockPlaceContext context) {
++ if (!this.getBlock().isEnabled(context.getLevel().enabledFeatures())) {
+ return InteractionResult.FAIL;
+- } else if (!blockplacecontext.canPlace()) {
++ } else if (!context.canPlace()) {
+ return InteractionResult.FAIL;
+ } else {
+- BlockPlaceContext blockplacecontext1 = this.updatePlacementContext(blockplacecontext);
++ BlockPlaceContext blockactioncontext1 = this.updatePlacementContext(context);
+
+- if (blockplacecontext1 == null) {
++ if (blockactioncontext1 == null) {
+ return InteractionResult.FAIL;
+ } else {
+- BlockState blockstate = this.getPlacementState(blockplacecontext1);
++ 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 (blockstate == null) {
++ if (iblockdata == null) {
+ return InteractionResult.FAIL;
+- } else if (!this.placeBlock(blockplacecontext1, blockstate)) {
++ } else if (!this.placeBlock(blockactioncontext1, iblockdata)) {
+ return InteractionResult.FAIL;
+ } else {
+- BlockPos blockpos = blockplacecontext1.getClickedPos();
+- Level level = blockplacecontext1.getLevel();
+- Player player = blockplacecontext1.getPlayer();
+- ItemStack itemstack = blockplacecontext1.getItemInHand();
+- BlockState blockstate1 = level.getBlockState(blockpos);
++ BlockPos blockposition = blockactioncontext1.getClickedPos();
++ Level world = blockactioncontext1.getLevel();
++ Player entityhuman = blockactioncontext1.getPlayer();
++ ItemStack itemstack = blockactioncontext1.getItemInHand();
++ IBlockData iblockdata1 = world.getBlockState(blockposition);
+
+- if (blockstate1.is(blockstate.getBlock())) {
+- blockstate1 = this.updateBlockStateFromTag(blockpos, level, itemstack, blockstate1);
+- this.updateCustomBlockEntityTag(blockpos, level, player, itemstack, blockstate1);
+- blockstate1.getBlock().setPlacedBy(level, blockpos, blockstate1, player, itemstack);
+- if (player instanceof ServerPlayer) {
+- CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer) player, blockpos, itemstack);
++ 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 = blockstate1.getSoundType();
++ SoundType soundeffecttype = iblockdata1.getSoundType();
+
+- level.playSound(player, blockpos, this.getPlaceSound(blockstate1), SoundSource.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
+- level.gameEvent(GameEvent.BLOCK_PLACE, blockpos, GameEvent.Context.of(player, blockstate1));
+- if (player == null || !player.getAbilities().instabuild) {
++ // 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 blockstate) {
+- return blockstate.getSoundType().getPlaceSound();
++ protected SoundEvent getPlaceSound(IBlockData state) {
++ return state.getSoundType().getPlaceSound();
+ }
+
+ @Nullable
+- public BlockPlaceContext updatePlacementContext(BlockPlaceContext blockplacecontext) {
+- return blockplacecontext;
++ public BlockPlaceContext updatePlacementContext(BlockPlaceContext context) {
++ return context;
+ }
+
+- protected boolean updateCustomBlockEntityTag(BlockPos blockpos, Level level, @Nullable Player player, ItemStack itemstack, BlockState blockstate) {
+- return updateCustomBlockEntityTag(level, player, blockpos, itemstack);
++ 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 blockplacecontext) {
+- BlockState blockstate = this.getBlock().getStateForPlacement(blockplacecontext);
++ protected IBlockData getPlacementState(BlockPlaceContext context) {
++ IBlockData iblockdata = this.getBlock().getStateForPlacement(context);
+
+- return blockstate != null && this.canPlace(blockplacecontext, blockstate) ? blockstate : null;
++ return iblockdata != null && this.canPlace(context, iblockdata) ? iblockdata : null;
+ }
+
+- private BlockState updateBlockStateFromTag(BlockPos blockpos, Level level, ItemStack itemstack, BlockState blockstate) {
+- BlockState blockstate1 = blockstate;
+- CompoundTag compoundtag = itemstack.getTag();
++ private IBlockData updateBlockStateFromTag(BlockPos pos, Level level, ItemStack stack, IBlockData state) {
++ IBlockData iblockdata1 = state;
++ CompoundTag nbttagcompound = stack.getTag();
+
+- if (compoundtag != null) {
+- CompoundTag compoundtag1 = compoundtag.getCompound("BlockStateTag");
+- StateDefinition<Block, BlockState> statedefinition = blockstate.getBlock().getStateDefinition();
+- Iterator iterator = compoundtag1.getAllKeys().iterator();
++ if (nbttagcompound != null) {
++ CompoundTag nbttagcompound1 = nbttagcompound.getCompound("BlockStateTag");
++ // CraftBukkit start
++ iblockdata1 = getBlockState(iblockdata1, nbttagcompound1);
++ }
+
++ if (iblockdata1 != state) {
++ level.setBlock(pos, iblockdata1, 2);
++ }
++
++ return iblockdata1;
++ }
++
++ 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<?> property = statedefinition.getProperty(s);
++ Property<?> iblockstate = blockstatelist.getProperty(s);
+
+- if (property != null) {
+- String s1 = compoundtag1.get(s).getAsString();
++ if (iblockstate != null) {
++ String s1 = nbttagcompound1.get(s).getAsString();
+
+- blockstate1 = updateState(blockstate1, property, s1);
++ iblockdata1 = updateState(iblockdata1, iblockstate, s1);
+ }
+ }
+ }
+-
+- if (blockstate1 != blockstate) {
+- level.setBlock(blockpos, blockstate1, 2);
+- }
+-
+- return blockstate1;
++ return iblockdata1;
+ }
+
+- private static <T extends Comparable<T>> BlockState updateState(BlockState blockstate, Property<T> property, String s) {
+- return (BlockState) property.getValue(s).map((comparable) -> {
+- return (BlockState) blockstate.setValue(property, comparable);
+- }).orElse(blockstate);
++ 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 blockplacecontext, BlockState blockstate) {
+- Player player = blockplacecontext.getPlayer();
+- CollisionContext collisioncontext = player == null ? CollisionContext.empty() : CollisionContext.of(player);
++ 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;
+
+- return (!this.mustSurvive() || blockstate.canSurvive(blockplacecontext.getLevel(), blockplacecontext.getClickedPos())) && blockplacecontext.getLevel().isUnobstructed(blockstate, blockplacecontext.getClickedPos(), collisioncontext);
++ 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 blockplacecontext, BlockState blockstate) {
+- return blockplacecontext.getLevel().setBlock(blockplacecontext.getClickedPos(), blockstate, 11);
++ 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 blockpos, ItemStack itemstack) {
++ public static boolean updateCustomBlockEntityTag(Level level, @Nullable Player player, BlockPos pos, ItemStack stack) {
+ MinecraftServer minecraftserver = level.getServer();
+
+ if (minecraftserver == null) {
+ return false;
+ } else {
+- CompoundTag compoundtag = getBlockEntityData(itemstack);
++ CompoundTag nbttagcompound = getBlockEntityData(stack);
+
+- if (compoundtag != null) {
+- BlockEntity blockentity = level.getBlockEntity(blockpos);
++ if (nbttagcompound != null) {
++ BlockEntity tileentity = level.getBlockEntity(pos);
+
+- if (blockentity != null) {
+- if (!level.isClientSide && blockentity.onlyOpCanSetNbt() && (player == null || !player.canUseGameMasterBlocks())) {
++ if (tileentity != null) {
++ if (!level.isClientSide && tileentity.onlyOpCanSetNbt() && (player == null || !player.canUseGameMasterBlocks())) {
+ return false;
+ }
+
+- CompoundTag compoundtag1 = blockentity.saveWithoutMetadata();
+- CompoundTag compoundtag2 = compoundtag1.copy();
++ CompoundTag nbttagcompound1 = tileentity.saveWithoutMetadata();
++ CompoundTag nbttagcompound2 = nbttagcompound1.copy();
+
+- compoundtag1.merge(compoundtag);
+- if (!compoundtag1.equals(compoundtag2)) {
+- blockentity.load(compoundtag1);
+- blockentity.setChanged();
++ nbttagcompound1.merge(nbttagcompound);
++ if (!nbttagcompound1.equals(nbttagcompound2)) {
++ tileentity.load(nbttagcompound1);
++ tileentity.setChanged();
+ return true;
+ }
+ }
+@@ -209,67 +248,62 @@
+ }
+
+ @Override
+- @Override
+ public String getDescriptionId() {
+ return this.getBlock().getDescriptionId();
+ }
+
+ @Override
+- @Override
+- public void appendHoverText(ItemStack itemstack, @Nullable Level level, List<Component> list, TooltipFlag tooltipflag) {
+- super.appendHoverText(itemstack, level, list, tooltipflag);
+- this.getBlock().appendHoverText(itemstack, level, list, tooltipflag);
++ public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flag) {
++ super.appendHoverText(stack, level, tooltip, flag);
++ this.getBlock().appendHoverText(stack, level, tooltip, flag);
+ }
+
+ public Block getBlock() {
+ return this.block;
+ }
+
+- public void registerBlocks(Map<Block, Item> map, Item item) {
+- map.put(this.getBlock(), item);
++ public void registerBlocks(Map<Block, Item> blockToItemMap, Item item) {
++ blockToItemMap.put(this.getBlock(), item);
+ }
+
+ @Override
+- @Override
+ public boolean canFitInsideContainerItems() {
+ return !(this.block instanceof ShulkerBoxBlock);
+ }
+
+ @Override
+- @Override
+- public void onDestroyed(ItemEntity itementity) {
++ public void onDestroyed(ItemEntity itemEntity) {
+ if (this.block instanceof ShulkerBoxBlock) {
+- ItemStack itemstack = itementity.getItem();
+- CompoundTag compoundtag = getBlockEntityData(itemstack);
++ ItemStack itemstack = itemEntity.getItem();
++ CompoundTag nbttagcompound = getBlockEntityData(itemstack);
+
+- if (compoundtag != null && compoundtag.contains("Items", 9)) {
+- ListTag listtag = compoundtag.getList("Items", 10);
+- Stream stream = listtag.stream();
++ 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));
++ ItemUtils.onContainerDestroyed(itemEntity, stream.map(CompoundTag.class::cast).map(ItemStack::of));
+ }
+ }
+
+ }
+
+ @Nullable
+- public static CompoundTag getBlockEntityData(ItemStack itemstack) {
+- return itemstack.getTagElement("BlockEntityTag");
++ public static CompoundTag getBlockEntityData(ItemStack stack) {
++ return stack.getTagElement("BlockEntityTag");
+ }
+
+- public static void setBlockEntityData(ItemStack itemstack, BlockEntityType<?> blockentitytype, CompoundTag compoundtag) {
+- if (compoundtag.isEmpty()) {
+- itemstack.removeTagKey("BlockEntityTag");
++ public static void setBlockEntityData(ItemStack stack, BlockEntityType<?> blockEntityType, CompoundTag blockEntityData) {
++ if (blockEntityData.isEmpty()) {
++ stack.removeTagKey("BlockEntityTag");
+ } else {
+- BlockEntity.addEntityType(compoundtag, blockentitytype);
+- itemstack.addTagElement("BlockEntityTag", compoundtag);
++ BlockEntity.addEntityType(blockEntityData, blockEntityType);
++ stack.addTagElement("BlockEntityTag", blockEntityData);
+ }
+
+ }
+
+ @Override
+- @Override
+ public FeatureFlagSet requiredFeatures() {
+ return this.getBlock().requiredFeatures();
+ }