Move CraftBukkit per-file patches
By: Initial <noreply+automated@papermc.io>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
--- a/net/minecraft/world/item/ItemArmorStand.java
|
||||
+++ b/net/minecraft/world/item/ItemArmorStand.java
|
||||
@@ -53,6 +53,11 @@
|
||||
float f = (float) MathHelper.floor((MathHelper.wrapDegrees(itemactioncontext.getRotation() - 180.0F) + 22.5F) / 45.0F) * 45.0F;
|
||||
|
||||
entityarmorstand.moveTo(entityarmorstand.getX(), entityarmorstand.getY(), entityarmorstand.getZ(), f, 0.0F);
|
||||
+ // CraftBukkit start
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(itemactioncontext, entityarmorstand).isCancelled()) {
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
worldserver.addFreshEntityWithPassengers(entityarmorstand);
|
||||
world.playSound((EntityHuman) null, entityarmorstand.getX(), entityarmorstand.getY(), entityarmorstand.getZ(), SoundEffects.ARMOR_STAND_PLACE, SoundCategory.BLOCKS, 0.75F, 0.8F);
|
||||
entityarmorstand.gameEvent(GameEvent.ENTITY_PLACE, itemactioncontext.getPlayer());
|
||||
@@ -0,0 +1,75 @@
|
||||
--- a/net/minecraft/world/item/ItemBlock.java
|
||||
+++ b/net/minecraft/world/item/ItemBlock.java
|
||||
@@ -32,6 +32,13 @@
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import net.minecraft.server.level.WorldServer;
|
||||
+import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
+import org.bukkit.event.block.BlockCanBuildEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ItemBlock extends Item {
|
||||
|
||||
/** @deprecated */
|
||||
@@ -62,6 +69,12 @@
|
||||
return EnumInteractionResult.FAIL;
|
||||
} else {
|
||||
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 EnumInteractionResult.FAIL;
|
||||
@@ -79,6 +92,19 @@
|
||||
this.updateCustomBlockEntityTag(blockposition, world, entityhuman, itemstack, iblockdata1);
|
||||
updateBlockEntityComponents(world, blockposition, itemstack);
|
||||
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((WorldServer) 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) {
|
||||
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
||||
+ }
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
if (entityhuman instanceof EntityPlayer) {
|
||||
CriterionTriggers.PLACED_BLOCK.trigger((EntityPlayer) entityhuman, blockposition, itemstack);
|
||||
}
|
||||
@@ -86,7 +112,7 @@
|
||||
|
||||
SoundEffectType soundeffecttype = iblockdata1.getSoundType();
|
||||
|
||||
- world.playSound(entityhuman, blockposition, this.getPlaceSound(iblockdata1), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F);
|
||||
+ // world.playSound(entityhuman, blockposition, this.getPlaceSound(iblockdata1), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F);
|
||||
world.gameEvent((Holder) GameEvent.BLOCK_PLACE, blockposition, GameEvent.a.of(entityhuman, iblockdata1));
|
||||
itemstack.consume(1, entityhuman);
|
||||
return EnumInteractionResult.SUCCESS;
|
||||
@@ -144,8 +170,15 @@
|
||||
protected boolean canPlace(BlockActionContext blockactioncontext, IBlockData iblockdata) {
|
||||
EntityHuman entityhuman = blockactioncontext.getPlayer();
|
||||
VoxelShapeCollision voxelshapecollision = entityhuman == null ? VoxelShapeCollision.empty() : VoxelShapeCollision.of(entityhuman);
|
||||
+ // CraftBukkit start - store default return
|
||||
+ boolean defaultReturn = (!this.mustSurvive() || iblockdata.canSurvive(blockactioncontext.getLevel(), blockactioncontext.getClickedPos())) && blockactioncontext.getLevel().isUnobstructed(iblockdata, blockactioncontext.getClickedPos(), voxelshapecollision);
|
||||
+ org.bukkit.entity.Player player = (blockactioncontext.getPlayer() instanceof EntityPlayer) ? (org.bukkit.entity.Player) blockactioncontext.getPlayer().getBukkitEntity() : null;
|
||||
|
||||
- return (!this.mustSurvive() || iblockdata.canSurvive(blockactioncontext.getLevel(), blockactioncontext.getClickedPos())) && blockactioncontext.getLevel().isUnobstructed(iblockdata, blockactioncontext.getClickedPos(), voxelshapecollision);
|
||||
+ BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(blockactioncontext.getLevel(), blockactioncontext.getClickedPos()), player, CraftBlockData.fromData(iblockdata), defaultReturn);
|
||||
+ blockactioncontext.getLevel().getCraftServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ return event.isBuildable();
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
protected boolean mustSurvive() {
|
||||
@@ -0,0 +1,36 @@
|
||||
--- a/net/minecraft/world/item/ItemBlockWallable.java
|
||||
+++ b/net/minecraft/world/item/ItemBlockWallable.java
|
||||
@@ -10,6 +10,12 @@
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
|
||||
+// CraftBukkit start
|
||||
+import net.minecraft.server.level.EntityPlayer;
|
||||
+import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
+import org.bukkit.event.block.BlockCanBuildEvent;
|
||||
+// CraftBukkit end
|
||||
|
||||
public class ItemBlockWallable extends ItemBlock {
|
||||
|
||||
@@ -49,7 +55,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
- return iblockdata1 != null && world.isUnobstructed(iblockdata1, blockposition, VoxelShapeCollision.empty()) ? iblockdata1 : null;
|
||||
+ // CraftBukkit start
|
||||
+ if (iblockdata1 != null) {
|
||||
+ boolean defaultReturn = world.isUnobstructed(iblockdata1, blockposition, VoxelShapeCollision.empty());
|
||||
+ org.bukkit.entity.Player player = (blockactioncontext.getPlayer() instanceof EntityPlayer) ? (org.bukkit.entity.Player) blockactioncontext.getPlayer().getBukkitEntity() : null;
|
||||
+
|
||||
+ BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(world, blockposition), player, CraftBlockData.fromData(iblockdata1), defaultReturn);
|
||||
+ blockactioncontext.getLevel().getCraftServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ return (event.isBuildable()) ? iblockdata1 : null;
|
||||
+ } else {
|
||||
+ return null;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,33 @@
|
||||
--- a/net/minecraft/world/item/ItemBoat.java
|
||||
+++ b/net/minecraft/world/item/ItemBoat.java
|
||||
@@ -58,6 +58,13 @@
|
||||
}
|
||||
|
||||
if (movingobjectpositionblock.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK) {
|
||||
+ // CraftBukkit start - Boat placement
|
||||
+ org.bukkit.event.player.PlayerInteractEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(entityhuman, org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), itemstack, false, enumhand, movingobjectpositionblock.getLocation());
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
AbstractBoat abstractboat = this.getBoat(world, movingobjectpositionblock, itemstack, entityhuman);
|
||||
|
||||
if (abstractboat == null) {
|
||||
@@ -68,7 +75,15 @@
|
||||
return EnumInteractionResult.FAIL;
|
||||
} else {
|
||||
if (!world.isClientSide) {
|
||||
- world.addFreshEntity(abstractboat);
|
||||
+ // CraftBukkit start
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(world, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), entityhuman, abstractboat, enumhand).isCancelled()) {
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
+
|
||||
+ if (!world.addFreshEntity(abstractboat)) {
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
world.gameEvent((Entity) entityhuman, (Holder) GameEvent.ENTITY_PLACE, movingobjectpositionblock.getLocation());
|
||||
itemstack.consume(1, entityhuman);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
--- a/net/minecraft/world/item/ItemBoneMeal.java
|
||||
+++ b/net/minecraft/world/item/ItemBoneMeal.java
|
||||
@@ -35,13 +35,19 @@
|
||||
|
||||
@Override
|
||||
public EnumInteractionResult useOn(ItemActionContext itemactioncontext) {
|
||||
+ // CraftBukkit start - extract bonemeal application logic to separate, static method
|
||||
+ return applyBonemeal(itemactioncontext);
|
||||
+ }
|
||||
+
|
||||
+ public static EnumInteractionResult applyBonemeal(ItemActionContext itemactioncontext) {
|
||||
+ // CraftBukkit end
|
||||
World world = itemactioncontext.getLevel();
|
||||
BlockPosition blockposition = itemactioncontext.getClickedPos();
|
||||
BlockPosition blockposition1 = blockposition.relative(itemactioncontext.getClickedFace());
|
||||
|
||||
if (growCrop(itemactioncontext.getItemInHand(), world, blockposition)) {
|
||||
if (!world.isClientSide) {
|
||||
- itemactioncontext.getPlayer().gameEvent(GameEvent.ITEM_INTERACT_FINISH);
|
||||
+ if (itemactioncontext.getPlayer() != null) itemactioncontext.getPlayer().gameEvent(GameEvent.ITEM_INTERACT_FINISH); // CraftBukkit - SPIGOT-7518
|
||||
world.levelEvent(1505, blockposition, 15);
|
||||
}
|
||||
|
||||
@@ -52,7 +58,7 @@
|
||||
|
||||
if (flag && growWaterPlant(itemactioncontext.getItemInHand(), world, blockposition1, itemactioncontext.getClickedFace())) {
|
||||
if (!world.isClientSide) {
|
||||
- itemactioncontext.getPlayer().gameEvent(GameEvent.ITEM_INTERACT_FINISH);
|
||||
+ if (itemactioncontext.getPlayer() != null) itemactioncontext.getPlayer().gameEvent(GameEvent.ITEM_INTERACT_FINISH); // CraftBukkit - SPIGOT-7518
|
||||
world.levelEvent(1505, blockposition1, 15);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
--- a/net/minecraft/world/item/ItemBucket.java
|
||||
+++ b/net/minecraft/world/item/ItemBucket.java
|
||||
@@ -30,6 +30,16 @@
|
||||
import net.minecraft.world.phys.MovingObjectPosition;
|
||||
import net.minecraft.world.phys.MovingObjectPositionBlock;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
|
||||
+import net.minecraft.server.level.WorldServer;
|
||||
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
|
||||
+import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
+import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ItemBucket extends Item implements DispensibleContainerItem {
|
||||
|
||||
public final FluidType content;
|
||||
@@ -63,6 +73,17 @@
|
||||
|
||||
if (block instanceof IFluidSource) {
|
||||
IFluidSource ifluidsource = (IFluidSource) block;
|
||||
+ // CraftBukkit start
|
||||
+ ItemStack dummyFluid = ifluidsource.pickupBlock(entityhuman, DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
|
||||
+ if (dummyFluid.isEmpty()) return EnumInteractionResult.FAIL; // Don't fire event if the bucket won't be filled.
|
||||
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) world, entityhuman, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem(), enumhand);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager)
|
||||
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
itemstack1 = ifluidsource.pickupBlock(entityhuman, world, blockposition, iblockdata);
|
||||
if (!itemstack1.isEmpty()) {
|
||||
@@ -71,7 +92,7 @@
|
||||
entityhuman.playSound(soundeffect, 1.0F, 1.0F);
|
||||
});
|
||||
world.gameEvent((Entity) entityhuman, (Holder) GameEvent.FLUID_PICKUP, blockposition);
|
||||
- ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1);
|
||||
+ ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit
|
||||
|
||||
if (!world.isClientSide) {
|
||||
CriterionTriggers.FILLED_BUCKET.trigger((EntityPlayer) entityhuman, itemstack1);
|
||||
@@ -86,7 +107,7 @@
|
||||
iblockdata = world.getBlockState(blockposition);
|
||||
BlockPosition blockposition2 = iblockdata.getBlock() instanceof IFluidContainer && this.content == FluidTypes.WATER ? blockposition : blockposition1;
|
||||
|
||||
- if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock)) {
|
||||
+ if (this.emptyContents(entityhuman, world, blockposition2, movingobjectpositionblock, movingobjectpositionblock.getDirection(), blockposition, itemstack, enumhand)) { // CraftBukkit
|
||||
this.checkExtraContent(entityhuman, world, itemstack, blockposition2);
|
||||
if (entityhuman instanceof EntityPlayer) {
|
||||
CriterionTriggers.PLACED_BLOCK.trigger((EntityPlayer) entityhuman, blockposition2, itemstack);
|
||||
@@ -114,6 +135,12 @@
|
||||
|
||||
@Override
|
||||
public boolean emptyContents(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock) {
|
||||
+ // CraftBukkit start
|
||||
+ return emptyContents(entityhuman, world, blockposition, movingobjectpositionblock, null, null, null, EnumHand.MAIN_HAND);
|
||||
+ }
|
||||
+
|
||||
+ public boolean emptyContents(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack, EnumHand enumhand) {
|
||||
+ // CraftBukkit end
|
||||
FluidType fluidtype = this.content;
|
||||
|
||||
if (!(fluidtype instanceof FluidTypeFlowing fluidtypeflowing)) {
|
||||
@@ -149,8 +176,18 @@
|
||||
|
||||
boolean flag2 = flag1;
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ if (flag2 && entityhuman != null) {
|
||||
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((WorldServer) world, entityhuman, blockposition, clicked, enumdirection, itemstack, enumhand);
|
||||
+ if (event.isCancelled()) {
|
||||
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-4238: needed when looking through entity
|
||||
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
||||
+ return false;
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
if (!flag2) {
|
||||
- return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null);
|
||||
+ return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (MovingObjectPositionBlock) null, enumdirection, clicked, itemstack, enumhand); // CraftBukkit
|
||||
} else if (world.dimensionType().ultraWarm() && this.content.is(TagsFluid.WATER)) {
|
||||
int i = blockposition.getX();
|
||||
int j = blockposition.getY();
|
||||
@@ -0,0 +1,16 @@
|
||||
--- a/net/minecraft/world/item/ItemDebugStick.java
|
||||
+++ b/net/minecraft/world/item/ItemDebugStick.java
|
||||
@@ -1,3 +1,4 @@
|
||||
+// mc-dev import
|
||||
package net.minecraft.world.item;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -92,7 +93,7 @@
|
||||
}
|
||||
|
||||
private static <T extends Comparable<T>> IBlockData cycleState(IBlockData iblockdata, IBlockState<T> iblockstate, boolean flag) {
|
||||
- return (IBlockData) iblockdata.setValue(iblockstate, (Comparable) getRelative(iblockstate.getPossibleValues(), iblockdata.getValue(iblockstate), flag));
|
||||
+ return (IBlockData) iblockdata.setValue(iblockstate, getRelative(iblockstate.getPossibleValues(), iblockdata.getValue(iblockstate), flag)); // CraftBukkit - decompile error
|
||||
}
|
||||
|
||||
private static <T> T getRelative(Iterable<T> iterable, @Nullable T t0, boolean flag) {
|
||||
@@ -0,0 +1,30 @@
|
||||
--- a/net/minecraft/world/item/ItemDye.java
|
||||
+++ b/net/minecraft/world/item/ItemDye.java
|
||||
@@ -13,6 +13,8 @@
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.block.entity.TileEntitySign;
|
||||
|
||||
+import org.bukkit.event.entity.SheepDyeWoolEvent; // CraftBukkit
|
||||
+
|
||||
public class ItemDye extends Item implements SignApplicator {
|
||||
|
||||
private static final Map<EnumColor, ItemDye> ITEM_BY_COLOR = Maps.newEnumMap(EnumColor.class);
|
||||
@@ -30,7 +32,17 @@
|
||||
if (entitysheep.isAlive() && !entitysheep.isSheared() && entitysheep.getColor() != this.dyeColor) {
|
||||
entitysheep.level().playSound(entityhuman, (Entity) entitysheep, SoundEffects.DYE_USE, SoundCategory.PLAYERS, 1.0F, 1.0F);
|
||||
if (!entityhuman.level().isClientSide) {
|
||||
- entitysheep.setColor(this.dyeColor);
|
||||
+ // CraftBukkit start
|
||||
+ byte bColor = (byte) this.dyeColor.getId();
|
||||
+ SheepDyeWoolEvent event = new SheepDyeWoolEvent((org.bukkit.entity.Sheep) entitysheep.getBukkitEntity(), org.bukkit.DyeColor.getByWoolData(bColor), (org.bukkit.entity.Player) entityhuman.getBukkitEntity());
|
||||
+ entitysheep.level().getCraftServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+
|
||||
+ entitysheep.setColor(EnumColor.byId((byte) event.getColor().getWoolData()));
|
||||
+ // CraftBukkit end
|
||||
itemstack.shrink(1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
--- a/net/minecraft/world/item/ItemEgg.java
|
||||
+++ b/net/minecraft/world/item/ItemEgg.java
|
||||
@@ -25,10 +25,18 @@
|
||||
public EnumInteractionResult use(World world, EntityHuman entityhuman, EnumHand enumhand) {
|
||||
ItemStack itemstack = entityhuman.getItemInHand(enumhand);
|
||||
|
||||
- world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
+ // world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); // CraftBukkit - moved down
|
||||
if (world instanceof WorldServer worldserver) {
|
||||
- IProjectile.spawnProjectileFromRotation(EntityEgg::new, worldserver, itemstack, entityhuman, 0.0F, ItemEgg.PROJECTILE_SHOOT_POWER, 1.0F);
|
||||
+ // CraftBukkit start
|
||||
+ if (IProjectile.spawnProjectileFromRotation(EntityEgg::new, worldserver, itemstack, entityhuman, 0.0F, ItemEgg.PROJECTILE_SHOOT_POWER, 1.0F).isRemoved()) {
|
||||
+ if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) {
|
||||
+ ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
|
||||
+ }
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
+ world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
|
||||
entityhuman.awardStat(StatisticList.ITEM_USED.get(this));
|
||||
itemstack.consume(1, entityhuman);
|
||||
@@ -0,0 +1,14 @@
|
||||
--- a/net/minecraft/world/item/ItemEndCrystal.java
|
||||
+++ b/net/minecraft/world/item/ItemEndCrystal.java
|
||||
@@ -47,6 +47,11 @@
|
||||
EntityEnderCrystal entityendercrystal = new EntityEnderCrystal(world, d0 + 0.5D, d1, d2 + 0.5D);
|
||||
|
||||
entityendercrystal.setShowBottom(false);
|
||||
+ // CraftBukkit start
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(itemactioncontext, entityendercrystal).isCancelled()) {
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
world.addFreshEntity(entityendercrystal);
|
||||
world.gameEvent((Entity) itemactioncontext.getPlayer(), (Holder) GameEvent.ENTITY_PLACE, blockposition1);
|
||||
EnderDragonBattle enderdragonbattle = ((WorldServer) world).getDragonFight();
|
||||
@@ -0,0 +1,15 @@
|
||||
--- a/net/minecraft/world/item/ItemEnderEye.java
|
||||
+++ b/net/minecraft/world/item/ItemEnderEye.java
|
||||
@@ -99,7 +99,11 @@
|
||||
entityendersignal.setItem(itemstack);
|
||||
entityendersignal.signalTo(blockposition);
|
||||
world.gameEvent((Holder) GameEvent.PROJECTILE_SHOOT, entityendersignal.position(), GameEvent.a.of((Entity) entityhuman));
|
||||
- world.addFreshEntity(entityendersignal);
|
||||
+ // CraftBukkit start
|
||||
+ if (!world.addFreshEntity(entityendersignal)) {
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
if (entityhuman instanceof EntityPlayer) {
|
||||
EntityPlayer entityplayer = (EntityPlayer) entityhuman;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
--- a/net/minecraft/world/item/ItemEnderPearl.java
|
||||
+++ b/net/minecraft/world/item/ItemEnderPearl.java
|
||||
@@ -23,10 +23,17 @@
|
||||
public EnumInteractionResult use(World world, EntityHuman entityhuman, EnumHand enumhand) {
|
||||
ItemStack itemstack = entityhuman.getItemInHand(enumhand);
|
||||
|
||||
- world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
if (world instanceof WorldServer worldserver) {
|
||||
- IProjectile.spawnProjectileFromRotation(EntityEnderPearl::new, worldserver, itemstack, entityhuman, 0.0F, ItemEnderPearl.PROJECTILE_SHOOT_POWER, 1.0F);
|
||||
+ // CraftBukkit start
|
||||
+ if (IProjectile.spawnProjectileFromRotation(EntityEnderPearl::new, worldserver, itemstack, entityhuman, 0.0F, ItemEnderPearl.PROJECTILE_SHOOT_POWER, 1.0F).isRemoved()) {
|
||||
+ if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) {
|
||||
+ ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
|
||||
+ }
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
}
|
||||
+ world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
+ // CraftBukkit end
|
||||
|
||||
entityhuman.awardStat(StatisticList.ITEM_USED.get(this));
|
||||
itemstack.consume(1, entityhuman);
|
||||
@@ -0,0 +1,31 @@
|
||||
--- a/net/minecraft/world/item/ItemFireball.java
|
||||
+++ b/net/minecraft/world/item/ItemFireball.java
|
||||
@@ -40,12 +40,28 @@
|
||||
if (!BlockCampfire.canLight(iblockdata) && !CandleBlock.canLight(iblockdata) && !CandleCakeBlock.canLight(iblockdata)) {
|
||||
blockposition = blockposition.relative(itemactioncontext.getClickedFace());
|
||||
if (BlockFireAbstract.canBePlacedAt(world, blockposition, itemactioncontext.getHorizontalDirection())) {
|
||||
+ // CraftBukkit start - fire BlockIgniteEvent
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FIREBALL, itemactioncontext.getPlayer()).isCancelled()) {
|
||||
+ if (!itemactioncontext.getPlayer().getAbilities().instabuild) {
|
||||
+ itemactioncontext.getItemInHand().shrink(1);
|
||||
+ }
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
this.playSound(world, blockposition);
|
||||
world.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(world, blockposition));
|
||||
world.gameEvent((Entity) itemactioncontext.getPlayer(), (Holder) GameEvent.BLOCK_PLACE, blockposition);
|
||||
flag = true;
|
||||
}
|
||||
} else {
|
||||
+ // CraftBukkit start - fire BlockIgniteEvent
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FIREBALL, itemactioncontext.getPlayer()).isCancelled()) {
|
||||
+ if (!itemactioncontext.getPlayer().getAbilities().instabuild) {
|
||||
+ itemactioncontext.getItemInHand().shrink(1);
|
||||
+ }
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
this.playSound(world, blockposition);
|
||||
world.setBlockAndUpdate(blockposition, (IBlockData) iblockdata.setValue(BlockProperties.LIT, true));
|
||||
world.gameEvent((Entity) itemactioncontext.getPlayer(), (Holder) GameEvent.BLOCK_CHANGE, blockposition);
|
||||
@@ -0,0 +1,41 @@
|
||||
--- a/net/minecraft/world/item/ItemFishingRod.java
|
||||
+++ b/net/minecraft/world/item/ItemFishingRod.java
|
||||
@@ -14,6 +14,11 @@
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.event.player.PlayerFishEvent;
|
||||
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ItemFishingRod extends Item {
|
||||
|
||||
public ItemFishingRod(Item.Info item_info) {
|
||||
@@ -34,13 +39,24 @@
|
||||
world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.FISHING_BOBBER_RETRIEVE, SoundCategory.NEUTRAL, 1.0F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
entityhuman.gameEvent(GameEvent.ITEM_INTERACT_FINISH);
|
||||
} else {
|
||||
- world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.FISHING_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
+ // world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.FISHING_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
if (world instanceof WorldServer) {
|
||||
WorldServer worldserver = (WorldServer) world;
|
||||
int j = (int) (EnchantmentManager.getFishingTimeReduction(worldserver, itemstack, entityhuman) * 20.0F);
|
||||
int k = EnchantmentManager.getFishingLuckBonus(worldserver, itemstack, entityhuman);
|
||||
|
||||
- IProjectile.spawnProjectile(new EntityFishingHook(entityhuman, world, k, j), worldserver, itemstack);
|
||||
+ // CraftBukkit start
|
||||
+ EntityFishingHook entityfishinghook = new EntityFishingHook(entityhuman, world, k, j);
|
||||
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), null, (org.bukkit.entity.FishHook) entityfishinghook.getBukkitEntity(), CraftEquipmentSlot.getHand(enumhand), PlayerFishEvent.State.FISHING);
|
||||
+ world.getCraftServer().getPluginManager().callEvent(playerFishEvent);
|
||||
+
|
||||
+ if (playerFishEvent.isCancelled()) {
|
||||
+ entityhuman.fishing = null;
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+ world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.FISHING_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
+ IProjectile.spawnProjectile(entityfishinghook, worldserver, itemstack);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
entityhuman.awardStat(StatisticList.ITEM_USED.get(this));
|
||||
@@ -0,0 +1,28 @@
|
||||
--- a/net/minecraft/world/item/ItemFlintAndSteel.java
|
||||
+++ b/net/minecraft/world/item/ItemFlintAndSteel.java
|
||||
@@ -37,6 +37,12 @@
|
||||
BlockPosition blockposition1 = blockposition.relative(itemactioncontext.getClickedFace());
|
||||
|
||||
if (BlockFireAbstract.canBePlacedAt(world, blockposition1, itemactioncontext.getHorizontalDirection())) {
|
||||
+ // CraftBukkit start - Store the clicked block
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition1, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, entityhuman).isCancelled()) {
|
||||
+ itemactioncontext.getItemInHand().hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(itemactioncontext.getHand()));
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
world.playSound(entityhuman, blockposition1, SoundEffects.FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, world.getRandom().nextFloat() * 0.4F + 0.8F);
|
||||
IBlockData iblockdata1 = BlockFireAbstract.getState(world, blockposition1);
|
||||
|
||||
@@ -54,6 +60,12 @@
|
||||
return EnumInteractionResult.FAIL;
|
||||
}
|
||||
} else {
|
||||
+ // CraftBukkit start - Store the clicked block
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, entityhuman).isCancelled()) {
|
||||
+ itemactioncontext.getItemInHand().hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(itemactioncontext.getHand()));
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
world.playSound(entityhuman, blockposition, SoundEffects.FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, world.getRandom().nextFloat() * 0.4F + 0.8F);
|
||||
world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockProperties.LIT, true), 11);
|
||||
world.gameEvent((Entity) entityhuman, (Holder) GameEvent.BLOCK_CHANGE, blockposition);
|
||||
@@ -0,0 +1,43 @@
|
||||
--- a/net/minecraft/world/item/ItemHanging.java
|
||||
+++ b/net/minecraft/world/item/ItemHanging.java
|
||||
@@ -25,6 +25,11 @@
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ItemHanging extends Item {
|
||||
|
||||
private static final IChatBaseComponent TOOLTIP_RANDOM_VARIANT = IChatBaseComponent.translatable("painting.random").withStyle(EnumChatFormat.GRAY);
|
||||
@@ -75,6 +80,19 @@
|
||||
|
||||
if (((EntityHanging) object).survives()) {
|
||||
if (!world.isClientSide) {
|
||||
+ // CraftBukkit start - fire HangingPlaceEvent
|
||||
+ Player who = (itemactioncontext.getPlayer() == null) ? null : (Player) itemactioncontext.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(itemactioncontext.getHand());
|
||||
+
|
||||
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) ((EntityHanging) object).getBukkitEntity(), who, blockClicked, blockFace, hand, org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack));
|
||||
+ world.getCraftServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
((EntityHanging) object).playPlacementSound();
|
||||
world.gameEvent((Entity) entityhuman, (Holder) GameEvent.ENTITY_PLACE, ((EntityHanging) object).position());
|
||||
world.addFreshEntity((Entity) object);
|
||||
@@ -102,7 +120,7 @@
|
||||
|
||||
if (!customdata.isEmpty()) {
|
||||
customdata.read(holderlookup_a.createSerializationContext(DynamicOpsNBT.INSTANCE), EntityPainting.VARIANT_MAP_CODEC).result().ifPresentOrElse((holder) -> {
|
||||
- Optional optional = ((PaintingVariant) holder.value()).title();
|
||||
+ Optional<IChatBaseComponent> optional = ((PaintingVariant) holder.value()).title(); // CraftBukkit - decompile error
|
||||
|
||||
Objects.requireNonNull(list);
|
||||
optional.ifPresent(list::add);
|
||||
@@ -0,0 +1,89 @@
|
||||
--- a/net/minecraft/world/item/ItemLeash.java
|
||||
+++ b/net/minecraft/world/item/ItemLeash.java
|
||||
@@ -19,6 +19,12 @@
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.phys.AxisAlignedBB;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
+import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
+import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ItemLeash extends Item {
|
||||
|
||||
public ItemLeash(Item.Info item_info) {
|
||||
@@ -35,14 +41,14 @@
|
||||
EntityHuman entityhuman = itemactioncontext.getPlayer();
|
||||
|
||||
if (!world.isClientSide && entityhuman != null) {
|
||||
- return bindPlayerMobs(entityhuman, world, blockposition);
|
||||
+ return bindPlayerMobs(entityhuman, world, blockposition, itemactioncontext.getHand()); // CraftBukkit - Pass hand
|
||||
}
|
||||
}
|
||||
|
||||
return EnumInteractionResult.PASS;
|
||||
}
|
||||
|
||||
- public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) {
|
||||
+ public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition, net.minecraft.world.EnumHand enumhand) { // CraftBukkit - Add EnumHand
|
||||
EntityLeash entityleash = null;
|
||||
List<Leashable> list = leashableInArea(world, blockposition, (leashable) -> {
|
||||
return leashable.getLeashHolder() == entityhuman;
|
||||
@@ -50,22 +56,55 @@
|
||||
|
||||
Leashable leashable;
|
||||
|
||||
- for (Iterator iterator = list.iterator(); iterator.hasNext(); leashable.setLeashedTo(entityleash, true)) {
|
||||
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) { // CraftBukkit - handle setLeashedTo at end of loop
|
||||
leashable = (Leashable) iterator.next();
|
||||
if (entityleash == null) {
|
||||
entityleash = EntityLeash.getOrCreateKnot(world, blockposition);
|
||||
+
|
||||
+ // CraftBukkit start - fire HangingPlaceEvent
|
||||
+ org.bukkit.inventory.EquipmentSlot hand = CraftEquipmentSlot.getHand(enumhand);
|
||||
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, CraftBlock.at(world, blockposition), org.bukkit.block.BlockFace.SELF, hand);
|
||||
+ world.getCraftServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ entityleash.discard(null); // CraftBukkit - add Bukkit remove cause
|
||||
+ return EnumInteractionResult.PASS;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
entityleash.playPlacementSound();
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ if (leashable instanceof Entity leashed) {
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(leashed, entityleash, entityhuman, enumhand).isCancelled()) {
|
||||
+ iterator.remove();
|
||||
+ continue;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ leashable.setLeashedTo(entityleash, true);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
world.gameEvent((Holder) GameEvent.BLOCK_ATTACH, blockposition, GameEvent.a.of((Entity) entityhuman));
|
||||
return EnumInteractionResult.SUCCESS_SERVER;
|
||||
} else {
|
||||
+ // CraftBukkit start- remove leash if we do not leash any entity because of the cancelled event
|
||||
+ if (entityleash != null) {
|
||||
+ entityleash.discard(null);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
return EnumInteractionResult.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) {
|
||||
+ return bindPlayerMobs(entityhuman, world, blockposition, net.minecraft.world.EnumHand.MAIN_HAND);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public static List<Leashable> leashableInArea(World world, BlockPosition blockposition, Predicate<Leashable> predicate) {
|
||||
double d0 = 7.0D;
|
||||
int i = blockposition.getX();
|
||||
@@ -0,0 +1,16 @@
|
||||
--- a/net/minecraft/world/item/ItemMinecart.java
|
||||
+++ b/net/minecraft/world/item/ItemMinecart.java
|
||||
@@ -67,7 +67,12 @@
|
||||
if (world instanceof WorldServer) {
|
||||
WorldServer worldserver = (WorldServer) world;
|
||||
|
||||
- worldserver.addFreshEntity(entityminecartabstract);
|
||||
+ // CraftBukkit start
|
||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(itemactioncontext, entityminecartabstract).isCancelled()) {
|
||||
+ return EnumInteractionResult.FAIL;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+ if (!worldserver.addFreshEntity(entityminecartabstract)) return EnumInteractionResult.PASS; // CraftBukkit
|
||||
worldserver.gameEvent((Holder) GameEvent.ENTITY_PLACE, blockposition, GameEvent.a.of(itemactioncontext.getPlayer(), worldserver.getBlockState(blockposition.below())));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
--- a/net/minecraft/world/item/ItemMonsterEgg.java
|
||||
+++ b/net/minecraft/world/item/ItemMonsterEgg.java
|
||||
@@ -176,10 +176,10 @@
|
||||
return Optional.empty();
|
||||
} else {
|
||||
((EntityInsentient) object).moveTo(vec3d.x(), vec3d.y(), vec3d.z(), 0.0F, 0.0F);
|
||||
- worldserver.addFreshEntityWithPassengers((Entity) object);
|
||||
+ worldserver.addFreshEntityWithPassengers((Entity) object, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); // CraftBukkit
|
||||
((EntityInsentient) object).setCustomName((IChatBaseComponent) itemstack.get(DataComponents.CUSTOM_NAME));
|
||||
itemstack.consume(1, entityhuman);
|
||||
- return Optional.of(object);
|
||||
+ return Optional.of((EntityInsentient) object); // CraftBukkit - decompile error
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
--- a/net/minecraft/world/item/ItemProjectileWeapon.java
|
||||
+++ b/net/minecraft/world/item/ItemProjectileWeapon.java
|
||||
@@ -54,9 +54,25 @@
|
||||
float f6 = f4 + f5 * (float) ((i + 1) / 2) * f3;
|
||||
|
||||
f5 = -f5;
|
||||
- IProjectile.spawnProjectile(this.createProjectile(worldserver, entityliving, itemstack, itemstack1, flag), worldserver, itemstack1, (iprojectile) -> {
|
||||
- this.shootProjectile(entityliving, iprojectile, i, f, f1, f6, entityliving1);
|
||||
- });
|
||||
+ // CraftBukkit start
|
||||
+ IProjectile iprojectile = this.createProjectile(worldserver, entityliving, itemstack, itemstack1, flag);
|
||||
+ this.shootProjectile(entityliving, iprojectile, i, f, f1, f6, entityliving1);
|
||||
+
|
||||
+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityliving, itemstack, itemstack1, iprojectile, enumhand, f, true);
|
||||
+ if (event.isCancelled()) {
|
||||
+ event.getProjectile().remove();
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ if (event.getProjectile() == iprojectile.getBukkitEntity()) {
|
||||
+ if (IProjectile.spawnProjectile(iprojectile, worldserver, itemstack1).isRemoved()) {
|
||||
+ if (entityliving instanceof net.minecraft.server.level.EntityPlayer) {
|
||||
+ ((net.minecraft.server.level.EntityPlayer) entityliving).getBukkitEntity().updateInventory();
|
||||
+ }
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
itemstack.hurtAndBreak(this.getDurabilityUse(itemstack1), entityliving, EntityLiving.getSlotForHand(enumhand));
|
||||
if (itemstack.isEmpty()) {
|
||||
break;
|
||||
@@ -0,0 +1,23 @@
|
||||
--- a/net/minecraft/world/item/ItemSign.java
|
||||
+++ b/net/minecraft/world/item/ItemSign.java
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
public class ItemSign extends ItemBlockWallable {
|
||||
|
||||
+ public static BlockPosition openSign; // CraftBukkit
|
||||
+
|
||||
public ItemSign(Block block, Block block1, Item.Info item_info) {
|
||||
super(block, block1, EnumDirection.DOWN, item_info);
|
||||
}
|
||||
@@ -35,7 +37,10 @@
|
||||
if (block instanceof BlockSign) {
|
||||
BlockSign blocksign = (BlockSign) block;
|
||||
|
||||
- blocksign.openTextEdit(entityhuman, tileentitysign, true);
|
||||
+ // CraftBukkit start - SPIGOT-4678
|
||||
+ // blocksign.openTextEdit(entityhuman, tileentitysign, true);
|
||||
+ ItemSign.openSign = blockposition;
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
--- a/net/minecraft/world/item/ItemSnowball.java
|
||||
+++ b/net/minecraft/world/item/ItemSnowball.java
|
||||
@@ -25,13 +25,21 @@
|
||||
public EnumInteractionResult use(World world, EntityHuman entityhuman, EnumHand enumhand) {
|
||||
ItemStack itemstack = entityhuman.getItemInHand(enumhand);
|
||||
|
||||
- world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
+ // CraftBukkit start - moved down
|
||||
+ // world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
if (world instanceof WorldServer worldserver) {
|
||||
- IProjectile.spawnProjectileFromRotation(EntitySnowball::new, worldserver, itemstack, entityhuman, 0.0F, ItemSnowball.PROJECTILE_SHOOT_POWER, 1.0F);
|
||||
+ if (IProjectile.spawnProjectileFromRotation(EntitySnowball::new, worldserver, itemstack, entityhuman, 0.0F, ItemSnowball.PROJECTILE_SHOOT_POWER, 1.0F).isAlive()) {
|
||||
+ itemstack.consume(1, entityhuman);
|
||||
+
|
||||
+ world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||
+ } else if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) {
|
||||
+ ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
entityhuman.awardStat(StatisticList.ITEM_USED.get(this));
|
||||
- itemstack.consume(1, entityhuman);
|
||||
+ // itemstack.consume(1, entityhuman); // CraftBukkit - moved up
|
||||
return EnumInteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,362 @@
|
||||
--- a/net/minecraft/world/item/ItemStack.java
|
||||
+++ b/net/minecraft/world/item/ItemStack.java
|
||||
@@ -96,18 +96,52 @@
|
||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import java.util.Map;
|
||||
+import java.util.Objects;
|
||||
+import net.minecraft.core.EnumDirection;
|
||||
+import net.minecraft.nbt.DynamicOpsNBT;
|
||||
+import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
|
||||
+import net.minecraft.server.level.WorldServer;
|
||||
+import net.minecraft.sounds.SoundCategory;
|
||||
+import net.minecraft.world.level.block.BlockBed;
|
||||
+import net.minecraft.world.level.block.Blocks;
|
||||
+import net.minecraft.world.level.block.BlockSapling;
|
||||
+import net.minecraft.world.level.block.BlockSign;
|
||||
+import net.minecraft.world.level.block.BlockTileEntity;
|
||||
+import net.minecraft.world.level.block.BlockWitherSkull;
|
||||
+import net.minecraft.world.level.block.SoundEffectType;
|
||||
+import net.minecraft.world.level.block.entity.TileEntity;
|
||||
+import net.minecraft.world.level.block.entity.TileEntityJukeBox;
|
||||
+import net.minecraft.world.level.block.entity.TileEntitySign;
|
||||
+import net.minecraft.world.level.block.entity.TileEntitySkull;
|
||||
+import net.minecraft.world.level.gameevent.GameEvent;
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.TreeType;
|
||||
+import org.bukkit.block.BlockState;
|
||||
+import org.bukkit.craftbukkit.block.CapturedBlockState;
|
||||
+import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
+import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.util.CraftLocation;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.block.BlockFertilizeEvent;
|
||||
+import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
+import org.bukkit.event.world.StructureGrowEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public final class ItemStack implements DataComponentHolder {
|
||||
|
||||
private static final List<IChatBaseComponent> OP_NBT_WARNING = List.of(IChatBaseComponent.translatable("item.op_warning.line1").withStyle(EnumChatFormat.RED, EnumChatFormat.BOLD), IChatBaseComponent.translatable("item.op_warning.line2").withStyle(EnumChatFormat.RED), IChatBaseComponent.translatable("item.op_warning.line3").withStyle(EnumChatFormat.RED));
|
||||
public static final Codec<ItemStack> CODEC = Codec.lazyInitialized(() -> {
|
||||
- return RecordCodecBuilder.create((instance) -> {
|
||||
+ return RecordCodecBuilder.<ItemStack>create((instance) -> { // CraftBukkit - decompile error
|
||||
return instance.group(Item.CODEC.fieldOf("id").forGetter(ItemStack::getItemHolder), ExtraCodecs.intRange(1, 99).fieldOf("count").orElse(1).forGetter(ItemStack::getCount), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> {
|
||||
return itemstack.components.asPatch();
|
||||
})).apply(instance, ItemStack::new);
|
||||
});
|
||||
});
|
||||
public static final Codec<ItemStack> SINGLE_ITEM_CODEC = Codec.lazyInitialized(() -> {
|
||||
- return RecordCodecBuilder.create((instance) -> {
|
||||
+ return RecordCodecBuilder.<ItemStack>create((instance) -> { // CraftBukkit - decompile error
|
||||
return instance.group(Item.CODEC.fieldOf("id").forGetter(ItemStack::getItemHolder), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> {
|
||||
return itemstack.components.asPatch();
|
||||
})).apply(instance, (holder, datacomponentpatch) -> {
|
||||
@@ -132,19 +166,25 @@
|
||||
if (i <= 0) {
|
||||
return ItemStack.EMPTY;
|
||||
} else {
|
||||
- Holder<Item> holder = (Holder) null.ITEM_STREAM_CODEC.decode(registryfriendlybytebuf);
|
||||
+ Holder<Item> holder = (Holder) ITEM_STREAM_CODEC.decode(registryfriendlybytebuf); // CraftBukkit - decompile error
|
||||
DataComponentPatch datacomponentpatch = (DataComponentPatch) DataComponentPatch.STREAM_CODEC.decode(registryfriendlybytebuf);
|
||||
|
||||
- return new ItemStack(holder, i, datacomponentpatch);
|
||||
+ // CraftBukkit start
|
||||
+ ItemStack itemstack = new ItemStack(holder, i, datacomponentpatch);
|
||||
+ if (!datacomponentpatch.isEmpty()) {
|
||||
+ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
|
||||
+ }
|
||||
+ return itemstack;
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
public void encode(RegistryFriendlyByteBuf registryfriendlybytebuf, ItemStack itemstack) {
|
||||
- if (itemstack.isEmpty()) {
|
||||
+ if (itemstack.isEmpty() || itemstack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem()
|
||||
registryfriendlybytebuf.writeVarInt(0);
|
||||
} else {
|
||||
registryfriendlybytebuf.writeVarInt(itemstack.getCount());
|
||||
- null.ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder());
|
||||
+ ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder()); // CraftBukkit - decompile error
|
||||
DataComponentPatch.STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.components.asPatch());
|
||||
}
|
||||
}
|
||||
@@ -187,7 +227,7 @@
|
||||
|
||||
return dataresult.isError() ? dataresult.map((unit) -> {
|
||||
return itemstack;
|
||||
- }) : (itemstack.getCount() > itemstack.getMaxStackSize() ? DataResult.error(() -> {
|
||||
+ }) : (itemstack.getCount() > itemstack.getMaxStackSize() ? DataResult.<ItemStack>error(() -> { // CraftBukkit - decompile error
|
||||
int i = itemstack.getCount();
|
||||
|
||||
return "Item stack with stack size of " + i + " was larger than maximum: " + itemstack.getMaxStackSize();
|
||||
@@ -294,8 +334,9 @@
|
||||
j = itemstack.getMaxStackSize();
|
||||
} while (i <= j);
|
||||
|
||||
+ int finalI = i, finalJ = j; // CraftBukkit - decompile error
|
||||
return DataResult.error(() -> {
|
||||
- return "Item stack with count of " + i + " was larger than maximum: " + j;
|
||||
+ return "Item stack with count of " + finalI + " was larger than maximum: " + finalJ; // CraftBukkit - decompile error
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -377,15 +418,173 @@
|
||||
return EnumInteractionResult.PASS;
|
||||
} else {
|
||||
Item item = this.getItem();
|
||||
- EnumInteractionResult enuminteractionresult = item.useOn(itemactioncontext);
|
||||
+ // CraftBukkit start - handle all block place event logic here
|
||||
+ DataComponentPatch oldData = this.components.asPatch();
|
||||
+ int oldCount = this.getCount();
|
||||
+ WorldServer world = (WorldServer) itemactioncontext.getLevel();
|
||||
+
|
||||
+ if (!(item instanceof ItemBucket || item instanceof SolidBucketItem)) { // if not bucket
|
||||
+ world.captureBlockStates = true;
|
||||
+ // special case bonemeal
|
||||
+ if (item == Items.BONE_MEAL) {
|
||||
+ world.captureTreeGeneration = true;
|
||||
+ }
|
||||
+ }
|
||||
+ EnumInteractionResult enuminteractionresult;
|
||||
+ try {
|
||||
+ enuminteractionresult = item.useOn(itemactioncontext);
|
||||
+ } finally {
|
||||
+ world.captureBlockStates = false;
|
||||
+ }
|
||||
+ DataComponentPatch newData = this.components.asPatch();
|
||||
+ int newCount = this.getCount();
|
||||
+ this.setCount(oldCount);
|
||||
+ this.restorePatch(oldData);
|
||||
+ if (enuminteractionresult.consumesAction() && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) {
|
||||
+ world.captureTreeGeneration = false;
|
||||
+ Location location = CraftLocation.toBukkit(blockposition, world.getWorld());
|
||||
+ TreeType treeType = BlockSapling.treeType;
|
||||
+ BlockSapling.treeType = null;
|
||||
+ List<CraftBlockState> blocks = new java.util.ArrayList<>(world.capturedBlockStates.values());
|
||||
+ world.capturedBlockStates.clear();
|
||||
+ StructureGrowEvent structureEvent = null;
|
||||
+ if (treeType != null) {
|
||||
+ boolean isBonemeal = getItem() == Items.BONE_MEAL;
|
||||
+ structureEvent = new StructureGrowEvent(location, treeType, isBonemeal, (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
|
||||
+ org.bukkit.Bukkit.getPluginManager().callEvent(structureEvent);
|
||||
+ }
|
||||
+
|
||||
+ BlockFertilizeEvent fertilizeEvent = new BlockFertilizeEvent(CraftBlock.at(world, blockposition), (Player) entityhuman.getBukkitEntity(), (List< BlockState>) (List<? extends BlockState>) blocks);
|
||||
+ fertilizeEvent.setCancelled(structureEvent != null && structureEvent.isCancelled());
|
||||
+ org.bukkit.Bukkit.getPluginManager().callEvent(fertilizeEvent);
|
||||
+
|
||||
+ if (!fertilizeEvent.isCancelled()) {
|
||||
+ // Change the stack to its new contents if it hasn't been tampered with.
|
||||
+ if (this.getCount() == oldCount && Objects.equals(this.components.asPatch(), oldData)) {
|
||||
+ this.restorePatch(newData);
|
||||
+ this.setCount(newCount);
|
||||
+ }
|
||||
+ for (CraftBlockState blockstate : blocks) {
|
||||
+ // SPIGOT-7572 - Move fix for SPIGOT-7248 to CapturedBlockState, to allow bees in bee nest
|
||||
+ CapturedBlockState.setBlockState(blockstate);
|
||||
+ }
|
||||
+ entityhuman.awardStat(StatisticList.ITEM_USED.get(item)); // SPIGOT-7236 - award stat
|
||||
+ }
|
||||
+
|
||||
+ ItemSign.openSign = null; // SPIGOT-6758 - Reset on early return
|
||||
+ return enuminteractionresult;
|
||||
+ }
|
||||
+ world.captureTreeGeneration = false;
|
||||
|
||||
if (entityhuman != null && enuminteractionresult instanceof EnumInteractionResult.d) {
|
||||
EnumInteractionResult.d enuminteractionresult_d = (EnumInteractionResult.d) enuminteractionresult;
|
||||
|
||||
if (enuminteractionresult_d.wasItemInteraction()) {
|
||||
- entityhuman.awardStat(StatisticList.ITEM_USED.get(item));
|
||||
+ EnumHand enumhand = itemactioncontext.getHand();
|
||||
+ org.bukkit.event.block.BlockPlaceEvent placeEvent = null;
|
||||
+ List<BlockState> blocks = new java.util.ArrayList<>(world.capturedBlockStates.values());
|
||||
+ world.capturedBlockStates.clear();
|
||||
+ if (blocks.size() > 1) {
|
||||
+ placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockMultiPlaceEvent(world, entityhuman, enumhand, blocks, blockposition.getX(), blockposition.getY(), blockposition.getZ());
|
||||
+ } else if (blocks.size() == 1) {
|
||||
+ placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(world, entityhuman, enumhand, blocks.get(0), blockposition.getX(), blockposition.getY(), blockposition.getZ());
|
||||
+ }
|
||||
+
|
||||
+ if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) {
|
||||
+ enuminteractionresult = EnumInteractionResult.FAIL; // cancel placement
|
||||
+ // PAIL: Remove this when MC-99075 fixed
|
||||
+ placeEvent.getPlayer().updateInventory();
|
||||
+ // revert back all captured blocks
|
||||
+ world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710
|
||||
+ for (BlockState blockstate : blocks) {
|
||||
+ blockstate.update(true, false);
|
||||
+ }
|
||||
+ world.preventPoiUpdated = false;
|
||||
+
|
||||
+ // Brute force all possible updates
|
||||
+ BlockPosition placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition();
|
||||
+ for (EnumDirection dir : EnumDirection.values()) {
|
||||
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, placedPos.relative(dir)));
|
||||
+ }
|
||||
+ ItemSign.openSign = null; // SPIGOT-6758 - Reset on early return
|
||||
+ } else {
|
||||
+ // Change the stack to its new contents if it hasn't been tampered with.
|
||||
+ if (this.getCount() == oldCount && Objects.equals(this.components.asPatch(), oldData)) {
|
||||
+ this.restorePatch(newData);
|
||||
+ this.setCount(newCount);
|
||||
+ }
|
||||
+
|
||||
+ for (Map.Entry<BlockPosition, TileEntity> e : world.capturedTileEntities.entrySet()) {
|
||||
+ world.setBlockEntity(e.getValue());
|
||||
+ }
|
||||
+
|
||||
+ for (BlockState blockstate : blocks) {
|
||||
+ int updateFlag = ((CraftBlockState) blockstate).getFlag();
|
||||
+ IBlockData oldBlock = ((CraftBlockState) blockstate).getHandle();
|
||||
+ BlockPosition newblockposition = ((CraftBlockState) blockstate).getPosition();
|
||||
+ IBlockData block = world.getBlockState(newblockposition);
|
||||
+
|
||||
+ if (!(block.getBlock() instanceof BlockTileEntity)) { // Containers get placed automatically
|
||||
+ block.onPlace(world, newblockposition, oldBlock, true, itemactioncontext);
|
||||
+ }
|
||||
+
|
||||
+ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getBlockState(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point
|
||||
+ }
|
||||
+
|
||||
+ if (this.item == Items.WITHER_SKELETON_SKULL) { // Special case skulls to allow wither spawns to be cancelled
|
||||
+ BlockPosition bp = blockposition;
|
||||
+ if (!world.getBlockState(blockposition).canBeReplaced()) {
|
||||
+ if (!world.getBlockState(blockposition).isSolid()) {
|
||||
+ bp = null;
|
||||
+ } else {
|
||||
+ bp = bp.relative(itemactioncontext.getClickedFace());
|
||||
+ }
|
||||
+ }
|
||||
+ if (bp != null) {
|
||||
+ TileEntity te = world.getBlockEntity(bp);
|
||||
+ if (te instanceof TileEntitySkull) {
|
||||
+ BlockWitherSkull.checkSpawn(world, bp, (TileEntitySkull) te);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // SPIGOT-4678
|
||||
+ if (this.item instanceof ItemSign && ItemSign.openSign != null) {
|
||||
+ try {
|
||||
+ if (world.getBlockEntity(ItemSign.openSign) instanceof TileEntitySign tileentitysign) {
|
||||
+ if (world.getBlockState(ItemSign.openSign).getBlock() instanceof BlockSign blocksign) {
|
||||
+ blocksign.openTextEdit(entityhuman, tileentitysign, true, org.bukkit.event.player.PlayerSignOpenEvent.Cause.PLACE); // Craftbukkit
|
||||
+ }
|
||||
+ }
|
||||
+ } finally {
|
||||
+ ItemSign.openSign = null;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // SPIGOT-7315: Moved from BlockBed#setPlacedBy
|
||||
+ if (placeEvent != null && this.item instanceof ItemBed) {
|
||||
+ BlockPosition position = ((CraftBlock) placeEvent.getBlock()).getPosition();
|
||||
+ IBlockData blockData = world.getBlockState(position);
|
||||
+
|
||||
+ if (blockData.getBlock() instanceof BlockBed) {
|
||||
+ world.blockUpdated(position, Blocks.AIR);
|
||||
+ blockData.updateNeighbourShapes(world, position, 3);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // SPIGOT-1288 - play sound stripped from ItemBlock
|
||||
+ if (this.item instanceof ItemBlock) {
|
||||
+ SoundEffectType soundeffecttype = ((ItemBlock) this.item).getBlock().defaultBlockState().getSoundType(); // TODO: not strictly correct, however currently only affects decorated pots
|
||||
+ world.playSound(entityhuman, blockposition, soundeffecttype.getPlaceSound(), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F);
|
||||
+ }
|
||||
+
|
||||
+ entityhuman.awardStat(StatisticList.ITEM_USED.get(item));
|
||||
+ }
|
||||
}
|
||||
}
|
||||
+ world.capturedTileEntities.clear();
|
||||
+ world.capturedBlockStates.clear();
|
||||
+ // CraftBukkit end
|
||||
|
||||
return enuminteractionresult;
|
||||
}
|
||||
@@ -492,6 +691,21 @@
|
||||
|
||||
public void hurtAndBreak(int i, WorldServer worldserver, @Nullable EntityPlayer entityplayer, Consumer<Item> consumer) {
|
||||
int j = this.processDurabilityChange(i, worldserver, entityplayer);
|
||||
+ // CraftBukkit start
|
||||
+ if (entityplayer != null) {
|
||||
+ PlayerItemDamageEvent event = new PlayerItemDamageEvent(entityplayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j);
|
||||
+ event.getPlayer().getServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (j != event.getDamage() || event.isCancelled()) {
|
||||
+ event.getPlayer().updateInventory();
|
||||
+ }
|
||||
+ if (event.isCancelled()) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ j = event.getDamage();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
if (j != 0) {
|
||||
this.applyDamage(this.getDamageValue() + j, entityplayer, consumer);
|
||||
@@ -511,6 +725,11 @@
|
||||
this.setDamageValue(i);
|
||||
if (this.isBroken()) {
|
||||
Item item = this.getItem();
|
||||
+ // CraftBukkit start - Check for item breaking
|
||||
+ if (this.count == 1 && entityplayer != null) {
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent(entityplayer, this);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
this.shrink(1);
|
||||
consumer.accept(item);
|
||||
@@ -770,6 +989,12 @@
|
||||
return this.getItem().useOnRelease(this);
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public void restorePatch(DataComponentPatch datacomponentpatch) {
|
||||
+ this.components.restorePatch(datacomponentpatch);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
@Nullable
|
||||
public <T> T set(DataComponentType<? super T> datacomponenttype, @Nullable T t0) {
|
||||
return this.components.set(datacomponenttype, t0);
|
||||
@@ -858,7 +1083,7 @@
|
||||
}
|
||||
|
||||
private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> datacomponenttype, Item.b item_b, Consumer<IChatBaseComponent> consumer, TooltipFlag tooltipflag) {
|
||||
- T t0 = (TooltipProvider) this.get(datacomponenttype);
|
||||
+ T t0 = (T) this.get(datacomponenttype); // CraftBukkit - decompile error
|
||||
|
||||
if (t0 != null) {
|
||||
t0.addToTooltip(item_b, consumer, tooltipflag);
|
||||
@@ -1091,6 +1316,13 @@
|
||||
EnchantmentManager.forEachModifier(this, enumitemslot, biconsumer);
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @Deprecated
|
||||
+ public void setItem(Item item) {
|
||||
+ this.item = item;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public IChatBaseComponent getDisplayName() {
|
||||
IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.empty().append(this.getHoverName());
|
||||
|
||||
@@ -1153,7 +1385,7 @@
|
||||
}
|
||||
|
||||
public void consume(int i, @Nullable EntityLiving entityliving) {
|
||||
- if (entityliving == null || !entityliving.hasInfiniteMaterials()) {
|
||||
+ if ((entityliving == null || !entityliving.hasInfiniteMaterials()) && this != ItemStack.EMPTY) { // CraftBukkit
|
||||
this.shrink(i);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
--- a/net/minecraft/world/item/ItemTrident.java
|
||||
+++ b/net/minecraft/world/item/ItemTrident.java
|
||||
@@ -86,9 +86,19 @@
|
||||
if (world instanceof WorldServer) {
|
||||
WorldServer worldserver = (WorldServer) world;
|
||||
|
||||
- itemstack.hurtWithoutBreaking(1, entityhuman);
|
||||
+ // itemstack.hurtWithoutBreaking(1, entityhuman); // CraftBukkit - moved down
|
||||
if (f == 0.0F) {
|
||||
EntityThrownTrident entitythrowntrident = (EntityThrownTrident) IProjectile.spawnProjectileFromRotation(EntityThrownTrident::new, worldserver, itemstack, entityhuman, 0.0F, 2.5F, 1.0F);
|
||||
+ // CraftBukkit start
|
||||
+ if (entitythrowntrident.isRemoved()) {
|
||||
+ if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) {
|
||||
+ ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory();
|
||||
+ }
|
||||
+ return false;
|
||||
+ }
|
||||
+ itemstack.hurtWithoutBreaking(1, entityhuman);
|
||||
+ entitythrowntrident.pickupItemStack = itemstack.copy(); // SPIGOT-4511 update since damage call moved
|
||||
+ // CraftBukkit end
|
||||
|
||||
if (entityhuman.hasInfiniteMaterials()) {
|
||||
entitythrowntrident.pickup = EntityArrow.PickupStatus.CREATIVE_ONLY;
|
||||
@@ -98,6 +108,10 @@
|
||||
|
||||
world.playSound((EntityHuman) null, (Entity) entitythrowntrident, (SoundEffect) holder.value(), SoundCategory.PLAYERS, 1.0F, 1.0F);
|
||||
return true;
|
||||
+ // CraftBukkit start - SPIGOT-5458 also need in this branch :(
|
||||
+ } else {
|
||||
+ itemstack.hurtWithoutBreaking(1, entityhuman);
|
||||
+ // CraftBukkkit end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +126,7 @@
|
||||
f3 *= f / f6;
|
||||
f4 *= f / f6;
|
||||
f5 *= f / f6;
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerRiptideEvent(entityhuman, itemstack, f3, f4, f5); // CraftBukkit
|
||||
entityhuman.push((double) f3, (double) f4, (double) f5);
|
||||
entityhuman.startAutoSpinAttack(20, 8.0F, itemstack);
|
||||
if (entityhuman.onGround()) {
|
||||
@@ -0,0 +1,20 @@
|
||||
--- a/net/minecraft/world/item/alchemy/PotionContents.java
|
||||
+++ b/net/minecraft/world/item/alchemy/PotionContents.java
|
||||
@@ -93,7 +93,7 @@
|
||||
}
|
||||
|
||||
public PotionContents withEffectAdded(MobEffect mobeffect) {
|
||||
- return new PotionContents(this.potion, this.customColor, SystemUtils.copyAndAdd(this.customEffects, (Object) mobeffect), this.customName);
|
||||
+ return new PotionContents(this.potion, this.customColor, SystemUtils.copyAndAdd(this.customEffects, mobeffect), this.customName); // CraftBukkit - decompile error
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
@@ -172,7 +172,7 @@
|
||||
if (((MobEffectList) mobeffect.getEffect().value()).isInstantenous()) {
|
||||
((MobEffectList) mobeffect.getEffect().value()).applyInstantenousEffect(worldserver, entityhuman2, entityhuman2, entityliving, mobeffect.getAmplifier(), 1.0D);
|
||||
} else {
|
||||
- entityliving.addEffect(mobeffect);
|
||||
+ entityliving.addEffect(mobeffect, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_DRINK); // CraftBukkit
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
--- a/net/minecraft/world/item/component/Consumable.java
|
||||
+++ b/net/minecraft/world/item/component/Consumable.java
|
||||
@@ -29,6 +29,11 @@
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import net.minecraft.world.item.Items;
|
||||
+import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public record Consumable(float consumeSeconds, ItemUseAnimation animation, Holder<SoundEffect> sound, boolean hasConsumeParticles, List<ConsumeEffect> onConsumeEffects) {
|
||||
|
||||
public static final float DEFAULT_CONSUME_SECONDS = 1.6F;
|
||||
@@ -69,8 +74,19 @@
|
||||
consumablelistener.onConsume(world, entityliving, itemstack, this);
|
||||
});
|
||||
if (!world.isClientSide) {
|
||||
+ // CraftBukkit start
|
||||
+ EntityPotionEffectEvent.Cause cause;
|
||||
+ if (itemstack.is(Items.MILK_BUCKET)) {
|
||||
+ cause = EntityPotionEffectEvent.Cause.MILK;
|
||||
+ } else if (itemstack.is(Items.POTION)) {
|
||||
+ cause = EntityPotionEffectEvent.Cause.POTION_DRINK;
|
||||
+ } else {
|
||||
+ cause = EntityPotionEffectEvent.Cause.FOOD;
|
||||
+ }
|
||||
+
|
||||
this.onConsumeEffects.forEach((consumeeffect) -> {
|
||||
- consumeeffect.apply(world, itemstack, entityliving);
|
||||
+ consumeeffect.apply(world, itemstack, entityliving, cause);
|
||||
+ // CraftBukkit end
|
||||
});
|
||||
}
|
||||
|
||||
@@ -79,6 +95,15 @@
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public void cancelUsingItem(net.minecraft.server.level.EntityPlayer entityplayer, ItemStack itemstack) {
|
||||
+ itemstack.getAllOfType(ConsumableListener.class).forEach((consumablelistener) -> {
|
||||
+ consumablelistener.cancelUsingItem(entityplayer, itemstack);
|
||||
+ });
|
||||
+ entityplayer.server.getPlayerList().sendActivePlayerEffects(entityplayer);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public boolean canConsume(EntityLiving entityliving, ItemStack itemstack) {
|
||||
FoodInfo foodinfo = (FoodInfo) itemstack.get(DataComponents.FOOD);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
--- a/net/minecraft/world/item/component/ConsumableListener.java
|
||||
+++ b/net/minecraft/world/item/component/ConsumableListener.java
|
||||
@@ -7,4 +7,6 @@
|
||||
public interface ConsumableListener {
|
||||
|
||||
void onConsume(World world, EntityLiving entityliving, ItemStack itemstack, Consumable consumable);
|
||||
+
|
||||
+ default void cancelUsingItem(net.minecraft.server.level.EntityPlayer entityplayer, ItemStack itemstack) {} // CraftBukkit
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
--- a/net/minecraft/world/item/component/DeathProtection.java
|
||||
+++ b/net/minecraft/world/item/component/DeathProtection.java
|
||||
@@ -15,6 +15,10 @@
|
||||
import net.minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffect;
|
||||
import net.minecraft.world.item.consume_effects.ConsumeEffect;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public record DeathProtection(List<ConsumeEffect> deathEffects) {
|
||||
|
||||
public static final Codec<DeathProtection> CODEC = RecordCodecBuilder.create((instance) -> {
|
||||
@@ -29,7 +33,7 @@
|
||||
while (iterator.hasNext()) {
|
||||
ConsumeEffect consumeeffect = (ConsumeEffect) iterator.next();
|
||||
|
||||
- consumeeffect.apply(entityliving.level(), itemstack, entityliving);
|
||||
+ consumeeffect.apply(entityliving.level(), itemstack, entityliving, EntityPotionEffectEvent.Cause.TOTEM); // CraftBukkit
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
--- a/net/minecraft/world/item/component/SuspiciousStewEffects.java
|
||||
+++ b/net/minecraft/world/item/component/SuspiciousStewEffects.java
|
||||
@@ -29,7 +29,7 @@
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, SuspiciousStewEffects> STREAM_CODEC = SuspiciousStewEffects.a.STREAM_CODEC.apply(ByteBufCodecs.list()).map(SuspiciousStewEffects::new, SuspiciousStewEffects::effects);
|
||||
|
||||
public SuspiciousStewEffects withEffectAdded(SuspiciousStewEffects.a suspicioussteweffects_a) {
|
||||
- return new SuspiciousStewEffects(SystemUtils.copyAndAdd(this.effects, (Object) suspicioussteweffects_a));
|
||||
+ return new SuspiciousStewEffects(SystemUtils.copyAndAdd(this.effects, suspicioussteweffects_a)); // CraftBukkit - decompile error
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,6 +44,15 @@
|
||||
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public void cancelUsingItem(net.minecraft.server.level.EntityPlayer entityplayer, ItemStack itemstack) {
|
||||
+ for (SuspiciousStewEffects.a suspicioussteweffects_a : this.effects) {
|
||||
+ entityplayer.connection.send(new net.minecraft.network.protocol.game.PacketPlayOutRemoveEntityEffect(entityplayer.getId(), suspicioussteweffects_a.effect()));
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
@Override
|
||||
public void addToTooltip(Item.b item_b, Consumer<IChatBaseComponent> consumer, TooltipFlag tooltipflag) {
|
||||
if (tooltipflag.isCreative()) {
|
||||
@@ -0,0 +1,31 @@
|
||||
--- a/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.java
|
||||
+++ b/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.java
|
||||
@@ -13,6 +13,10 @@
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.World;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public record ApplyStatusEffectsConsumeEffect(List<MobEffect> effects, float probability) implements ConsumeEffect {
|
||||
|
||||
public static final MapCodec<ApplyStatusEffectsConsumeEffect> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
|
||||
@@ -38,7 +42,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving) {
|
||||
+ public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving, EntityPotionEffectEvent.Cause cause) { // CraftBukkit
|
||||
if (entityliving.getRandom().nextFloat() >= this.probability) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -48,7 +52,7 @@
|
||||
while (iterator.hasNext()) {
|
||||
MobEffect mobeffect = (MobEffect) iterator.next();
|
||||
|
||||
- if (entityliving.addEffect(new MobEffect(mobeffect))) {
|
||||
+ if (entityliving.addEffect(new MobEffect(mobeffect), cause)) { // CraftBukkit
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
--- a/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.java
|
||||
+++ b/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.java
|
||||
@@ -7,6 +7,10 @@
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.World;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public record ClearAllStatusEffectsConsumeEffect() implements ConsumeEffect {
|
||||
|
||||
public static final ClearAllStatusEffectsConsumeEffect INSTANCE = new ClearAllStatusEffectsConsumeEffect();
|
||||
@@ -19,7 +23,9 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving) {
|
||||
- return entityliving.removeAllEffects();
|
||||
+ // CraftBukkit start
|
||||
+ public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving, EntityPotionEffectEvent.Cause cause) {
|
||||
+ return entityliving.removeAllEffects(cause);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
--- a/net/minecraft/world/item/consume_effects/ConsumeEffect.java
|
||||
+++ b/net/minecraft/world/item/consume_effects/ConsumeEffect.java
|
||||
@@ -12,6 +12,10 @@
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.World;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public interface ConsumeEffect {
|
||||
|
||||
Codec<ConsumeEffect> CODEC = BuiltInRegistries.CONSUME_EFFECT_TYPE.byNameCodec().dispatch(ConsumeEffect::getType, ConsumeEffect.a::codec);
|
||||
@@ -19,7 +23,15 @@
|
||||
|
||||
ConsumeEffect.a<? extends ConsumeEffect> getType();
|
||||
|
||||
- boolean apply(World world, ItemStack itemstack, EntityLiving entityliving);
|
||||
+ // CraftBukkit start
|
||||
+ default boolean apply(World world, ItemStack itemstack, EntityLiving entityliving) {
|
||||
+ return this.apply(world, itemstack, entityliving, EntityPotionEffectEvent.Cause.UNKNOWN);
|
||||
+ }
|
||||
+
|
||||
+ default boolean apply(World world, ItemStack itemstack, EntityLiving entityliving, EntityPotionEffectEvent.Cause cause) {
|
||||
+ return this.apply(world, itemstack, entityliving);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
public static record a<T extends ConsumeEffect>(MapCodec<T> codec, StreamCodec<RegistryFriendlyByteBuf, T> streamCodec) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
--- a/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.java
|
||||
+++ b/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.java
|
||||
@@ -15,6 +15,10 @@
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.World;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public record RemoveStatusEffectsConsumeEffect(HolderSet<MobEffectList> effects) implements ConsumeEffect {
|
||||
|
||||
public static final MapCodec<RemoveStatusEffectsConsumeEffect> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
|
||||
@@ -32,14 +36,14 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving) {
|
||||
+ public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving, EntityPotionEffectEvent.Cause cause) { // CraftBukkit
|
||||
boolean flag = false;
|
||||
Iterator iterator = this.effects.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Holder<MobEffectList> holder = (Holder) iterator.next();
|
||||
|
||||
- if (entityliving.removeEffect(holder)) {
|
||||
+ if (entityliving.removeEffect(holder, cause)) { // CraftBukkit
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
--- a/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.java
|
||||
+++ b/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.java
|
||||
@@ -53,7 +53,16 @@
|
||||
|
||||
Vec3D vec3d = entityliving.position();
|
||||
|
||||
- if (entityliving.randomTeleport(d0, d1, d2, true)) {
|
||||
+ // CraftBukkit start - handle canceled status of teleport event
|
||||
+ java.util.Optional<Boolean> status = entityliving.randomTeleport(d0, d1, d2, true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT);
|
||||
+
|
||||
+ if (!status.isPresent()) {
|
||||
+ // teleport event was canceled, no more tries
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if (status.get()) {
|
||||
+ // CraftBukkit end
|
||||
world.gameEvent((Holder) GameEvent.TELEPORT, vec3d, GameEvent.a.of((Entity) entityliving));
|
||||
SoundEffect soundeffect;
|
||||
SoundCategory soundcategory;
|
||||
@@ -0,0 +1,93 @@
|
||||
--- a/net/minecraft/world/item/crafting/CraftingManager.java
|
||||
+++ b/net/minecraft/world/item/crafting/CraftingManager.java
|
||||
@@ -39,6 +39,11 @@
|
||||
import net.minecraft.world.level.World;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import java.util.Collections;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class CraftingManager extends ResourceDataAbstract<RecipeMap> implements RecipeAccess {
|
||||
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
@@ -111,7 +116,25 @@
|
||||
CraftingManager.LOGGER.info("Loaded {} recipes", recipemap.values().size());
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public void addRecipe(RecipeHolder<?> irecipe) {
|
||||
+ this.recipes.addRecipe(irecipe);
|
||||
+ finalizeRecipeLoading();
|
||||
+ }
|
||||
+
|
||||
+ private FeatureFlagSet featureflagset;
|
||||
+
|
||||
+ public void finalizeRecipeLoading() {
|
||||
+ if (featureflagset != null) {
|
||||
+ finalizeRecipeLoading(featureflagset);
|
||||
+
|
||||
+ MinecraftServer.getServer().getPlayerList().reloadRecipes();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
public void finalizeRecipeLoading(FeatureFlagSet featureflagset) {
|
||||
+ this.featureflagset = featureflagset;
|
||||
+ // CraftBukkit end
|
||||
List<SelectableRecipe.a<RecipeStonecutting>> list = new ArrayList();
|
||||
List<CraftingManager.b> list1 = CraftingManager.RECIPE_PROPERTY_SETS.entrySet().stream().map((entry) -> {
|
||||
return new CraftingManager.b((ResourceKey) entry.getKey(), (CraftingManager.c) entry.getValue());
|
||||
@@ -130,7 +153,7 @@
|
||||
RecipeStonecutting recipestonecutting = (RecipeStonecutting) irecipe;
|
||||
|
||||
if (isIngredientEnabled(featureflagset, recipestonecutting.input()) && recipestonecutting.resultDisplay().isEnabled(featureflagset)) {
|
||||
- list.add(new SelectableRecipe.a<>(recipestonecutting.input(), new SelectableRecipe<>(recipestonecutting.resultDisplay(), Optional.of(recipeholder))));
|
||||
+ list.add(new SelectableRecipe.a<RecipeStonecutting>(recipestonecutting.input(), new SelectableRecipe<>(recipestonecutting.resultDisplay(), Optional.of((RecipeHolder<RecipeStonecutting>) recipeholder)))); // CraftBukkit - decompile error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +195,10 @@
|
||||
}
|
||||
|
||||
public <I extends RecipeInput, T extends IRecipe<I>> Optional<RecipeHolder<T>> getRecipeFor(Recipes<T> recipes, I i0, World world) {
|
||||
- return this.recipes.getRecipesFor(recipes, i0, world).findFirst();
|
||||
+ // CraftBukkit start
|
||||
+ List<RecipeHolder<T>> list = this.recipes.getRecipesFor(recipes, i0, world).toList();
|
||||
+ return (list.isEmpty()) ? Optional.empty() : Optional.of(list.getLast()); // CraftBukkit - SPIGOT-4638: last recipe gets priority
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
public Optional<RecipeHolder<?>> byKey(ResourceKey<IRecipe<?>> resourcekey) {
|
||||
@@ -183,7 +209,7 @@
|
||||
private <T extends IRecipe<?>> RecipeHolder<T> byKeyTyped(Recipes<T> recipes, ResourceKey<IRecipe<?>> resourcekey) {
|
||||
RecipeHolder<?> recipeholder = this.recipes.byKey(resourcekey);
|
||||
|
||||
- return recipeholder != null && recipeholder.value().getType().equals(recipes) ? recipeholder : null;
|
||||
+ return recipeholder != null && recipeholder.value().getType().equals(recipes) ? (RecipeHolder) recipeholder : null; // CraftBukkit - decompile error
|
||||
}
|
||||
|
||||
public Map<ResourceKey<RecipePropertySet>, RecipePropertySet> getSynchronizedItemProperties() {
|
||||
@@ -231,6 +257,22 @@
|
||||
return new RecipeHolder<>(resourcekey, irecipe);
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public boolean removeRecipe(ResourceKey<IRecipe<?>> mcKey) {
|
||||
+ boolean removed = this.recipes.removeRecipe(mcKey);
|
||||
+ if (removed) {
|
||||
+ finalizeRecipeLoading();
|
||||
+ }
|
||||
+
|
||||
+ return removed;
|
||||
+ }
|
||||
+
|
||||
+ public void clearRecipes() {
|
||||
+ this.recipes = RecipeMap.create(Collections.emptyList());
|
||||
+ finalizeRecipeLoading();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public static <I extends RecipeInput, T extends IRecipe<I>> CraftingManager.a<I, T> createCheck(final Recipes<T> recipes) {
|
||||
return new CraftingManager.a<I, T>() {
|
||||
@Nullable
|
||||
@@ -0,0 +1,35 @@
|
||||
--- a/net/minecraft/world/item/crafting/FurnaceRecipe.java
|
||||
+++ b/net/minecraft/world/item/crafting/FurnaceRecipe.java
|
||||
@@ -4,6 +4,14 @@
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class FurnaceRecipe extends RecipeCooking {
|
||||
|
||||
public FurnaceRecipe(String s, CookingBookCategory cookingbookcategory, RecipeItemStack recipeitemstack, ItemStack itemstack, float f, int i) {
|
||||
@@ -45,4 +53,17 @@
|
||||
|
||||
return recipebookcategory;
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
|
||||
+
|
||||
+ CraftFurnaceRecipe recipe = new CraftFurnaceRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
|
||||
+ recipe.setGroup(this.group());
|
||||
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
|
||||
+
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
--- a/net/minecraft/world/item/crafting/IRecipe.java
|
||||
+++ b/net/minecraft/world/item/crafting/IRecipe.java
|
||||
@@ -44,4 +44,6 @@
|
||||
}
|
||||
|
||||
RecipeBookCategory recipeBookCategory();
|
||||
+
|
||||
+ org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id); // CraftBukkit
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
--- a/net/minecraft/world/item/crafting/IRecipeComplex.java
|
||||
+++ b/net/minecraft/world/item/crafting/IRecipeComplex.java
|
||||
@@ -8,6 +8,15 @@
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import net.minecraft.world.item.ItemStack;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftComplexRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public abstract class IRecipeComplex implements RecipeCrafting {
|
||||
|
||||
private final CraftingBookCategory category;
|
||||
@@ -34,6 +43,19 @@
|
||||
@Override
|
||||
public abstract RecipeSerializer<? extends IRecipeComplex> getSerializer();
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(ItemStack.EMPTY);
|
||||
+
|
||||
+ CraftComplexRecipe recipe = new CraftComplexRecipe(id, result, this);
|
||||
+ recipe.setGroup(this.group());
|
||||
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
|
||||
+
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public static class Serializer<T extends RecipeCrafting> implements RecipeSerializer<T> {
|
||||
|
||||
private final MapCodec<T> codec;
|
||||
@@ -41,13 +63,13 @@
|
||||
|
||||
public Serializer(IRecipeComplex.Serializer.Factory<T> irecipecomplex_serializer_factory) {
|
||||
this.codec = RecordCodecBuilder.mapCodec((instance) -> {
|
||||
- P1 p1 = instance.group(CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(RecipeCrafting::category));
|
||||
+ P1<RecordCodecBuilder.Mu<T>, CraftingBookCategory> p1 = instance.group(CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(RecipeCrafting::category)); // CraftBukkit - decompile error
|
||||
|
||||
Objects.requireNonNull(irecipecomplex_serializer_factory);
|
||||
return p1.apply(instance, irecipecomplex_serializer_factory::create);
|
||||
});
|
||||
StreamCodec streamcodec = CraftingBookCategory.STREAM_CODEC;
|
||||
- Function function = RecipeCrafting::category;
|
||||
+ Function<RecipeCrafting, CraftingBookCategory> function = RecipeCrafting::category; // CraftBukkit - decompile error
|
||||
|
||||
Objects.requireNonNull(irecipecomplex_serializer_factory);
|
||||
this.streamCodec = StreamCodec.composite(streamcodec, function, irecipecomplex_serializer_factory::create);
|
||||
@@ -0,0 +1,35 @@
|
||||
--- a/net/minecraft/world/item/crafting/RecipeBlasting.java
|
||||
+++ b/net/minecraft/world/item/crafting/RecipeBlasting.java
|
||||
@@ -4,6 +4,14 @@
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftBlastingRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class RecipeBlasting extends RecipeCooking {
|
||||
|
||||
public RecipeBlasting(String s, CookingBookCategory cookingbookcategory, RecipeItemStack recipeitemstack, ItemStack itemstack, float f, int i) {
|
||||
@@ -43,4 +51,17 @@
|
||||
|
||||
return recipebookcategory;
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
|
||||
+
|
||||
+ CraftBlastingRecipe recipe = new CraftBlastingRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
|
||||
+ recipe.setGroup(this.group());
|
||||
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
|
||||
+
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
--- a/net/minecraft/world/item/crafting/RecipeCampfire.java
|
||||
+++ b/net/minecraft/world/item/crafting/RecipeCampfire.java
|
||||
@@ -4,6 +4,14 @@
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftCampfireRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class RecipeCampfire extends RecipeCooking {
|
||||
|
||||
public RecipeCampfire(String s, CookingBookCategory cookingbookcategory, RecipeItemStack recipeitemstack, ItemStack itemstack, float f, int i) {
|
||||
@@ -29,4 +37,17 @@
|
||||
public RecipeBookCategory recipeBookCategory() {
|
||||
return RecipeBookCategories.CAMPFIRE;
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
|
||||
+
|
||||
+ CraftCampfireRecipe recipe = new CraftCampfireRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
|
||||
+ recipe.setGroup(this.group());
|
||||
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
|
||||
+
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
--- a/net/minecraft/world/item/crafting/RecipeHolder.java
|
||||
+++ b/net/minecraft/world/item/crafting/RecipeHolder.java
|
||||
@@ -5,8 +5,19 @@
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public record RecipeHolder<T extends IRecipe<?>>(ResourceKey<IRecipe<?>> id, T value) {
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public final Recipe toBukkitRecipe() {
|
||||
+ return this.value.toBukkitRecipe(CraftNamespacedKey.fromMinecraft(this.id.location()));
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, RecipeHolder<?>> STREAM_CODEC = StreamCodec.composite(ResourceKey.streamCodec(Registries.RECIPE), RecipeHolder::id, IRecipe.STREAM_CODEC, RecipeHolder::value, RecipeHolder::new);
|
||||
|
||||
public boolean equals(Object object) {
|
||||
@@ -0,0 +1,66 @@
|
||||
--- a/net/minecraft/world/item/crafting/RecipeItemStack.java
|
||||
+++ b/net/minecraft/world/item/crafting/RecipeItemStack.java
|
||||
@@ -21,6 +21,11 @@
|
||||
import net.minecraft.world.item.crafting.display.SlotDisplay;
|
||||
import net.minecraft.world.level.IMaterial;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import java.util.List;
|
||||
+import javax.annotation.Nullable;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public final class RecipeItemStack implements AutoRecipeStackManager.a<Holder<Item>>, Predicate<ItemStack> {
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, RecipeItemStack> CONTENTS_STREAM_CODEC = ByteBufCodecs.holderSet(Registries.ITEM).map(RecipeItemStack::new, (recipeitemstack) -> {
|
||||
@@ -38,6 +43,24 @@
|
||||
return recipeitemstack.values;
|
||||
});
|
||||
private final HolderSet<Item> values;
|
||||
+ // CraftBukkit start
|
||||
+ @Nullable
|
||||
+ private List<ItemStack> itemStacks;
|
||||
+
|
||||
+ public boolean isExact() {
|
||||
+ return this.itemStacks != null;
|
||||
+ }
|
||||
+
|
||||
+ public List<ItemStack> itemStacks() {
|
||||
+ return this.itemStacks;
|
||||
+ }
|
||||
+
|
||||
+ public static RecipeItemStack ofStacks(List<ItemStack> stacks) {
|
||||
+ RecipeItemStack recipe = RecipeItemStack.of(stacks.stream().map(ItemStack::getItem));
|
||||
+ recipe.itemStacks = stacks;
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
private RecipeItemStack(HolderSet<Item> holderset) {
|
||||
holderset.unwrap().ifRight((list) -> {
|
||||
@@ -70,6 +93,17 @@
|
||||
}
|
||||
|
||||
public boolean test(ItemStack itemstack) {
|
||||
+ // CraftBukkit start
|
||||
+ if (this.isExact()) {
|
||||
+ for (ItemStack itemstack1 : this.itemStacks()) {
|
||||
+ if (itemstack1.getItem() == itemstack.getItem() && ItemStack.isSameItemSameComponents(itemstack, itemstack1)) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return false;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
return itemstack.is(this.values);
|
||||
}
|
||||
|
||||
@@ -79,7 +113,7 @@
|
||||
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof RecipeItemStack recipeitemstack) {
|
||||
- return Objects.equals(this.values, recipeitemstack.values);
|
||||
+ return Objects.equals(this.values, recipeitemstack.values) && Objects.equals(this.itemStacks, recipeitemstack.itemStacks); // CraftBukkit
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
--- a/net/minecraft/world/item/crafting/RecipeMap.java
|
||||
+++ b/net/minecraft/world/item/crafting/RecipeMap.java
|
||||
@@ -12,6 +12,11 @@
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.World;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import com.google.common.collect.LinkedHashMultimap;
|
||||
+import com.google.common.collect.Maps;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class RecipeMap {
|
||||
|
||||
public static final RecipeMap EMPTY = new RecipeMap(ImmutableMultimap.of(), Map.of());
|
||||
@@ -35,11 +40,39 @@
|
||||
com_google_common_collect_immutablemap_builder.put(recipeholder.id(), recipeholder);
|
||||
}
|
||||
|
||||
- return new RecipeMap(builder.build(), com_google_common_collect_immutablemap_builder.build());
|
||||
+ // CraftBukkit start - mutable
|
||||
+ return new RecipeMap(LinkedHashMultimap.create(builder.build()), Maps.newHashMap(com_google_common_collect_immutablemap_builder.build()));
|
||||
+ }
|
||||
+
|
||||
+ public void addRecipe(RecipeHolder<?> irecipe) {
|
||||
+ Collection<RecipeHolder<?>> map = this.byType.get(irecipe.value().getType());
|
||||
+
|
||||
+ if (byKey.containsKey(irecipe.id())) {
|
||||
+ throw new IllegalStateException("Duplicate recipe ignored with ID " + irecipe.id());
|
||||
+ } else {
|
||||
+ map.add(irecipe);
|
||||
+ byKey.put(irecipe.id(), irecipe);
|
||||
+ }
|
||||
}
|
||||
|
||||
+ public boolean removeRecipe(ResourceKey<IRecipe<?>> mcKey) {
|
||||
+ boolean removed = false;
|
||||
+ Iterator<RecipeHolder<?>> iter = byType.values().iterator();
|
||||
+ while (iter.hasNext()) {
|
||||
+ RecipeHolder<?> recipe = iter.next();
|
||||
+ if (recipe.id().equals(mcKey)) {
|
||||
+ iter.remove();
|
||||
+ removed = true;
|
||||
+ }
|
||||
+ }
|
||||
+ removed |= byKey.remove(mcKey) != null;
|
||||
+
|
||||
+ return removed;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public <I extends RecipeInput, T extends IRecipe<I>> Collection<RecipeHolder<T>> byType(Recipes<T> recipes) {
|
||||
- return this.byType.get(recipes);
|
||||
+ return (Collection) this.byType.get(recipes); // CraftBukkit - decompile error
|
||||
}
|
||||
|
||||
public Collection<RecipeHolder<?>> values() {
|
||||
@@ -0,0 +1,35 @@
|
||||
--- a/net/minecraft/world/item/crafting/RecipeSmoking.java
|
||||
+++ b/net/minecraft/world/item/crafting/RecipeSmoking.java
|
||||
@@ -4,6 +4,14 @@
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftSmokingRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class RecipeSmoking extends RecipeCooking {
|
||||
|
||||
public RecipeSmoking(String s, CookingBookCategory cookingbookcategory, RecipeItemStack recipeitemstack, ItemStack itemstack, float f, int i) {
|
||||
@@ -29,4 +37,17 @@
|
||||
public RecipeBookCategory recipeBookCategory() {
|
||||
return RecipeBookCategories.SMOKER_FOOD;
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
|
||||
+
|
||||
+ CraftSmokingRecipe recipe = new CraftSmokingRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime());
|
||||
+ recipe.setGroup(this.group());
|
||||
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
|
||||
+
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
--- a/net/minecraft/world/item/crafting/RecipeStonecutting.java
|
||||
+++ b/net/minecraft/world/item/crafting/RecipeStonecutting.java
|
||||
@@ -7,6 +7,14 @@
|
||||
import net.minecraft.world.item.crafting.display.SlotDisplay;
|
||||
import net.minecraft.world.item.crafting.display.StonecutterRecipeDisplay;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftStonecuttingRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class RecipeStonecutting extends RecipeSingleItem {
|
||||
|
||||
public RecipeStonecutting(String s, RecipeItemStack recipeitemstack, ItemStack itemstack) {
|
||||
@@ -36,4 +44,16 @@
|
||||
public RecipeBookCategory recipeBookCategory() {
|
||||
return RecipeBookCategories.STONECUTTER;
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result());
|
||||
+
|
||||
+ CraftStonecuttingRecipe recipe = new CraftStonecuttingRecipe(id, result, CraftRecipe.toBukkit(this.input()));
|
||||
+ recipe.setGroup(this.group());
|
||||
+
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
--- a/net/minecraft/world/item/crafting/ShapedRecipes.java
|
||||
+++ b/net/minecraft/world/item/crafting/ShapedRecipes.java
|
||||
@@ -17,6 +17,14 @@
|
||||
import net.minecraft.world.item.crafting.display.SlotDisplay;
|
||||
import net.minecraft.world.level.World;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftShapedRecipe;
|
||||
+import org.bukkit.inventory.RecipeChoice;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ShapedRecipes implements RecipeCrafting {
|
||||
|
||||
final ShapedRecipePattern pattern;
|
||||
@@ -39,6 +47,68 @@
|
||||
this(s, craftingbookcategory, shapedrecipepattern, itemstack, true);
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public org.bukkit.inventory.ShapedRecipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
|
||||
+ CraftShapedRecipe recipe = new CraftShapedRecipe(id, result, this);
|
||||
+ recipe.setGroup(this.group);
|
||||
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
|
||||
+
|
||||
+ switch (this.pattern.height()) {
|
||||
+ case 1:
|
||||
+ switch (this.pattern.width()) {
|
||||
+ case 1:
|
||||
+ recipe.shape("a");
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ recipe.shape("ab");
|
||||
+ break;
|
||||
+ case 3:
|
||||
+ recipe.shape("abc");
|
||||
+ break;
|
||||
+ }
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ switch (this.pattern.width()) {
|
||||
+ case 1:
|
||||
+ recipe.shape("a","b");
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ recipe.shape("ab","cd");
|
||||
+ break;
|
||||
+ case 3:
|
||||
+ recipe.shape("abc","def");
|
||||
+ break;
|
||||
+ }
|
||||
+ break;
|
||||
+ case 3:
|
||||
+ switch (this.pattern.width()) {
|
||||
+ case 1:
|
||||
+ recipe.shape("a","b","c");
|
||||
+ break;
|
||||
+ case 2:
|
||||
+ recipe.shape("ab","cd","ef");
|
||||
+ break;
|
||||
+ case 3:
|
||||
+ recipe.shape("abc","def","ghi");
|
||||
+ break;
|
||||
+ }
|
||||
+ break;
|
||||
+ }
|
||||
+ char c = 'a';
|
||||
+ for (Optional<RecipeItemStack> list : this.pattern.ingredients()) {
|
||||
+ RecipeChoice choice = CraftRecipe.toBukkit(list);
|
||||
+ if (choice != null) {
|
||||
+ recipe.setIngredient(c, choice);
|
||||
+ }
|
||||
+
|
||||
+ c++;
|
||||
+ }
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
@Override
|
||||
public RecipeSerializer<? extends ShapedRecipes> getSerializer() {
|
||||
return RecipeSerializer.SHAPED_RECIPE;
|
||||
@@ -0,0 +1,39 @@
|
||||
--- a/net/minecraft/world/item/crafting/ShapelessRecipes.java
|
||||
+++ b/net/minecraft/world/item/crafting/ShapelessRecipes.java
|
||||
@@ -17,6 +17,13 @@
|
||||
import net.minecraft.world.item.crafting.display.SlotDisplay;
|
||||
import net.minecraft.world.level.World;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ShapelessRecipes implements RecipeCrafting {
|
||||
|
||||
final String group;
|
||||
@@ -33,6 +40,22 @@
|
||||
this.ingredients = list;
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ @Override
|
||||
+ public org.bukkit.inventory.ShapelessRecipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
|
||||
+ CraftShapelessRecipe recipe = new CraftShapelessRecipe(id, result, this);
|
||||
+ recipe.setGroup(this.group);
|
||||
+ recipe.setCategory(CraftRecipe.getCategory(this.category()));
|
||||
+
|
||||
+ for (RecipeItemStack list : this.ingredients) {
|
||||
+ recipe.addIngredient(CraftRecipe.toBukkit(list));
|
||||
+ }
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
@Override
|
||||
public RecipeSerializer<ShapelessRecipes> getSerializer() {
|
||||
return RecipeSerializer.SHAPELESS_RECIPE;
|
||||
@@ -0,0 +1,35 @@
|
||||
--- a/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
|
||||
+++ b/net/minecraft/world/item/crafting/SmithingTransformRecipe.java
|
||||
@@ -14,6 +14,14 @@
|
||||
import net.minecraft.world.item.crafting.display.SlotDisplay;
|
||||
import net.minecraft.world.item.crafting.display.SmithingRecipeDisplay;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftSmithingTransformRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class SmithingTransformRecipe implements SmithingRecipe {
|
||||
|
||||
final Optional<RecipeItemStack> template;
|
||||
@@ -71,6 +79,17 @@
|
||||
return List.of(new SmithingRecipeDisplay(RecipeItemStack.optionalIngredientToDisplay(this.template), RecipeItemStack.optionalIngredientToDisplay(this.base), RecipeItemStack.optionalIngredientToDisplay(this.addition), new SlotDisplay.f(this.result), new SlotDisplay.d(Items.SMITHING_TABLE)));
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
|
||||
+
|
||||
+ CraftSmithingTransformRecipe recipe = new CraftSmithingTransformRecipe(id, result, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition));
|
||||
+
|
||||
+ return recipe;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public static class a implements RecipeSerializer<SmithingTransformRecipe> {
|
||||
|
||||
private static final MapCodec<SmithingTransformRecipe> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
|
||||
@@ -0,0 +1,30 @@
|
||||
--- a/net/minecraft/world/item/crafting/SmithingTrimRecipe.java
|
||||
+++ b/net/minecraft/world/item/crafting/SmithingTrimRecipe.java
|
||||
@@ -21,6 +21,13 @@
|
||||
import net.minecraft.world.item.equipment.trim.TrimPattern;
|
||||
import net.minecraft.world.item.equipment.trim.TrimPatterns;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftSmithingTrimRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class SmithingTrimRecipe implements SmithingRecipe {
|
||||
|
||||
final Optional<RecipeItemStack> template;
|
||||
@@ -97,6 +104,13 @@
|
||||
return List.of(new SmithingRecipeDisplay(slotdisplay2, slotdisplay, slotdisplay1, new SlotDisplay.g(slotdisplay, slotdisplay1, slotdisplay2), new SlotDisplay.d(Items.SMITHING_TABLE)));
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ return new CraftSmithingTrimRecipe(id, CraftRecipe.toBukkit(this.template), CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition));
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public static class a implements RecipeSerializer<SmithingTrimRecipe> {
|
||||
|
||||
private static final MapCodec<SmithingTrimRecipe> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
|
||||
@@ -0,0 +1,31 @@
|
||||
--- a/net/minecraft/world/item/crafting/TransmuteRecipe.java
|
||||
+++ b/net/minecraft/world/item/crafting/TransmuteRecipe.java
|
||||
@@ -20,6 +20,14 @@
|
||||
import net.minecraft.world.level.IMaterial;
|
||||
import net.minecraft.world.level.World;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemType;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftTransmuteRecipe;
|
||||
+import org.bukkit.inventory.Recipe;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class TransmuteRecipe implements RecipeCrafting {
|
||||
|
||||
final String group;
|
||||
@@ -84,6 +92,13 @@
|
||||
return List.of(new ShapelessCraftingRecipeDisplay(List.of(this.input.display(), this.material.display()), new SlotDisplay.d(this.result), new SlotDisplay.d(Items.CRAFTING_TABLE)));
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Recipe toBukkitRecipe(NamespacedKey id) {
|
||||
+ return new CraftTransmuteRecipe(id, CraftItemType.minecraftToBukkit(this.result.value()), CraftRecipe.toBukkit(this.input), CraftRecipe.toBukkit(this.material));
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
@Override
|
||||
public RecipeSerializer<TransmuteRecipe> getSerializer() {
|
||||
return RecipeSerializer.TRANSMUTE;
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/net/minecraft/world/item/enchantment/effects/ApplyMobEffect.java
|
||||
+++ b/net/minecraft/world/item/enchantment/effects/ApplyMobEffect.java
|
||||
@@ -34,7 +34,7 @@
|
||||
int j = Math.round(MathHelper.randomBetween(randomsource, this.minDuration.calculate(i), this.maxDuration.calculate(i)) * 20.0F);
|
||||
int k = Math.max(0, Math.round(MathHelper.randomBetween(randomsource, this.minAmplifier.calculate(i), this.maxAmplifier.calculate(i))));
|
||||
|
||||
- entityliving.addEffect(new MobEffect((Holder) optional.get(), j, k));
|
||||
+ entityliving.addEffect(new MobEffect((Holder) optional.get(), j, k), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ATTACK); // CraftBukkit
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
--- a/net/minecraft/world/item/enchantment/effects/Ignite.java
|
||||
+++ b/net/minecraft/world/item/enchantment/effects/Ignite.java
|
||||
@@ -8,6 +8,11 @@
|
||||
import net.minecraft.world.item.enchantment.LevelBasedValue;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||||
+import org.bukkit.event.entity.EntityCombustEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public record Ignite(LevelBasedValue duration) implements EnchantmentEntityEffect {
|
||||
|
||||
public static final MapCodec<Ignite> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
|
||||
@@ -18,7 +23,21 @@
|
||||
|
||||
@Override
|
||||
public void apply(WorldServer worldserver, int i, EnchantedItemInUse enchantediteminuse, Entity entity, Vec3D vec3d) {
|
||||
- entity.igniteForSeconds(this.duration.calculate(i));
|
||||
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
|
||||
+ EntityCombustEvent entityCombustEvent;
|
||||
+ if (enchantediteminuse.owner() != null) {
|
||||
+ entityCombustEvent = new EntityCombustByEntityEvent(enchantediteminuse.owner().getBukkitEntity(), entity.getBukkitEntity(), this.duration.calculate(i));
|
||||
+ } else {
|
||||
+ entityCombustEvent = new EntityCombustEvent(entity.getBukkitEntity(), this.duration.calculate(i));
|
||||
+ }
|
||||
+
|
||||
+ org.bukkit.Bukkit.getPluginManager().callEvent(entityCombustEvent);
|
||||
+ if (entityCombustEvent.isCancelled()) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ entity.igniteForSeconds(entityCombustEvent.getDuration(), false);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/net/minecraft/world/item/enchantment/effects/ReplaceBlock.java
|
||||
+++ b/net/minecraft/world/item/enchantment/effects/ReplaceBlock.java
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
if ((Boolean) this.predicate.map((blockpredicate) -> {
|
||||
return blockpredicate.test(worldserver, blockposition);
|
||||
- }).orElse(true) && worldserver.setBlockAndUpdate(blockposition, this.blockState.getState(entity.getRandom(), blockposition))) {
|
||||
+ }).orElse(true) && org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(worldserver, blockposition, this.blockState.getState(entity.getRandom(), blockposition), entity)) { // CraftBukkit - Call EntityBlockFormEvent
|
||||
this.triggerGameEvent.ifPresent((holder) -> {
|
||||
worldserver.gameEvent(entity, holder, blockposition);
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/net/minecraft/world/item/enchantment/effects/ReplaceDisk.java
|
||||
+++ b/net/minecraft/world/item/enchantment/effects/ReplaceDisk.java
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
if (blockposition1.distToCenterSqr(vec3d.x(), (double) blockposition1.getY() + 0.5D, vec3d.z()) < (double) MathHelper.square(j) && (Boolean) this.predicate.map((blockpredicate) -> {
|
||||
return blockpredicate.test(worldserver, blockposition1);
|
||||
- }).orElse(true) && worldserver.setBlockAndUpdate(blockposition1, this.blockState.getState(randomsource, blockposition1))) {
|
||||
+ }).orElse(true) && org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(worldserver, blockposition1, this.blockState.getState(randomsource, blockposition1), entity)) { // CraftBukkit - Call EntityBlockFormEvent for Frost Walker
|
||||
this.triggerGameEvent.ifPresent((holder) -> {
|
||||
worldserver.gameEvent(entity, holder, blockposition1);
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
--- a/net/minecraft/world/item/enchantment/effects/SummonEntityEffect.java
|
||||
+++ b/net/minecraft/world/item/enchantment/effects/SummonEntityEffect.java
|
||||
@@ -20,6 +20,12 @@
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import net.minecraft.world.item.Items;
|
||||
+import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
+import org.bukkit.event.weather.LightningStrikeEvent;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public record SummonEntityEffect(HolderSet<EntityTypes<?>> entityTypes, boolean joinTeam) implements EnchantmentEntityEffect {
|
||||
|
||||
public static final MapCodec<SummonEntityEffect> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
|
||||
@@ -34,7 +40,7 @@
|
||||
Optional<Holder<EntityTypes<?>>> optional = this.entityTypes().getRandomElement(worldserver.getRandom());
|
||||
|
||||
if (!optional.isEmpty()) {
|
||||
- Entity entity1 = ((EntityTypes) ((Holder) optional.get()).value()).spawn(worldserver, blockposition, EntitySpawnReason.TRIGGERED);
|
||||
+ Entity entity1 = ((EntityTypes) ((Holder) optional.get()).value()).create(worldserver, null, blockposition, EntitySpawnReason.TRIGGERED, false, false); // CraftBukkit
|
||||
|
||||
if (entity1 != null) {
|
||||
if (entity1 instanceof EntityLightning) {
|
||||
@@ -46,6 +52,11 @@
|
||||
|
||||
entitylightning.setCause(entityplayer);
|
||||
}
|
||||
+ // CraftBukkit start
|
||||
+ worldserver.strikeLightning(entity1, (enchantediteminuse.itemStack().getItem() == Items.TRIDENT) ? LightningStrikeEvent.Cause.TRIDENT : LightningStrikeEvent.Cause.ENCHANTMENT);
|
||||
+ } else {
|
||||
+ worldserver.addFreshEntityWithPassengers(entity1, CreatureSpawnEvent.SpawnReason.ENCHANTMENT);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
if (this.joinTeam && entity.getTeam() != null) {
|
||||
@@ -0,0 +1,9 @@
|
||||
--- a/net/minecraft/world/item/trading/IMerchant.java
|
||||
+++ b/net/minecraft/world/item/trading/IMerchant.java
|
||||
@@ -54,4 +54,6 @@
|
||||
boolean isClientSide();
|
||||
|
||||
boolean stillValid(EntityHuman entityhuman);
|
||||
+
|
||||
+ org.bukkit.craftbukkit.inventory.CraftMerchant getCraftMerchant(); // CraftBukkit
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
--- a/net/minecraft/world/item/trading/MerchantRecipe.java
|
||||
+++ b/net/minecraft/world/item/trading/MerchantRecipe.java
|
||||
@@ -8,6 +8,8 @@
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
+import org.bukkit.craftbukkit.inventory.CraftMerchantRecipe; // CraftBukkit
|
||||
+
|
||||
public class MerchantRecipe {
|
||||
|
||||
public static final Codec<MerchantRecipe> CODEC = RecordCodecBuilder.create((instance) -> {
|
||||
@@ -44,6 +46,18 @@
|
||||
public int demand;
|
||||
public float priceMultiplier;
|
||||
public int xp;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftMerchantRecipe bukkitHandle;
|
||||
+
|
||||
+ public CraftMerchantRecipe asBukkit() {
|
||||
+ return (bukkitHandle == null) ? bukkitHandle = new CraftMerchantRecipe(this) : bukkitHandle;
|
||||
+ }
|
||||
+
|
||||
+ public MerchantRecipe(ItemCost baseCostA, Optional<ItemCost> costB, ItemStack result, int uses, int maxUses, int experience, float priceMultiplier, int demand, CraftMerchantRecipe bukkit) {
|
||||
+ this(baseCostA, costB, result, uses, maxUses, experience, priceMultiplier, demand);
|
||||
+ this.bukkitHandle = bukkit;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
private MerchantRecipe(ItemCost itemcost, Optional<ItemCost> optional, ItemStack itemstack, int i, int j, boolean flag, int k, int l, float f, int i1) {
|
||||
this.baseCostA = itemcost;
|
||||
@@ -185,7 +199,11 @@
|
||||
if (!this.satisfiedBy(itemstack, itemstack1)) {
|
||||
return false;
|
||||
} else {
|
||||
- itemstack.shrink(this.getCostA().getCount());
|
||||
+ // CraftBukkit start
|
||||
+ if (!this.getCostA().isEmpty()) {
|
||||
+ itemstack.shrink(this.getCostA().getCount());
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
if (!this.getCostB().isEmpty()) {
|
||||
itemstack1.shrink(this.getCostB().getCount());
|
||||
}
|
||||
Reference in New Issue
Block a user