diff options
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/item/MinecartItem.java.patch')
-rw-r--r-- | patch-remap/mache-spigotflower/net/minecraft/world/item/MinecartItem.java.patch | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/item/MinecartItem.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/item/MinecartItem.java.patch new file mode 100644 index 0000000000..506e4c1f8e --- /dev/null +++ b/patch-remap/mache-spigotflower/net/minecraft/world/item/MinecartItem.java.patch @@ -0,0 +1,195 @@ +--- a/net/minecraft/world/item/MinecartItem.java ++++ b/net/minecraft/world/item/MinecartItem.java +@@ -2,9 +2,9 @@ + + import net.minecraft.core.BlockPos; + import net.minecraft.core.Direction; +-import net.minecraft.core.dispenser.BlockSource; + import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; + import net.minecraft.core.dispenser.DispenseItemBehavior; ++import net.minecraft.core.dispenser.SourceBlock; + import net.minecraft.server.level.ServerLevel; + import net.minecraft.tags.BlockTags; + import net.minecraft.world.InteractionResult; +@@ -14,10 +14,15 @@ + import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.BaseRailBlock; + import net.minecraft.world.level.block.DispenserBlock; +-import net.minecraft.world.level.block.state.BlockState; ++import net.minecraft.world.level.block.state.IBlockData; + import net.minecraft.world.level.block.state.properties.RailShape; + import net.minecraft.world.level.gameevent.GameEvent; + import net.minecraft.world.phys.Vec3; ++// CraftBukkit start ++import org.bukkit.craftbukkit.block.CraftBlock; ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.event.block.BlockDispenseEvent; ++// CraftBukkit end + + public class MinecartItem extends Item { + +@@ -25,90 +30,121 @@ + private final DefaultDispenseItemBehavior defaultDispenseItemBehavior = new DefaultDispenseItemBehavior(); + + @Override +- @Override +- public ItemStack execute(BlockSource blocksource, ItemStack itemstack) { +- Direction direction = (Direction) blocksource.state().getValue(DispenserBlock.FACING); +- ServerLevel serverlevel = blocksource.level(); +- Vec3 vec3 = blocksource.center(); +- double d0 = vec3.x() + (double) direction.getStepX() * 1.125D; +- double d1 = Math.floor(vec3.y()) + (double) direction.getStepY(); +- double d2 = vec3.z() + (double) direction.getStepZ() * 1.125D; +- BlockPos blockpos = blocksource.pos().relative(direction); +- BlockState blockstate = serverlevel.getBlockState(blockpos); +- RailShape railshape = blockstate.getBlock() instanceof BaseRailBlock ? (RailShape) blockstate.getValue(((BaseRailBlock) blockstate.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH; ++ public ItemStack execute(SourceBlock sourceblock, ItemStack itemstack) { ++ Direction enumdirection = (Direction) sourceblock.state().getValue(DispenserBlock.FACING); ++ ServerLevel worldserver = sourceblock.level(); ++ Vec3 vec3d = sourceblock.center(); ++ double d0 = vec3d.x() + (double) enumdirection.getStepX() * 1.125D; ++ double d1 = Math.floor(vec3d.y()) + (double) enumdirection.getStepY(); ++ double d2 = vec3d.z() + (double) enumdirection.getStepZ() * 1.125D; ++ BlockPos blockposition = sourceblock.pos().relative(enumdirection); ++ IBlockData iblockdata = worldserver.getBlockState(blockposition); ++ RailShape blockpropertytrackposition = iblockdata.getBlock() instanceof BaseRailBlock ? (RailShape) iblockdata.getValue(((BaseRailBlock) iblockdata.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH; + double d3; + +- if (blockstate.is(BlockTags.RAILS)) { +- if (railshape.isAscending()) { ++ if (iblockdata.is(BlockTags.RAILS)) { ++ if (blockpropertytrackposition.isAscending()) { + d3 = 0.6D; + } else { + d3 = 0.1D; + } + } else { +- if (!blockstate.isAir() || !serverlevel.getBlockState(blockpos.below()).is(BlockTags.RAILS)) { +- return this.defaultDispenseItemBehavior.dispense(blocksource, itemstack); ++ if (!iblockdata.isAir() || !worldserver.getBlockState(blockposition.below()).is(BlockTags.RAILS)) { ++ return this.defaultDispenseItemBehavior.dispense(sourceblock, itemstack); + } + +- BlockState blockstate1 = serverlevel.getBlockState(blockpos.below()); +- RailShape railshape1 = blockstate1.getBlock() instanceof BaseRailBlock ? (RailShape) blockstate1.getValue(((BaseRailBlock) blockstate1.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH; ++ IBlockData iblockdata1 = worldserver.getBlockState(blockposition.below()); ++ RailShape blockpropertytrackposition1 = iblockdata1.getBlock() instanceof BaseRailBlock ? (RailShape) iblockdata1.getValue(((BaseRailBlock) iblockdata1.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH; + +- if (direction != Direction.DOWN && railshape1.isAscending()) { ++ if (enumdirection != Direction.DOWN && blockpropertytrackposition1.isAscending()) { + d3 = -0.4D; + } else { + d3 = -0.9D; + } + } + +- AbstractMinecart abstractminecart = AbstractMinecart.createMinecart(serverlevel, d0, d1 + d3, d2, ((MinecartItem) itemstack.getItem()).type, itemstack, (Player) null); ++ // CraftBukkit start ++ // EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, d0, d1 + d3, d2, ((ItemMinecart) itemstack.getItem()).type); ++ ItemStack itemstack1 = itemstack.split(1); ++ org.bukkit.block.Block block2 = CraftBlock.at(worldserver, sourceblock.pos()); ++ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); + +- serverlevel.addFreshEntity(abstractminecart); +- itemstack.shrink(1); ++ BlockDispenseEvent event = new BlockDispenseEvent(block2, craftItem.clone(), new org.bukkit.util.Vector(d0, d1 + d3, d2)); ++ if (!DispenserBlock.eventFired) { ++ worldserver.getCraftServer().getPluginManager().callEvent(event); ++ } ++ ++ if (event.isCancelled()) { ++ itemstack.grow(1); ++ return itemstack; ++ } ++ ++ if (!event.getItem().equals(craftItem)) { ++ itemstack.grow(1); ++ // Chain to handler for new item ++ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); ++ DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem()); ++ if (idispensebehavior != DispenseItemBehavior.NOOP && idispensebehavior != this) { ++ idispensebehavior.dispense(sourceblock, eventStack); ++ return itemstack; ++ } ++ } ++ ++ itemstack1 = CraftItemStack.asNMSCopy(event.getItem()); ++ AbstractMinecart entityminecartabstract = AbstractMinecart.createMinecart(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), ((MinecartItem) itemstack1.getItem()).type, itemstack1, (Player) null); ++ ++ if (!worldserver.addFreshEntity(entityminecartabstract)) itemstack.grow(1); ++ // itemstack.shrink(1); // CraftBukkit - handled during event processing ++ // CraftBukkit end + return itemstack; + } + + @Override +- @Override +- protected void playSound(BlockSource blocksource) { +- blocksource.level().levelEvent(1000, blocksource.pos(), 0); ++ protected void playSound(SourceBlock sourceblock) { ++ sourceblock.level().levelEvent(1000, sourceblock.pos(), 0); + } + }; +- final AbstractMinecart.Type type; ++ final AbstractMinecart.EnumMinecartType type; + +- public MinecartItem(AbstractMinecart.Type abstractminecart_type, Item.Properties item_properties) { +- super(item_properties); +- this.type = abstractminecart_type; ++ public MinecartItem(AbstractMinecart.EnumMinecartType type, Item.Properties properties) { ++ super(properties); ++ this.type = type; + DispenserBlock.registerBehavior(this, MinecartItem.DISPENSE_ITEM_BEHAVIOR); + } + + @Override +- @Override +- public InteractionResult useOn(UseOnContext useoncontext) { +- Level level = useoncontext.getLevel(); +- BlockPos blockpos = useoncontext.getClickedPos(); +- BlockState blockstate = level.getBlockState(blockpos); ++ public InteractionResult useOn(UseOnContext context) { ++ Level world = context.getLevel(); ++ BlockPos blockposition = context.getClickedPos(); ++ IBlockData iblockdata = world.getBlockState(blockposition); + +- if (!blockstate.is(BlockTags.RAILS)) { ++ if (!iblockdata.is(BlockTags.RAILS)) { + return InteractionResult.FAIL; + } else { +- ItemStack itemstack = useoncontext.getItemInHand(); ++ ItemStack itemstack = context.getItemInHand(); + +- if (level instanceof ServerLevel) { +- ServerLevel serverlevel = (ServerLevel) level; +- RailShape railshape = blockstate.getBlock() instanceof BaseRailBlock ? (RailShape) blockstate.getValue(((BaseRailBlock) blockstate.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH; ++ if (world instanceof ServerLevel) { ++ ServerLevel worldserver = (ServerLevel) world; ++ RailShape blockpropertytrackposition = iblockdata.getBlock() instanceof BaseRailBlock ? (RailShape) iblockdata.getValue(((BaseRailBlock) iblockdata.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH; + double d0 = 0.0D; + +- if (railshape.isAscending()) { ++ if (blockpropertytrackposition.isAscending()) { + d0 = 0.5D; + } + +- AbstractMinecart abstractminecart = AbstractMinecart.createMinecart(serverlevel, (double) blockpos.getX() + 0.5D, (double) blockpos.getY() + 0.0625D + d0, (double) blockpos.getZ() + 0.5D, this.type, itemstack, useoncontext.getPlayer()); ++ AbstractMinecart entityminecartabstract = AbstractMinecart.createMinecart(worldserver, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.0625D + d0, (double) blockposition.getZ() + 0.5D, this.type, itemstack, context.getPlayer()); + +- serverlevel.addFreshEntity(abstractminecart); +- serverlevel.gameEvent(GameEvent.ENTITY_PLACE, blockpos, GameEvent.Context.of(useoncontext.getPlayer(), serverlevel.getBlockState(blockpos.below()))); ++ // CraftBukkit start ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(context, entityminecartabstract).isCancelled()) { ++ return InteractionResult.FAIL; ++ } ++ // CraftBukkit end ++ if (!worldserver.addFreshEntity(entityminecartabstract)) return InteractionResult.PASS; // CraftBukkit ++ worldserver.gameEvent(GameEvent.ENTITY_PLACE, blockposition, GameEvent.Context.of(context.getPlayer(), worldserver.getBlockState(blockposition.below()))); + } + + itemstack.shrink(1); +- return InteractionResult.sidedSuccess(level.isClientSide); ++ return InteractionResult.sidedSuccess(world.isClientSide); + } + } + } |