3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-24 15:20:11 +01:00
Paper/src/main/java/net/minecraft/server/ContainerHopper.java

86 Zeilen
2.4 KiB
Java

2013-03-13 23:33:27 +01:00
package net.minecraft.server;
// CraftBukkit start
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
// CraftBukkit end
public class ContainerHopper extends Container {
2013-04-27 11:40:05 +02:00
private final IInventory hopper;
2013-03-13 23:33:27 +01:00
// CraftBukkit start
private CraftInventoryView bukkitEntity = null;
private PlayerInventory player;
public CraftInventoryView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}
2013-04-27 11:40:05 +02:00
CraftInventory inventory = new CraftInventory(this.hopper);
2013-03-13 23:33:27 +01:00
bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
return bukkitEntity;
}
// CraftBukkit end
public ContainerHopper(PlayerInventory playerinventory, IInventory iinventory) {
2013-04-27 11:40:05 +02:00
this.hopper = iinventory;
2013-03-13 23:33:27 +01:00
this.player = playerinventory; // CraftBukkit - save player
iinventory.startOpen();
byte b0 = 51;
int i;
for (i = 0; i < iinventory.getSize(); ++i) {
this.a(new Slot(iinventory, i, 44 + i * 18, 20));
}
for (i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.a(new Slot(playerinventory, j + i * 9 + 9, 8 + j * 18, i * 18 + b0));
}
}
for (i = 0; i < 9; ++i) {
this.a(new Slot(playerinventory, i, 8 + i * 18, 58 + b0));
}
}
public boolean a(EntityHuman entityhuman) {
if (!this.checkReachable) return true; // CraftBukkit
2013-04-27 11:40:05 +02:00
return this.hopper.a(entityhuman);
2013-03-13 23:33:27 +01:00
}
public ItemStack b(EntityHuman entityhuman, int i) {
ItemStack itemstack = null;
Slot slot = (Slot) this.c.get(i);
2013-07-01 13:03:00 +02:00
if (slot != null && slot.e()) {
2013-03-13 23:33:27 +01:00
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.cloneItemStack();
2013-04-27 11:40:05 +02:00
if (i < this.hopper.getSize()) {
if (!this.a(itemstack1, this.hopper.getSize(), this.c.size(), true)) {
2013-03-13 23:33:27 +01:00
return null;
}
2013-04-27 11:40:05 +02:00
} else if (!this.a(itemstack1, 0, this.hopper.getSize(), false)) {
2013-03-13 23:33:27 +01:00
return null;
}
if (itemstack1.count == 0) {
slot.set((ItemStack) null);
} else {
2013-07-01 13:03:00 +02:00
slot.f();
2013-03-13 23:33:27 +01:00
}
}
return itemstack;
}
public void b(EntityHuman entityhuman) {
super.b(entityhuman);
2013-04-27 11:40:05 +02:00
this.hopper.g();
2013-03-13 23:33:27 +01:00
}
}