User Tools

Site Tools


tutorial:screenhandler

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:screenhandler [2021/09/01 00:28] – updated BlockEntityType.Builder to FabricBlockEntityTypeBuilder for 1.17 lvanderzandetutorial:screenhandler [2024/02/19 02:51] (current) – [ScreenHandler and Screen] transferSlot -> quickMove per yarn mappings netuserget
Line 91: Line 91:
     public DefaultedList<ItemStack> getItems() {     public DefaultedList<ItemStack> getItems() {
         return inventory;         return inventory;
- 
     }     }
  
Line 107: Line 106:
     @Override     @Override
     public Text getDisplayName() {     public Text getDisplayName() {
-        return new TranslatableText(getCachedState().getBlock().getTranslationKey());+        // for 1.19+ 
 +        return Text.translatable(getCachedState().getBlock().getTranslationKey()); 
 +        // for earlier versions 
 +        // return new TranslatableText(getCachedState().getBlock().getTranslationKey());
     }     }
          
Line 142: Line 144:
  
     static {     static {
-        BOX_BLOCK = Registry.register(Registry.BLOCK, BOX, new BoxBlock(FabricBlockSettings.copyOf(Blocks.CHEST))); +        BOX_BLOCK = Registry.register(Registries.BLOCK, BOX, new BoxBlock(FabricBlockSettings.copyOf(Blocks.CHEST))); 
-        BOX_BLOCK_ITEM = Registry.register(Registry.ITEM, BOX, new BlockItem(BOX_BLOCK, new Item.Settings().group(ItemGroup.MISC)));+        BOX_BLOCK_ITEM = Registry.register(Registries.ITEM, BOX, new BlockItem(BOX_BLOCK, new Item.Settings()));
  
         //The parameter of build at the very end is always null, do not worry about it         //The parameter of build at the very end is always null, do not worry about it
Line 215: Line 217:
     // Shift + Player Inv Slot     // Shift + Player Inv Slot
     @Override     @Override
-    public ItemStack transferSlot(PlayerEntity player, int invSlot) {+    public ItemStack quickMove(PlayerEntity player, int invSlot) {
         ItemStack newStack = ItemStack.EMPTY;         ItemStack newStack = ItemStack.EMPTY;
         Slot slot = this.slots.get(invSlot);         Slot slot = this.slots.get(invSlot);
Line 243: Line 245:
  
 <code java [enable_line_numbers="true"] BoxScreen.java> <code java [enable_line_numbers="true"] BoxScreen.java>
-public class BoxScreen extends HandledScreen<ScreenHandler> {+public class BoxScreen extends HandledScreen<BoxScreenHandler> {
     //A path to the gui texture. In this example we use the texture from the dispenser     //A path to the gui texture. In this example we use the texture from the dispenser
     private static final Identifier TEXTURE = new Identifier("minecraft", "textures/gui/container/dispenser.png");     private static final Identifier TEXTURE = new Identifier("minecraft", "textures/gui/container/dispenser.png");
  
-    public BoxScreen(ScreenHandler handler, PlayerInventory inventory, Text title) {+    public BoxScreen(BoxScreenHandler handler, PlayerInventory inventory, Text title) {
         super(handler, inventory, title);         super(handler, inventory, title);
     }     }
Line 253: Line 255:
     @Override     @Override
     protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {     protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
-        RenderSystem.setShader(GameRenderer::getPositionTexShader);+        RenderSystem.setShader(GameRenderer::getPositionTexProgram);
         RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);         RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
         RenderSystem.setShaderTexture(0, TEXTURE);         RenderSystem.setShaderTexture(0, TEXTURE);
Line 259: Line 261:
         int y = (height - backgroundHeight) / 2;         int y = (height - backgroundHeight) / 2;
         drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight);         drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight);
 +        //in 1.20 or above,this method is in DrawContext class.
     }     }
  
Line 288: Line 291:
     @Override     @Override
     public void onInitializeClient() {     public void onInitializeClient() {
-        ScreenRegistry.register(ExampleMod.BOX_SCREEN_HANDLER, BoxScreen::new);+        HandledScreens.register(ExampleMod.BOX_SCREEN_HANDLER, BoxScreen::new);
     }     }
 } }
tutorial/screenhandler.1630456103.txt.gz · Last modified: 2021/09/01 00:28 by lvanderzande