User Tools

Site Tools


zh_cn: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
zh_cn:tutorial:screenhandler [2022/05/04 12:40] solidblockzh_cn:tutorial:screenhandler [2023/09/14 01:42] (current) – [ScreenHandler 和 Screen] wjz_p
Line 105: Line 105:
     @Override     @Override
     public Text getDisplayName() {     public Text getDisplayName() {
-        return new TranslatableText(getCachedState().getBlock().getTranslationKey());+        return Text.translatable(getCachedState().getBlock().getTranslationKey()); 
 +        // 对于1.19之前的版本,请使用: 
 +        // return new TranslatableText(getCachedState().getBlock().getTranslationKey());
     }     }
          
Line 138: Line 140:
  
     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().group(ItemGroup.MISC)));
  
         //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
         // 1.17 之前         // 1.17 之前
-        BOX_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, BOX, BlockEntityType.Builder.create(BoxBlockEntity::new, BOX_BLOCK).build(null));+        BOX_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, BOX, BlockEntityType.Builder.create(BoxBlockEntity::new, BOX_BLOCK).build(null));
         // 在 1.17 使用 FabricBlockEntityTypeBuilder 而不是 BlockEntityType.Builder         // 在 1.17 使用 FabricBlockEntityTypeBuilder 而不是 BlockEntityType.Builder
-        BOX_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, BOX, FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, BOX_BLOCK).build(null));+        BOX_BLOCK_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, BOX, FabricBlockEntityTypeBuilder.create(BoxBlockEntity::new, BOX_BLOCK).build(null));
     }     }
  
Line 182: Line 184:
  
         // 这会将槽位放置在 3×3 网格的正确位置中。这些槽位在客户端和服务器中都存在!         // 这会将槽位放置在 3×3 网格的正确位置中。这些槽位在客户端和服务器中都存在!
-        // 但是这不会渲染槽位的背景,这是 Screens job+        // 但是这不会渲染槽位的背景,这是 Screens 类的工作
         int m;         int m;
         int l;         int l;
Line 249: Line 251:
     @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 255: Line 257:
         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);
 +        //1.20或者以上的版本,这个方法在DrawContext类里面。
     }     }
  
zh_cn/tutorial/screenhandler.1651668016.txt.gz · Last modified: 2022/05/04 12:40 by solidblock