aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/item/MinecartItem.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/item/MinecartItem.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/world/item/MinecartItem.java.patch217
1 files changed, 217 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/item/MinecartItem.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/item/MinecartItem.java.patch
new file mode 100644
index 0000000000..a46e0e5dde
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/world/item/MinecartItem.java.patch
@@ -0,0 +1,217 @@
+--- a/net/minecraft/world/item/MinecartItem.java
++++ b/net/minecraft/world/item/MinecartItem.java
+@@ -2,118 +2,149 @@
+
+ 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;
++import net.minecraft.world.entity.player.Player;
+ import net.minecraft.world.entity.vehicle.AbstractMinecart;
+ import net.minecraft.world.item.context.UseOnContext;
+ 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 {
++
+ private static final DispenseItemBehavior DISPENSE_ITEM_BEHAVIOR = new DefaultDispenseItemBehavior() {
+ private final DefaultDispenseItemBehavior defaultDispenseItemBehavior = new DefaultDispenseItemBehavior();
+
+ @Override
+- public ItemStack execute(BlockSource blockSource, ItemStack itemStack) {
+- Direction direction = blockSource.state().getValue(DispenserBlock.FACING);
+- ServerLevel serverLevel = blockSource.level();
+- Vec3 vec3 = blockSource.center();
+- double d = vec3.x() + (double)direction.getStepX() * 1.125;
+- double d1 = Math.floor(vec3.y()) + (double)direction.getStepY();
+- double d2 = vec3.z() + (double)direction.getStepZ() * 1.125;
+- BlockPos blockPos = blockSource.pos().relative(direction);
+- BlockState blockState = serverLevel.getBlockState(blockPos);
+- RailShape railShape = blockState.getBlock() instanceof BaseRailBlock
+- ? 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()) {
+- d3 = 0.6;
++
++ if (iblockdata.is(BlockTags.RAILS)) {
++ if (blockpropertytrackposition.isAscending()) {
++ d3 = 0.6D;
+ } else {
+- d3 = 0.1;
++ 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
+- ? blockState1.getValue(((BaseRailBlock)blockState1.getBlock()).getShapeProperty())
+- : RailShape.NORTH_SOUTH;
+- if (direction != Direction.DOWN && railShape1.isAscending()) {
+- d3 = -0.4;
++ IBlockData iblockdata1 = worldserver.getBlockState(blockposition.below());
++ RailShape blockpropertytrackposition1 = iblockdata1.getBlock() instanceof BaseRailBlock ? (RailShape) iblockdata1.getValue(((BaseRailBlock) iblockdata1.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
++
++ if (enumdirection != Direction.DOWN && blockpropertytrackposition1.isAscending()) {
++ d3 = -0.4D;
+ } else {
+- d3 = -0.9;
++ d3 = -0.9D;
+ }
+ }
+
+- AbstractMinecart abstractMinecart = AbstractMinecart.createMinecart(
+- serverLevel, d, d1 + d3, d2, ((MinecartItem)itemStack.getItem()).type, itemStack, null
+- );
+- serverLevel.addFreshEntity(abstractMinecart);
+- itemStack.shrink(1);
+- return itemStack;
++ // 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);
++
++ 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
+- 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 type, Item.Properties properties) {
++ public MinecartItem(AbstractMinecart.EnumMinecartType type, Item.Properties properties) {
+ super(properties);
+ this.type = type;
+- DispenserBlock.registerBehavior(this, DISPENSE_ITEM_BEHAVIOR);
++ DispenserBlock.registerBehavior(this, MinecartItem.DISPENSE_ITEM_BEHAVIOR);
+ }
+
+ @Override
+ public InteractionResult useOn(UseOnContext context) {
+- Level level = context.getLevel();
+- BlockPos clickedPos = context.getClickedPos();
+- BlockState blockState = level.getBlockState(clickedPos);
+- if (!blockState.is(BlockTags.RAILS)) {
++ Level world = context.getLevel();
++ BlockPos blockposition = context.getClickedPos();
++ IBlockData iblockdata = world.getBlockState(blockposition);
++
++ if (!iblockdata.is(BlockTags.RAILS)) {
+ return InteractionResult.FAIL;
+ } else {
+- ItemStack itemInHand = context.getItemInHand();
+- if (level instanceof ServerLevel serverLevel) {
+- RailShape railShape = blockState.getBlock() instanceof BaseRailBlock
+- ? blockState.getValue(((BaseRailBlock)blockState.getBlock()).getShapeProperty())
+- : RailShape.NORTH_SOUTH;
+- double d = 0.0;
+- if (railShape.isAscending()) {
+- d = 0.5;
++ ItemStack itemstack = context.getItemInHand();
++
++ 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 (blockpropertytrackposition.isAscending()) {
++ d0 = 0.5D;
+ }
+
+- AbstractMinecart abstractMinecart = AbstractMinecart.createMinecart(
+- serverLevel,
+- (double)clickedPos.getX() + 0.5,
+- (double)clickedPos.getY() + 0.0625 + d,
+- (double)clickedPos.getZ() + 0.5,
+- this.type,
+- itemInHand,
+- context.getPlayer()
+- );
+- serverLevel.addFreshEntity(abstractMinecart);
+- serverLevel.gameEvent(
+- GameEvent.ENTITY_PLACE, clickedPos, GameEvent.Context.of(context.getPlayer(), serverLevel.getBlockState(clickedPos.below()))
+- );
++ 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());
++
++ // 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())));
+ }
+
+- itemInHand.shrink(1);
+- return InteractionResult.sidedSuccess(level.isClientSide);
++ itemstack.shrink(1);
++ return InteractionResult.sidedSuccess(world.isClientSide);
+ }
+ }
+ }