Package net.minecraft.screen
Class ScreenHandler
java.lang.Object
net.minecraft.screen.ScreenHandler
- Direct Known Subclasses:
AbstractRecipeScreenHandler,BeaconScreenHandler,BrewingStandScreenHandler,CartographyTableScreenHandler,CreativeInventoryScreen.CreativeScreenHandler,EnchantmentScreenHandler,ForgingScreenHandler,Generic3x3ContainerScreenHandler,GenericContainerScreenHandler,GrindstoneScreenHandler,HopperScreenHandler,HorseScreenHandler,LecternScreenHandler,LoomScreenHandler,MerchantScreenHandler,ShulkerBoxScreenHandler,StonecutterScreenHandler
public abstract class ScreenHandler extends Object
-
Field Summary
Fields Modifier and Type Field Description private shortactionIdprivate List<ScreenHandlerListener>listenersprivate List<Property>propertiesprivate intquickCraftButtonprivate Set<Slot>quickCraftSlotsprivate intquickCraftStageprivate Set<PlayerEntity>restrictedPlayersDefaultedList<Slot>slotsintsyncIdprivate DefaultedList<ItemStack>trackedStacksA list of item stacks that is used for tracking changes insendContentUpdates().private ScreenHandlerType<?>type -
Constructor Summary
Constructors Modifier Constructor Description protectedScreenHandler(ScreenHandlerType<?> type, int syncId) -
Method Summary
Modifier and Type Method Description voidaddListener(ScreenHandlerListener listener)protected voidaddProperties(PropertyDelegate propertyDelegate)protected PropertyaddProperty(Property property)protected SlotaddSlot(Slot slot)static intcalculateComparatorOutput(BlockEntity entity)static intcalculateComparatorOutput(Inventory inventory)static voidcalculateStackSize(Set<Slot> slots, int mode, ItemStack stack, int stackSize)booleancanInsertIntoSlot(ItemStack stack, Slot slot)booleancanInsertIntoSlot(Slot slot)static booleancanInsertItemIntoSlot(Slot slot, ItemStack stack, boolean allowOverflow)abstract booleancanUse(PlayerEntity player)protected static booleancanUse(ScreenHandlerContext context, PlayerEntity player, Block block)protected static voidcheckDataCount(PropertyDelegate data, int expectedCount)Checks that the size of thedatais at least as large as theexpectedCount.protected static voidcheckSize(Inventory inventory, int expectedSize)Checks that the size of the provided inventory is at least as large as theexpectedSize.voidclose(PlayerEntity player)protected voiddropInventory(PlayerEntity player, Inventory inventory)protected voidendQuickCraft()shortgetNextActionId(PlayerInventory playerInventory)SlotgetSlot(int index)DefaultedList<ItemStack>getStacks()ScreenHandlerType<?>getType()protected booleaninsertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast)booleanisNotRestricted(PlayerEntity player)booleanonButtonClick(PlayerEntity player, int id)voidonContentChanged(Inventory inventory)ItemStackonSlotClick(int slotIndex, int clickData, SlotActionType actionType, PlayerEntity player)Performs a slot click.static intpackQuickCraftData(int quickCraftStage, int buttonId)voidremoveListener(ScreenHandlerListener listener)private ItemStackremoveStack(int slotIndex, int clickData, SlotActionType actionType, PlayerEntity player)voidsendContentUpdates()Sends updates to listeners if any properties or slot stacks have changed.voidsetPlayerRestriction(PlayerEntity player, boolean unrestricted)voidsetProperty(int id, int value)voidsetStackInSlot(int slot, ItemStack stack)static booleanshouldQuickCraftContinue(int stage, PlayerEntity player)ItemStacktransferSlot(PlayerEntity player, int index)static intunpackQuickCraftButton(int quickCraftData)static intunpackQuickCraftStage(int quickCraftData)voidupdateSlotStacks(List<ItemStack> stacks)
-
Field Details
-
trackedStacks
A list of item stacks that is used for tracking changes insendContentUpdates(). -
slots
-
properties
-
type
-
syncId
public final int syncId -
actionId
@Environment(CLIENT) private short actionId -
quickCraftStage
private int quickCraftStage -
quickCraftButton
private int quickCraftButton -
quickCraftSlots
-
listeners
-
restrictedPlayers
-
-
Constructor Details
-
ScreenHandler
-
-
Method Details
-
canUse
-
getType
-
checkSize
Checks that the size of the provided inventory is at least as large as theexpectedSize.- Throws:
IllegalArgumentException- if the inventory size is smaller thanexpectedSize
-
checkDataCount
Checks that the size of thedatais at least as large as theexpectedCount.- Throws:
IllegalArgumentException- if thedatahas a smaller size thanexpectedCount
-
addSlot
-
addProperty
-
addProperties
-
addListener
-
removeListener
-
getStacks
-
sendContentUpdates
public void sendContentUpdates()Sends updates to listeners if any properties or slot stacks have changed. -
onButtonClick
-
getSlot
-
transferSlot
-
onSlotClick
public ItemStack onSlotClick(int slotIndex, int clickData, SlotActionType actionType, PlayerEntity player)Performs a slot click. This can behave in many different ways depending mainly on the action type.- Parameters:
actionType- The type of slot click. Check the docs for each SlotActionType value for details- Returns:
- The stack that was clicked on before anything changed, used mostly for verifying that the client and server are in sync
-
removeStack
private ItemStack removeStack(int slotIndex, int clickData, SlotActionType actionType, PlayerEntity player) -
canInsertIntoSlot
-
close
-
dropInventory
-
onContentChanged
-
setStackInSlot
-
updateSlotStacks
-
setProperty
public void setProperty(int id, int value) -
getNextActionId
-
isNotRestricted
-
setPlayerRestriction
-
canUse
-
insertItem
-
unpackQuickCraftButton
public static int unpackQuickCraftButton(int quickCraftData) -
unpackQuickCraftStage
public static int unpackQuickCraftStage(int quickCraftData) -
packQuickCraftData
@Environment(CLIENT) public static int packQuickCraftData(int quickCraftStage, int buttonId) -
shouldQuickCraftContinue
-
endQuickCraft
protected void endQuickCraft() -
canInsertItemIntoSlot
-
calculateStackSize
-
canInsertIntoSlot
-
calculateComparatorOutput
-
calculateComparatorOutput
-