mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 02:55:47 +01:00
SPIGOT-4871: Manually opened double chest doesn't have close animation
This commit is contained in:
parent
8deeeec0ac
commit
84400e66b8
@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.block;
|
||||
import net.minecraft.server.BlockChest;
|
||||
import net.minecraft.server.Blocks;
|
||||
import net.minecraft.server.ITileInventory;
|
||||
import net.minecraft.server.InventoryLargeChest;
|
||||
import net.minecraft.server.TileEntityChest;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -51,7 +50,7 @@ public class CraftChest extends CraftLootable<TileEntityChest> implements Chest
|
||||
ITileInventory nms = blockChest.getInventory(data, world.getHandle(), this.getPosition());
|
||||
|
||||
if (nms instanceof BlockChest.DoubleInventory) {
|
||||
inventory = new CraftInventoryDoubleChest(((BlockChest.DoubleInventory) nms).inventorylargechest);
|
||||
inventory = new CraftInventoryDoubleChest((BlockChest.DoubleInventory) nms);
|
||||
}
|
||||
return inventory;
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftContainer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
@ -319,7 +320,15 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
InventoryType type = inventory.getType();
|
||||
Container formerContainer = getHandle().activeContainer;
|
||||
|
||||
IInventory iinventory = (inventory instanceof CraftInventory) ? ((CraftInventory) inventory).getInventory() : new org.bukkit.craftbukkit.inventory.InventoryWrapper(inventory);
|
||||
ITileInventory iinventory = null;
|
||||
if (inventory instanceof CraftInventoryDoubleChest) {
|
||||
iinventory = ((CraftInventoryDoubleChest) inventory).tile;
|
||||
} else if (inventory instanceof CraftInventory) {
|
||||
CraftInventory craft = (CraftInventory) inventory;
|
||||
if (craft.getInventory() instanceof ITileInventory) {
|
||||
iinventory = (ITileInventory) craft.getInventory();
|
||||
}
|
||||
}
|
||||
|
||||
if (iinventory instanceof ITileInventory) {
|
||||
if (iinventory instanceof TileEntity) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import net.minecraft.server.BlockChest;
|
||||
import net.minecraft.server.ITileInventory;
|
||||
import net.minecraft.server.InventoryLargeChest;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
@ -8,13 +10,15 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CraftInventoryDoubleChest extends CraftInventory implements DoubleChestInventory {
|
||||
public ITileInventory tile;
|
||||
private final CraftInventory left;
|
||||
private final CraftInventory right;
|
||||
|
||||
public CraftInventoryDoubleChest(CraftInventory left, CraftInventory right) {
|
||||
super(new InventoryLargeChest(left.getInventory(), right.getInventory()));
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
public CraftInventoryDoubleChest(BlockChest.DoubleInventory block) {
|
||||
super(block.inventorylargechest);
|
||||
this.tile = block;
|
||||
this.left = new CraftInventory(block.inventorylargechest.left);
|
||||
this.right = new CraftInventory(block.inventorylargechest.right);
|
||||
}
|
||||
|
||||
public CraftInventoryDoubleChest(InventoryLargeChest largeChest) {
|
||||
|
@ -1,155 +0,0 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.server.EntityHuman;
|
||||
import net.minecraft.server.IInventory;
|
||||
import net.minecraft.server.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class InventoryWrapper implements IInventory {
|
||||
|
||||
private final Inventory inventory;
|
||||
private final List<HumanEntity> viewers = new ArrayList<HumanEntity>();
|
||||
|
||||
public InventoryWrapper(Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return inventory.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
return CraftItemStack.asNMSCopy(inventory.getItem(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
// Copied from CraftItemStack
|
||||
ItemStack stack = getItem(i);
|
||||
ItemStack result;
|
||||
if (stack.isEmpty()) {
|
||||
return stack;
|
||||
}
|
||||
if (stack.getCount() <= j) {
|
||||
this.setItem(i, ItemStack.a);
|
||||
result = stack;
|
||||
} else {
|
||||
result = CraftItemStack.copyNMSStack(stack, j);
|
||||
stack.subtract(j);
|
||||
}
|
||||
this.update();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
// Copied from CraftItemStack
|
||||
ItemStack stack = getItem(i);
|
||||
ItemStack result;
|
||||
if (stack.isEmpty()) {
|
||||
return stack;
|
||||
}
|
||||
if (stack.getCount() <= 1) {
|
||||
this.setItem(i, ItemStack.a);
|
||||
result = stack;
|
||||
} else {
|
||||
result = CraftItemStack.copyNMSStack(stack, 1);
|
||||
stack.subtract(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
inventory.setItem(i, CraftItemStack.asBukkitCopy(itemstack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return inventory.getMaxStackSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startOpen(EntityHuman entityhuman) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeContainer(EntityHuman entityhuman) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean b(int i, ItemStack itemstack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getContents() {
|
||||
int size = getSize();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
items.add(getItem(i));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
viewers.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
viewers.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return viewers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return inventory.getHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
inventory.setMaxStackSize(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return inventory.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNotEmpty() {
|
||||
return Iterables.any(inventory, Predicates.notNull());
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.junit.Test;
|
||||
|
||||
public class InventoryWrapperTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Inventory raw = new CraftInventoryCustom(null, 27);
|
||||
raw.addItem(new ItemStack(Material.STONE));
|
||||
|
||||
Assert.assertTrue(raw.contains(Material.STONE));
|
||||
|
||||
InventoryWrapper wrapper = new InventoryWrapper(raw);
|
||||
CraftInventory proxy = new CraftInventory(wrapper);
|
||||
|
||||
Assert.assertTrue(proxy.contains(Material.STONE));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user