Class ExtendedScreenHandlerType<T extends ScreenHandler,D>
java.lang.Object
net.minecraft.screen.ScreenHandlerType<T>
net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType<T,D>
- Type Parameters:
T
- the type of screen handler created by this typeD
- the type of the data
- All Implemented Interfaces:
ToggleableFeature
A
ScreenHandlerType
for an extended screen handler that
synchronizes additional data to the client when it is opened.
Extended screen handlers can be opened using
PlayerEntity.openHandledScreen
with an
ExtendedScreenHandlerFactory
.
Example
// Data class
public record OvenData(String label) {
public static final PacketCodec<RegistryByteBuf, OvenData> PACKET_CODEC = PacketCodec.tuple(
PacketCodecs.STRING,
OvenData::label,
OvenData::new
);
}
// Creating and registering the type
public static final ExtendedScreenHandlerType<OvenScreenHandler> OVEN =
new ExtendedScreenHandlerType((syncId, inventory, data) -> ..., OvenData.PACKET_CODEC);
Registry.register(Registry.SCREEN_HANDLER, Identifier.of(...), OVEN);
// Note: remember to also register the screen using vanilla's HandledScreens!
// Screen handler class
public class OvenScreenHandler extends ScreenHandler {
public OvenScreenHandler(int syncId) {
super(MyScreenHandlers.OVEN, syncId);
}
}
// Opening the extended screen handler
var factory = new ExtendedScreenHandlerFactory() {
...
};
player.openHandlerScreen(factory); // only works on ServerPlayerEntity instances
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A factory for creating screen handler instances from additional opening data. -
Field Summary
Fields inherited from class net.minecraft.screen.ScreenHandlerType
ANVIL, BEACON, BLAST_FURNACE, BREWING_STAND, CARTOGRAPHY_TABLE, CRAFTER_3X3, CRAFTING, ENCHANTMENT, FURNACE, GENERIC_3X3, GENERIC_9X1, GENERIC_9X2, GENERIC_9X3, GENERIC_9X4, GENERIC_9X5, GENERIC_9X6, GRINDSTONE, HOPPER, LECTERN, LOOM, MERCHANT, SHULKER_BOX, SMITHING, SMOKER, STONECUTTER
Fields inherited from interface net.minecraft.resource.featuretoggle.ToggleableFeature
FEATURE_ENABLED_REGISTRY_KEYS
-
Constructor Summary
ConstructorDescriptionExtendedScreenHandlerType
(ExtendedScreenHandlerType.ExtendedFactory<T, D> factory, PacketCodec<? super RegistryByteBuf, D> packetCodec) Constructs an extended screen handler type. -
Method Summary
Modifier and TypeMethodDescriptionfinal T
create
(int syncId, PlayerInventory inventory) Deprecated.create
(int syncId, PlayerInventory inventory, D data) Creates a new screen handler using the extra opening data.PacketCodec
<? super RegistryByteBuf, D> Methods inherited from class net.minecraft.screen.ScreenHandlerType
getRequiredFeatures
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minecraft.resource.featuretoggle.ToggleableFeature
isEnabled
-
Constructor Details
-
ExtendedScreenHandlerType
public ExtendedScreenHandlerType(ExtendedScreenHandlerType.ExtendedFactory<T, D> factory, PacketCodec<? super RegistryByteBuf, D> packetCodec) Constructs an extended screen handler type.- Parameters:
factory
- the screen handler factory used forcreate(int, PlayerInventory, Object)
-
-
Method Details
-
create
Deprecated.Usecreate(int, PlayerInventory, Object)
instead.- Overrides:
create
in classScreenHandlerType<T extends ScreenHandler>
- Throws:
UnsupportedOperationException
- always; usecreate(int, PlayerInventory, Object)
-
create
Creates a new screen handler using the extra opening data.- Parameters:
syncId
- the sync IDinventory
- the player inventorydata
- the synced opening data- Returns:
- the created screen handler
-
getPacketCodec
- Returns:
- the packet codec for serializing the data of this screen handler
-
create(int, PlayerInventory, Object)
instead.