diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/item/HangingEntityItem.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/item/HangingEntityItem.java.patch | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/item/HangingEntityItem.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/item/HangingEntityItem.java.patch new file mode 100644 index 0000000000..f19767ab05 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/item/HangingEntityItem.java.patch @@ -0,0 +1,183 @@ +--- a/net/minecraft/world/item/HangingEntityItem.java ++++ b/net/minecraft/world/item/HangingEntityItem.java +@@ -6,23 +6,28 @@ + import net.minecraft.ChatFormatting; + import net.minecraft.core.BlockPos; + import net.minecraft.core.Direction; +-import net.minecraft.core.Holder; + import net.minecraft.nbt.CompoundTag; + import net.minecraft.network.chat.Component; +-import net.minecraft.resources.ResourceKey; + import net.minecraft.util.Mth; + import net.minecraft.world.InteractionResult; ++import net.minecraft.world.entity.Entity; + import net.minecraft.world.entity.EntityType; + import net.minecraft.world.entity.decoration.GlowItemFrame; + import net.minecraft.world.entity.decoration.HangingEntity; + import net.minecraft.world.entity.decoration.ItemFrame; + import net.minecraft.world.entity.decoration.Painting; +-import net.minecraft.world.entity.player.Player; ++import net.minecraft.world.entity.decoration.PaintingVariant; + import net.minecraft.world.item.context.UseOnContext; + import net.minecraft.world.level.Level; + import net.minecraft.world.level.gameevent.GameEvent; + ++// CraftBukkit start ++import org.bukkit.entity.Player; ++import org.bukkit.event.hanging.HangingPlaceEvent; ++// CraftBukkit end ++ + public class HangingEntityItem extends Item { ++ + private static final Component TOOLTIP_RANDOM_VARIANT = Component.translatable("painting.random").withStyle(ChatFormatting.GRAY); + private final EntityType<? extends HangingEntity> type; + +@@ -33,54 +38,71 @@ + + @Override + public InteractionResult useOn(UseOnContext context) { +- BlockPos clickedPos = context.getClickedPos(); +- Direction clickedFace = context.getClickedFace(); +- BlockPos blockPos = clickedPos.relative(clickedFace); +- Player player = context.getPlayer(); +- ItemStack itemInHand = context.getItemInHand(); +- if (player != null && !this.mayPlace(player, clickedFace, itemInHand, blockPos)) { ++ BlockPos blockposition = context.getClickedPos(); ++ Direction enumdirection = context.getClickedFace(); ++ BlockPos blockposition1 = blockposition.relative(enumdirection); ++ net.minecraft.world.entity.player.Player entityhuman = context.getPlayer(); ++ ItemStack itemstack = context.getItemInHand(); ++ ++ if (entityhuman != null && !this.mayPlace(entityhuman, enumdirection, itemstack, blockposition1)) { + return InteractionResult.FAIL; + } else { +- Level level = context.getLevel(); +- HangingEntity hangingEntity; ++ Level world = context.getLevel(); ++ Object object; ++ + if (this.type == EntityType.PAINTING) { +- Optional<Painting> optional = Painting.create(level, blockPos, clickedFace); ++ Optional<Painting> optional = Painting.create(world, blockposition1, enumdirection); ++ + if (optional.isEmpty()) { + return InteractionResult.CONSUME; + } + +- hangingEntity = optional.get(); ++ object = (HangingEntity) optional.get(); + } else if (this.type == EntityType.ITEM_FRAME) { +- hangingEntity = new ItemFrame(level, blockPos, clickedFace); ++ object = new ItemFrame(world, blockposition1, enumdirection); + } else { + if (this.type != EntityType.GLOW_ITEM_FRAME) { +- return InteractionResult.sidedSuccess(level.isClientSide); ++ return InteractionResult.sidedSuccess(world.isClientSide); + } + +- hangingEntity = new GlowItemFrame(level, blockPos, clickedFace); ++ object = new GlowItemFrame(world, blockposition1, enumdirection); + } + +- CompoundTag tag = itemInHand.getTag(); +- if (tag != null) { +- EntityType.updateCustomEntityTag(level, player, hangingEntity, tag); ++ CompoundTag nbttagcompound = itemstack.getTag(); ++ ++ if (nbttagcompound != null) { ++ EntityType.updateCustomEntityTag(world, entityhuman, (Entity) object, nbttagcompound); + } + +- if (hangingEntity.survives()) { +- if (!level.isClientSide) { +- hangingEntity.playPlacementSound(); +- level.gameEvent(player, GameEvent.ENTITY_PLACE, hangingEntity.position()); +- level.addFreshEntity(hangingEntity); ++ if (((HangingEntity) object).survives()) { ++ if (!world.isClientSide) { ++ // CraftBukkit start - fire HangingPlaceEvent ++ Player who = (context.getPlayer() == null) ? null : (Player) context.getPlayer().getBukkitEntity(); ++ org.bukkit.block.Block blockClicked = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); ++ org.bukkit.block.BlockFace blockFace = org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(enumdirection); ++ org.bukkit.inventory.EquipmentSlot hand = org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(context.getHand()); ++ ++ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) ((HangingEntity) object).getBukkitEntity(), who, blockClicked, blockFace, hand, org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); ++ world.getCraftServer().getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ return InteractionResult.FAIL; ++ } ++ // CraftBukkit end ++ ((HangingEntity) object).playPlacementSound(); ++ world.gameEvent((Entity) entityhuman, GameEvent.ENTITY_PLACE, ((HangingEntity) object).position()); ++ world.addFreshEntity((Entity) object); + } + +- itemInHand.shrink(1); +- return InteractionResult.sidedSuccess(level.isClientSide); ++ itemstack.shrink(1); ++ return InteractionResult.sidedSuccess(world.isClientSide); + } else { + return InteractionResult.CONSUME; + } + } + } + +- protected boolean mayPlace(Player player, Direction direction, ItemStack hangingEntityStack, BlockPos pos) { ++ protected boolean mayPlace(net.minecraft.world.entity.player.Player player, Direction direction, ItemStack hangingEntityStack, BlockPos pos) { + return !direction.getAxis().isVertical() && player.mayUseItemAt(pos, direction, hangingEntityStack); + } + +@@ -88,36 +110,24 @@ + public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents, TooltipFlag isAdvanced) { + super.appendHoverText(stack, level, tooltipComponents, isAdvanced); + if (this.type == EntityType.PAINTING) { +- CompoundTag tag = stack.getTag(); +- if (tag != null && tag.contains("EntityTag", 10)) { +- CompoundTag compound = tag.getCompound("EntityTag"); +- Painting.loadVariant(compound) +- .ifPresentOrElse( +- holder -> { +- holder.unwrapKey() +- .ifPresent( +- resourceKey -> { +- tooltipComponents.add( +- Component.translatable(resourceKey.location().toLanguageKey("painting", "title")).withStyle(ChatFormatting.YELLOW) +- ); +- tooltipComponents.add( +- Component.translatable(resourceKey.location().toLanguageKey("painting", "author")).withStyle(ChatFormatting.GRAY) +- ); +- } +- ); +- tooltipComponents.add( +- Component.translatable( +- "painting.dimensions", +- Mth.positiveCeilDiv(holder.value().getWidth(), 16), +- Mth.positiveCeilDiv(holder.value().getHeight(), 16) +- ) +- ); +- }, +- () -> tooltipComponents.add(TOOLTIP_RANDOM_VARIANT) +- ); ++ CompoundTag nbttagcompound = stack.getTag(); ++ ++ if (nbttagcompound != null && nbttagcompound.contains("EntityTag", 10)) { ++ CompoundTag nbttagcompound1 = nbttagcompound.getCompound("EntityTag"); ++ ++ Painting.loadVariant(nbttagcompound1).ifPresentOrElse((holder) -> { ++ holder.unwrapKey().ifPresent((resourcekey) -> { ++ tooltipComponents.add(Component.translatable(resourcekey.location().toLanguageKey("painting", "title")).withStyle(ChatFormatting.YELLOW)); ++ tooltipComponents.add(Component.translatable(resourcekey.location().toLanguageKey("painting", "author")).withStyle(ChatFormatting.GRAY)); ++ }); ++ tooltipComponents.add(Component.translatable("painting.dimensions", Mth.positiveCeilDiv(((PaintingVariant) holder.value()).getWidth(), 16), Mth.positiveCeilDiv(((PaintingVariant) holder.value()).getHeight(), 16))); ++ }, () -> { ++ tooltipComponents.add(HangingEntityItem.TOOLTIP_RANDOM_VARIANT); ++ }); + } else if (isAdvanced.isCreative()) { +- tooltipComponents.add(TOOLTIP_RANDOM_VARIANT); ++ tooltipComponents.add(HangingEntityItem.TOOLTIP_RANDOM_VARIANT); + } + } ++ + } + } |