3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 21:10:17 +01:00

[Bleeding] Allow custom inventory views to change their type to BREWING or ENCHANTING, and also allow them to change their title and size. Fixes BUKKIT-1190

Dieser Commit ist enthalten in:
Celtic Minstrel 2012-03-12 17:33:18 -04:00 committet von EvilSeph
Ursprung db5f804482
Commit 241cf1c664

Datei anzeigen

@ -11,8 +11,10 @@ import net.minecraft.server.Packet100OpenWindow;
import net.minecraft.server.Slot; import net.minecraft.server.Slot;
public class CraftContainer extends Container { public class CraftContainer extends Container {
InventoryView view; private InventoryView view;
InventoryType cachedType; private InventoryType cachedType;
private String cachedTitle;
private int cachedSize;
public CraftContainer(InventoryView view, int id) { public CraftContainer(InventoryView view, int id) {
this.view = view; this.view = view;
@ -21,6 +23,8 @@ public class CraftContainer extends Container {
IInventory top = ((CraftInventory)view.getTopInventory()).getInventory(); IInventory top = ((CraftInventory)view.getTopInventory()).getInventory();
IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory(); IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory();
cachedType = view.getType(); cachedType = view.getType();
cachedTitle = view.getTitle();
cachedSize = getSize();
setupSlots(top, bottom); setupSlots(top, bottom);
} }
@ -29,15 +33,21 @@ public class CraftContainer extends Container {
return view; return view;
} }
private int getSize() {
return view.getTopInventory().getSize();
}
@Override @Override
public boolean b(EntityHuman entityhuman) { public boolean b(EntityHuman entityhuman) {
if (cachedType == view.getType()) { if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) {
return true; return true;
} }
// If the window type has changed for some reason, update the player // If the window type has changed for some reason, update the player
// This method will be called every tick or something, so it's // This method will be called every tick or something, so it's
// as good a place as any to put something like this. // as good a place as any to put something like this.
boolean typeChanged = (cachedType != view.getType());
cachedType = view.getType(); cachedType = view.getType();
cachedTitle = view.getTitle();
if (view.getPlayer() instanceof CraftPlayer) { if (view.getPlayer() instanceof CraftPlayer) {
CraftPlayer player = (CraftPlayer) view.getPlayer(); CraftPlayer player = (CraftPlayer) view.getPlayer();
int type; int type;
@ -51,6 +61,12 @@ public class CraftContainer extends Container {
case DISPENSER: case DISPENSER:
type = 3; type = 3;
break; break;
case ENCHANTING:
type = 4;
break;
case BREWING:
type = 5;
break;
default: default:
type = 0; type = 0;
break; break;
@ -59,8 +75,11 @@ public class CraftContainer extends Container {
IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory(); IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory();
this.d.clear(); this.d.clear();
this.e.clear(); this.e.clear();
setupSlots(top, bottom); if (typeChanged) {
player.getHandle().netServerHandler.sendPacket(new Packet100OpenWindow(this.windowId, type, "Crafting", 9)); setupSlots(top, bottom);
}
int size = getSize();
player.getHandle().netServerHandler.sendPacket(new Packet100OpenWindow(this.windowId, type, cachedTitle, size));
player.updateInventory(); player.updateInventory();
} }
return true; return true;