Class ContainerExtended
java.lang.Object
net.minecraft.world.inventory.AbstractContainerMenu
org.cyclops.cyclopscore.inventory.container.ContainerExtended
- All Implemented Interfaces:
IContainerButtonClickAcceptorServer<ContainerExtended>
,IValueNotifiable
,IValueNotifier
- Direct Known Subclasses:
InventoryContainer
,ItemInventoryContainer
public abstract class ContainerExtended
extends net.minecraft.world.inventory.AbstractContainerMenu
implements IContainerButtonClickAcceptorServer<ContainerExtended>, IValueNotifier, IValueNotifiable
A container with inventory.
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
protected int
protected int
protected final net.minecraft.world.entity.player.Player
Fields inherited from class net.minecraft.world.inventory.AbstractContainerMenu
CARRIED_SLOT_SIZE, containerId, QUICKCRAFT_HEADER_CONTINUE, QUICKCRAFT_HEADER_END, QUICKCRAFT_HEADER_START, QUICKCRAFT_TYPE_CHARITABLE, QUICKCRAFT_TYPE_CLONE, QUICKCRAFT_TYPE_GREEDY, SLOT_CLICKED_OUTSIDE, slots
-
Constructor Summary
ConstructorDescriptionContainerExtended
(net.minecraft.world.inventory.MenuType<?> type, int id, net.minecraft.world.entity.player.Inventory inventory) Make a new ContainerExtended. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addInventory
(net.minecraft.world.Container inventory, int indexOffset, int offsetX, int offsetY, int rows, int cols) protected void
addPlayerArmorInventory
(net.minecraft.world.entity.player.Inventory inventory, int offsetX, int offsetY) Add player armor inventory to the GUI.protected void
addPlayerInventory
(net.minecraft.world.entity.player.Inventory inventory, int offsetX, int offsetY) Add player inventory and hotbar to the GUI.protected net.minecraft.world.inventory.Slot
addSlot
(net.minecraft.world.inventory.Slot slot) void
addSlotListener
(net.minecraft.world.inventory.ContainerListener listener) protected void
adjustPhantomSlot
(net.minecraft.world.inventory.Slot slot, int mouseButton, net.minecraft.world.inventory.ClickType clickType) void
void
clicked
(int slotId, int dragType, net.minecraft.world.inventory.ClickType clickType, net.minecraft.world.entity.player.Player player) protected net.minecraft.world.inventory.Slot
createNewSlot
(net.minecraft.world.Container inventory, int index, int x, int y) protected void
fillPhantomSlot
(net.minecraft.world.inventory.Slot slot, net.minecraft.world.item.ItemStack stackHeld, int mouseButton, net.minecraft.world.inventory.ClickType clickType) protected int
net.minecraft.world.entity.player.Inventory
Get the inventory of the player for which this container is instantiated.protected abstract int
protected int
getSlotRange
(int originSlot, int slotRange, boolean reverse) protected int
getSlotStart
(int originSlot, int slotStart, boolean reverse) net.minecraft.nbt.CompoundTag
getValue
(int valueId) Get the value for the given value id.net.minecraft.world.inventory.MenuType<?>
protected void
This is the place to initialize values server-side so that they can be sent to the client for the first time.protected boolean
moveItemStackTo
(net.minecraft.world.item.ItemStack stack, int slotStart, int slotRange, boolean reverse) boolean
onButtonClick
(String buttonId) When the button is clicked, both server and client side.void
onUpdate
(int valueId, net.minecraft.nbt.CompoundTag value) Called by the server if the value has changed.void
putButtonAction
(String buttonId, IContainerButtonAction<ContainerExtended> action) Set a button action.net.minecraft.world.item.ItemStack
quickMoveStack
(net.minecraft.world.entity.player.Player player, int slotID) <T> Supplier<T>
registerSyncedVariable
(Class<T> clazz, Supplier<T> serverValueSupplier) Register the given variable for automatically sychronizing between client and server.protected void
void
setGuiValueListener
(IValueNotifiable listener) Set the listener that will be triggered when a value in this container is updated by the server.static void
setSlotPosX
(net.minecraft.world.inventory.Slot slot, int newValue) static void
setSlotPosY
(net.minecraft.world.inventory.Slot slot, int newValue) void
setValue
(int valueId, net.minecraft.nbt.CompoundTag value) Set the value for given value id.Methods inherited from class net.minecraft.world.inventory.AbstractContainerMenu
addDataSlot, addDataSlots, broadcastFullState, canDragTo, canItemQuickReplace, canTakeItemForPickAll, checkContainerDataCount, checkContainerSize, clearContainer, clickMenuButton, createCarriedSlotAccess, findSlot, getCarried, getItems, getQuickcraftHeader, getQuickcraftMask, getQuickCraftPlaceCount, getQuickcraftType, getRedstoneSignalFromBlockEntity, getRedstoneSignalFromContainer, getSlot, getStateId, getType, incrementStateId, initializeContents, isValidQuickcraftType, isValidSlotIndex, removed, removeSlotListener, resumeRemoteUpdates, sendAllDataToRemote, setCarried, setData, setItem, setRemoteCarried, setRemoteSlot, setRemoteSlotNoCopy, setSynchronizer, slotsChanged, stillValid, stillValid, suppressRemoteUpdates, transferState
-
Field Details
-
ITEMBOX
protected static final int ITEMBOX- See Also:
-
player
protected final net.minecraft.world.entity.player.Player player -
offsetX
protected int offsetX -
offsetY
protected int offsetY
-
-
Constructor Details
-
ContainerExtended
public ContainerExtended(@Nullable net.minecraft.world.inventory.MenuType<?> type, int id, net.minecraft.world.entity.player.Inventory inventory) Make a new ContainerExtended.- Parameters:
type
- The container type.id
- The container id.inventory
- The player inventory.
-
-
Method Details
-
broadcastChanges
public void broadcastChanges()- Overrides:
broadcastChanges
in classnet.minecraft.world.inventory.AbstractContainerMenu
-
setGuiValueListener
Set the listener that will be triggered when a value in this container is updated by the server.- Parameters:
listener
- The listener that will be triggered.
-
addSlotListener
public void addSlotListener(net.minecraft.world.inventory.ContainerListener listener) - Overrides:
addSlotListener
in classnet.minecraft.world.inventory.AbstractContainerMenu
-
initializeValues
protected void initializeValues()This is the place to initialize values server-side so that they can be sent to the client for the first time. This is only called on the server. Make sure not to initialize the value id's here, but do that inside the constructor, because these must be equal for client and server. -
createNewSlot
protected net.minecraft.world.inventory.Slot createNewSlot(net.minecraft.world.Container inventory, int index, int x, int y) -
setSlotPosX
public static void setSlotPosX(net.minecraft.world.inventory.Slot slot, int newValue) -
setSlotPosY
public static void setSlotPosY(net.minecraft.world.inventory.Slot slot, int newValue) -
addSlot
protected net.minecraft.world.inventory.Slot addSlot(net.minecraft.world.inventory.Slot slot) - Overrides:
addSlot
in classnet.minecraft.world.inventory.AbstractContainerMenu
-
addInventory
protected void addInventory(net.minecraft.world.Container inventory, int indexOffset, int offsetX, int offsetY, int rows, int cols) -
addPlayerInventory
protected void addPlayerInventory(net.minecraft.world.entity.player.Inventory inventory, int offsetX, int offsetY) Add player inventory and hotbar to the GUI.- Parameters:
inventory
- Inventory of the playeroffsetX
- Offset to XoffsetY
- Offset to Y
-
addPlayerArmorInventory
protected void addPlayerArmorInventory(net.minecraft.world.entity.player.Inventory inventory, int offsetX, int offsetY) Add player armor inventory to the GUI.- Parameters:
inventory
- Inventory of the playeroffsetX
- Offset to XoffsetY
- Offset to Y
-
getSizeInventory
protected abstract int getSizeInventory() -
getSlotStart
protected int getSlotStart(int originSlot, int slotStart, boolean reverse) -
getSlotRange
protected int getSlotRange(int originSlot, int slotRange, boolean reverse) -
quickMoveStack
public net.minecraft.world.item.ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int slotID) - Specified by:
quickMoveStack
in classnet.minecraft.world.inventory.AbstractContainerMenu
-
moveItemStackTo
protected boolean moveItemStackTo(net.minecraft.world.item.ItemStack stack, int slotStart, int slotRange, boolean reverse) - Overrides:
moveItemStackTo
in classnet.minecraft.world.inventory.AbstractContainerMenu
-
getPlayerIInventory
public net.minecraft.world.entity.player.Inventory getPlayerIInventory()Get the inventory of the player for which this container is instantiated.- Returns:
- The player inventory.
-
clicked
public void clicked(int slotId, int dragType, net.minecraft.world.inventory.ClickType clickType, net.minecraft.world.entity.player.Player player) - Overrides:
clicked
in classnet.minecraft.world.inventory.AbstractContainerMenu
-
resetQuickCraft
protected void resetQuickCraft()- Overrides:
resetQuickCraft
in classnet.minecraft.world.inventory.AbstractContainerMenu
-
adjustPhantomSlot
protected void adjustPhantomSlot(net.minecraft.world.inventory.Slot slot, int mouseButton, net.minecraft.world.inventory.ClickType clickType) -
fillPhantomSlot
protected void fillPhantomSlot(net.minecraft.world.inventory.Slot slot, net.minecraft.world.item.ItemStack stackHeld, int mouseButton, net.minecraft.world.inventory.ClickType clickType) -
putButtonAction
Description copied from interface:IContainerButtonClickAcceptorServer
Set a button action. The used button id should correspond to id that was used to create the button's pressable in the gui.- Specified by:
putButtonAction
in interfaceIContainerButtonClickAcceptorServer<ContainerExtended>
- Parameters:
buttonId
- The button id.action
- The action to set for the given button id.
-
onButtonClick
Description copied from interface:IContainerButtonClickAcceptorServer
When the button is clicked, both server and client side.- Specified by:
onButtonClick
in interfaceIContainerButtonClickAcceptorServer<ContainerExtended>
- Parameters:
buttonId
- The button id.- Returns:
- If an action was found and executed.
-
getNextValueId
protected int getNextValueId()- Returns:
- The next unique value id.
-
setValue
public void setValue(int valueId, net.minecraft.nbt.CompoundTag value) Description copied from interface:IValueNotifier
Set the value for given value id. This will send a packet if it has changed. If called on the client, a packet to the server will be sent. If called on the server, a packet to the client will be sent.- Specified by:
setValue
in interfaceIValueNotifier
- Parameters:
valueId
- The value id.value
- The new value.
-
getValue
public net.minecraft.nbt.CompoundTag getValue(int valueId) Description copied from interface:IValueNotifier
Get the value for the given value id.- Specified by:
getValue
in interfaceIValueNotifier
- Parameters:
valueId
- The value id.- Returns:
- The value or null.
-
getValueIds
- Specified by:
getValueIds
in interfaceIValueNotifier
- Returns:
- All available value ids.
-
getValueNotifiableType
public net.minecraft.world.inventory.MenuType<?> getValueNotifiableType()- Specified by:
getValueNotifiableType
in interfaceIValueNotifiable
- Returns:
- The container type.
-
onUpdate
public void onUpdate(int valueId, net.minecraft.nbt.CompoundTag value) Description copied from interface:IValueNotifiable
Called by the server if the value has changed.- Specified by:
onUpdate
in interfaceIValueNotifiable
- Parameters:
valueId
- The value id.value
- The new value.
-
registerSyncedVariable
Register the given variable for automatically sychronizing between client and server. This method should be called in the constructor of a container, and the resulting supplier should be stored. This resulting supplier can be called at any time by the client to lookup values.- Type Parameters:
T
- The variable type.- Parameters:
clazz
- The class of the variable to sync.serverValueSupplier
- A supplier for the server-side variable value.- Returns:
- A supplier that can be called for retrieving the value.
-