PaperMC/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartContainer.patch
2024-02-21 20:55:34 +11:00

96 lines
3.1 KiB
Diff

--- a/net/minecraft/world/entity/vehicle/EntityMinecartContainer.java
+++ b/net/minecraft/world/entity/vehicle/EntityMinecartContainer.java
@@ -18,6 +18,15 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.World;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
public abstract class EntityMinecartContainer extends EntityMinecartAbstract implements ContainerEntity {
private NonNullList<ItemStack> itemStacks;
@@ -25,14 +34,55 @@
public MinecraftKey lootTable;
public long lootTableSeed;
+ // CraftBukkit start
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+ private int maxStack = MAX_STACK;
+
+ public List<ItemStack> getContents() {
+ return this.itemStacks;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public InventoryHolder getOwner() {
+ org.bukkit.entity.Entity cart = getBukkitEntity();
+ if(cart instanceof InventoryHolder) return (InventoryHolder) cart;
+ return null;
+ }
+
+ @Override
+ public int getMaxStackSize() {
+ return maxStack;
+ }
+
+ public void setMaxStackSize(int size) {
+ maxStack = size;
+ }
+
+ @Override
+ public Location getLocation() {
+ return getBukkitEntity().getLocation();
+ }
+ // CraftBukkit end
+
protected EntityMinecartContainer(EntityTypes<?> entitytypes, World world) {
super(entitytypes, world);
- this.itemStacks = NonNullList.withSize(36, ItemStack.EMPTY);
+ this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); // CraftBukkit - SPIGOT-3513
}
protected EntityMinecartContainer(EntityTypes<?> entitytypes, double d0, double d1, double d2, World world) {
super(entitytypes, world, d0, d1, d2);
- this.itemStacks = NonNullList.withSize(36, ItemStack.EMPTY);
+ this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); // CraftBukkit - SPIGOT-3513
}
@Override
@@ -76,11 +126,18 @@
@Override
public void remove(Entity.RemovalReason entity_removalreason) {
+ // CraftBukkit start - add Bukkit remove cause
+ this.remove(entity_removalreason, null);
+ }
+
+ @Override
+ public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
+ // CraftBukkit end
if (!this.level().isClientSide && entity_removalreason.shouldDestroy()) {
InventoryUtils.dropContents(this.level(), (Entity) this, (IInventory) this);
}
- super.remove(entity_removalreason);
+ super.remove(entity_removalreason, cause); // CraftBukkit - add Bukkit remove cause
}
@Override