2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/item/ItemMinecart.java
|
|
|
|
+++ b/net/minecraft/world/item/ItemMinecart.java
|
2023-09-21 18:40:00 +02:00
|
|
|
@@ -18,6 +18,12 @@
|
2021-06-11 07:00:00 +02:00
|
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
2023-09-21 18:40:00 +02:00
|
|
|
import net.minecraft.world.phys.Vec3D;
|
2015-02-26 23:41:06 +01:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
2023-09-21 18:40:00 +02:00
|
|
|
+import org.bukkit.craftbukkit.block.CraftBlock;
|
2015-02-26 23:41:06 +01:00
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
|
|
+import org.bukkit.event.block.BlockDispenseEvent;
|
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
|
|
|
public class ItemMinecart extends Item {
|
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
private static final IDispenseBehavior DISPENSE_ITEM_BEHAVIOR = new DispenseBehaviorItem() {
|
2023-09-21 18:40:00 +02:00
|
|
|
@@ -57,14 +63,43 @@
|
2015-02-26 23:41:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, d0, d1 + d3, d2, ((ItemMinecart) itemstack.getItem()).type);
|
2015-02-26 23:41:06 +01:00
|
|
|
+ // CraftBukkit start
|
2021-11-21 23:00:00 +01:00
|
|
|
+ // EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, d0, d1 + d3, d2, ((ItemMinecart) itemstack.getItem()).type);
|
|
|
|
+ ItemStack itemstack1 = itemstack.split(1);
|
2023-09-21 18:40:00 +02:00
|
|
|
+ org.bukkit.block.Block block2 = CraftBlock.at(worldserver, sourceblock.pos());
|
2015-02-26 23:41:06 +01:00
|
|
|
+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
|
|
|
|
+
|
|
|
|
+ BlockDispenseEvent event = new BlockDispenseEvent(block2, craftItem.clone(), new org.bukkit.util.Vector(d0, d1 + d3, d2));
|
|
|
|
+ if (!BlockDispenser.eventFired) {
|
2021-06-11 13:33:49 +02:00
|
|
|
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
|
2015-02-26 23:41:06 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (event.isCancelled()) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ itemstack.grow(1);
|
2015-02-26 23:41:06 +01:00
|
|
|
+ return itemstack;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!event.getItem().equals(craftItem)) {
|
2021-11-21 23:00:00 +01:00
|
|
|
+ itemstack.grow(1);
|
2015-02-26 23:41:06 +01:00
|
|
|
+ // Chain to handler for new item
|
|
|
|
+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
|
2021-06-11 07:00:00 +02:00
|
|
|
+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem());
|
|
|
|
+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) {
|
2023-09-21 18:40:00 +02:00
|
|
|
+ idispensebehavior.dispense(sourceblock, eventStack);
|
2015-02-26 23:41:06 +01:00
|
|
|
+ return itemstack;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ itemstack1 = CraftItemStack.asNMSCopy(event.getItem());
|
2021-11-21 23:00:00 +01:00
|
|
|
+ EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), ((ItemMinecart) itemstack1.getItem()).type);
|
2015-02-26 23:41:06 +01:00
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
if (itemstack.hasCustomHoverName()) {
|
|
|
|
entityminecartabstract.setCustomName(itemstack.getHoverName());
|
2015-02-26 23:41:06 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- worldserver.addFreshEntity(entityminecartabstract);
|
|
|
|
- itemstack.shrink(1);
|
|
|
|
+ if (!worldserver.addFreshEntity(entityminecartabstract)) itemstack.grow(1);
|
|
|
|
+ // itemstack.shrink(1); // CraftBukkit - handled during event processing
|
2015-02-26 23:41:06 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:40:00 +02:00
|
|
|
@@ -106,7 +141,12 @@
|
2021-11-21 23:00:00 +01:00
|
|
|
entityminecartabstract.setCustomName(itemstack.getHoverName());
|
2017-03-21 23:03:20 +01:00
|
|
|
}
|
|
|
|
|
2021-11-21 23:00:00 +01:00
|
|
|
- world.addFreshEntity(entityminecartabstract);
|
2018-12-27 00:45:36 +01:00
|
|
|
+ // CraftBukkit start
|
|
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(itemactioncontext, entityminecartabstract).isCancelled()) {
|
|
|
|
+ return EnumInteractionResult.FAIL;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
+ if (!world.addFreshEntity(entityminecartabstract)) return EnumInteractionResult.PASS; // CraftBukkit
|
2022-06-07 18:00:00 +02:00
|
|
|
world.gameEvent(GameEvent.ENTITY_PLACE, blockposition, GameEvent.a.of(itemactioncontext.getPlayer(), world.getBlockState(blockposition.below())));
|
2017-03-21 23:03:20 +01:00
|
|
|
}
|
|
|
|
|