Buckets:
| { | |
| "path": "Minecraft/mc-Data/ExampleScreenHandler.java", | |
| "original_extension": "java", | |
| "content": "package com.example.examplemod;\n\nimport net.minecraft.entity.player.PlayerEntity;\nimport net.minecraft.entity.player.PlayerInventory;\nimport net.minecraft.inventory.Inventory;\nimport net.minecraft.inventory.SimpleInventory;\nimport net.minecraft.item.ItemStack;\nimport net.minecraft.registry.Registries;\nimport net.minecraft.registry.Registry;\nimport net.minecraft.screen.ScreenHandler;\nimport net.minecraft.screen.ScreenHandlerType;\nimport net.minecraft.screen.slot.Slot;\nimport net.minecraft.util.Identifier;\nimport net.minecraft.world.World;\n\n/**\n * A minimal 3-slot ScreenHandler (server-side GUI logic) you'd open from a\n * block entity. Pair with a matching HandledScreen on the client for visuals.\n * ScreenHandler API is unchanged across 1.21.7 - 1.21.11.\n */\npublic class ExampleScreenHandler extends ScreenHandler {\n\n public static final ScreenHandlerType<ExampleScreenHandler> TYPE = Registry.register(\n Registries.SCREEN_HANDLER,\n Identifier.of(ExampleMod.MOD_ID, \"example_screen_handler\"),\n new ScreenHandlerType<>(ExampleScreenHandler::new, net.minecraft.feature.FeatureFlags.VANILLA_FEATURES)\n );\n\n private final Inventory inventory;\n\n // Client-side constructor (called when server tells client to open screen)\n public ExampleScreenHandler(int syncId, PlayerInventory playerInventory) {\n this(syncId, playerInventory, new SimpleInventory(3));\n }\n\n // Server-side constructor\n public ExampleScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory) {\n super(TYPE, syncId);\n this.inventory = inventory;\n checkSize(inventory, 3);\n inventory.onOpen(playerInventory.player);\n\n int slotIndex = 0;\n\n // Our 3 custom slots (e.g. input/fuel/output style layout)\n for (int col = 0; col < 3; col++) {\n this.addSlot(new Slot(inventory, slotIndex++, 44 + col * 18, 20));\n }\n\n // Standard player inventory + hotbar slots below\n for (int row = 0; row < 3; row++) {\n for (int col = 0; col < 9; col++) {\n this.addSlot(new Slot(playerInventory, col + row * 9 + 9, 8 + col * 18, 51 + row * 18));\n }\n }\n for (int col = 0; col < 9; col++) {\n this.addSlot(new Slot(playerInventory, col, 8 + col * 18, 109));\n }\n }\n\n @Override\n public boolean canUse(World world, PlayerEntity player) {\n return inventory.canPlayerUse(player);\n }\n\n @Override\n public ItemStack quickMove(PlayerEntity player, int slotIndex) {\n // Simplified shift-click handling; real mods implement full slot transfer logic here.\n Slot slot = this.slots.get(slotIndex);\n if (!slot.hasStack()) return ItemStack.EMPTY;\n ItemStack stack = slot.getStack().copy();\n slot.setStack(ItemStack.EMPTY);\n return stack;\n }\n\n @Override\n public void onClosed(PlayerEntity player) {\n super.onClosed(player);\n inventory.onClose(player);\n }\n}\n" | |
| } |
Xet Storage Details
- Size:
- 3.2 kB
- Xet hash:
- 4fc6fb25d996f5fc170f705ab342eab48d73f530a5bfc98f4596d7b2edfe5002
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.