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