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 short
actionId
private List<ScreenHandlerListener>
listeners
private List<Property>
properties
private int
quickCraftButton
private Set<Slot>
quickCraftSlots
private int
quickCraftStage
private Set<PlayerEntity>
restrictedPlayers
List<Slot>
slots
int
syncId
private DefaultedList<ItemStack>
trackedStacks
A list of item stacks that is used for tracking changes insendContentUpdates()
.private ScreenHandlerType<?>
type
-
Constructor Summary
Constructors Modifier Constructor Description protected
ScreenHandler(ScreenHandlerType<?> type, int syncId)
-
Method Summary
Modifier and Type Method Description void
addListener(ScreenHandlerListener listener)
protected void
addProperties(PropertyDelegate propertyDelegate)
protected Property
addProperty(Property property)
protected Slot
addSlot(Slot slot)
static int
calculateComparatorOutput(BlockEntity entity)
static int
calculateComparatorOutput(Inventory inventory)
static void
calculateStackSize(Set<Slot> slots, int mode, ItemStack stack, int stackSize)
boolean
canInsertIntoSlot(ItemStack stack, Slot slot)
boolean
canInsertIntoSlot(Slot slot)
static boolean
canInsertItemIntoSlot(Slot slot, ItemStack stack, boolean allowOverflow)
static boolean
canStacksCombine(ItemStack first, ItemStack second)
abstract boolean
canUse(PlayerEntity player)
protected static boolean
canUse(ScreenHandlerContext context, PlayerEntity player, Block block)
protected static void
checkDataCount(PropertyDelegate data, int expectedCount)
Checks that the size of thedata
is at least as large as theexpectedCount
.protected static void
checkSize(Inventory inventory, int expectedSize)
Checks that the size of the provided inventory is at least as large as theexpectedSize
.void
close(PlayerEntity player)
protected void
dropInventory(PlayerEntity player, World world, Inventory inventory)
protected void
endQuickCraft()
short
getNextActionId(PlayerInventory playerInventory)
Slot
getSlot(int index)
DefaultedList<ItemStack>
getStacks()
ScreenHandlerType<?>
getType()
protected boolean
insertItem(ItemStack stack, int startIndex, int endIndex, boolean fromLast)
boolean
isNotRestricted(PlayerEntity player)
private ItemStack
method_30010(int int2, int int3, SlotActionType slotActionType, PlayerEntity playerEntity)
boolean
onButtonClick(PlayerEntity player, int id)
void
onContentChanged(Inventory inventory)
ItemStack
onSlotClick(int int2, int int3, SlotActionType actionType, PlayerEntity playerEntity)
Performs a slot click.static int
packQuickCraftData(int quickCraftStage, int buttonId)
void
removeListener(ScreenHandlerListener listener)
void
sendContentUpdates()
Sends updates to listeners if any properties or slot stacks have changed.void
setPlayerRestriction(PlayerEntity player, boolean unrestricted)
void
setProperty(int id, int value)
void
setStackInSlot(int slot, ItemStack stack)
static boolean
shouldQuickCraftContinue(int stage, PlayerEntity player)
ItemStack
transferSlot(PlayerEntity player, int index)
static int
unpackQuickCraftButton(int quickCraftData)
static int
unpackQuickCraftStage(int quickCraftData)
void
updateSlotStacks(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 thedata
is at least as large as theexpectedCount
.- Throws:
IllegalArgumentException
- if thedata
has 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 int2, int int3, SlotActionType actionType, PlayerEntity playerEntity)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
-
method_30010
private ItemStack method_30010(int int2, int int3, SlotActionType slotActionType, PlayerEntity playerEntity) -
canStacksCombine
-
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
-