Browse Source

trea修复

hsj 3 days ago
parent
commit
5c1cc1e9da

+ 1 - 20
src/client/java/com/husj/client/screen/DisassemblerScreen.java

@@ -2,11 +2,9 @@ package com.husj.client.screen;
 
 import com.husj.screen.DisassemblerScreenHandler;
 import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.gui.DrawableHelper;
 import net.minecraft.client.gui.screen.ingame.HandledScreen;
+import com.mojang.blaze3d.pipeline.RenderPipeline;
 import net.minecraft.client.render.*;
-import net.minecraft.client.render.texture.TextureManager;
-import net.minecraft.client.util.math.MatrixStack;
 import net.minecraft.entity.player.PlayerInventory;
 import net.minecraft.text.Text;
 import net.minecraft.util.Identifier;
@@ -28,23 +26,6 @@ public class DisassemblerScreen extends HandledScreen<DisassemblerScreenHandler>
     protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
         int x = (width - backgroundWidth) / 2;
         int y = (height - backgroundHeight) / 2;
-        
-        MatrixStack matrices = context.getMatrices();
-        TextureManager textureManager = context.getTextureManager();
-        
-        // 绑定纹理
-        textureManager.bindTexture(TEXTURE);
-        
-        // 绘制背景
-        RenderSystem.enableBlend();
-        DrawableHelper.drawTexture(matrices, x, y, 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 256);
-        
-        // 绘制进度条
-        if (handler.isCrafting()) {
-            int progress = handler.getScaledProgress();
-            DrawableHelper.drawTexture(matrices, x + 79, y + 34, 176.0F, 0.0F, progress + 1, 16, 256, 256);
-        }
-        RenderSystem.disableBlend();
     }
 
     @Override

+ 15 - 8
src/main/java/com/husj/ModBlocks.java

@@ -11,25 +11,32 @@ import net.minecraft.item.BlockItem;
 import net.minecraft.item.Item;
 import net.minecraft.registry.Registries;
 import net.minecraft.registry.Registry;
+import net.minecraft.registry.RegistryKey;
+import net.minecraft.registry.RegistryKeys;
 import net.minecraft.util.Identifier;
 
 public class ModBlocks {
     public static final Block DISASSEMBLER_BLOCK = registerBlock("disassembler",
-        new DisassemblerBlock(AbstractBlock.Settings.copy(Blocks.IRON_BLOCK).nonOpaque()));
+        DisassemblerBlock::new, AbstractBlock.Settings.create().nonOpaque());
 
     public static final BlockEntityType<DisassemblerBlockEntity> DISASSEMBLER_BLOCK_ENTITY =
         Registry.register(Registries.BLOCK_ENTITY_TYPE,
             Identifier.of("husj", "disassembler_block_entity"),
             FabricBlockEntityTypeBuilder.create(DisassemblerBlockEntity::new, DISASSEMBLER_BLOCK).build());
 
-    private static Block registerBlock(String name, Block block) {
-        registerBlockItem(name, block);
-        return Registry.register(Registries.BLOCK, Identifier.of("husj", name), block);
-    }
+    private static Block registerBlock(String name, java.util.function.Function<AbstractBlock.Settings, Block> factory,
+                                       AbstractBlock.Settings settings) {
+        RegistryKey<Block> blockKey = RegistryKey.of(RegistryKeys.BLOCK, Identifier.of("husj", name));
+        settings.registryKey(blockKey);
+        Block block = factory.apply(settings);
+
+        Registry.register(Registries.BLOCK, blockKey, block);
+
+        RegistryKey<Item> itemKey = RegistryKey.of(RegistryKeys.ITEM, Identifier.of("husj", name));
+        Item.Settings itemSettings = new Item.Settings().registryKey(itemKey).useBlockPrefixedTranslationKey();
+        Registry.register(Registries.ITEM, itemKey, new BlockItem(block, itemSettings));
 
-    private static Item registerBlockItem(String name, Block block) {
-        return Registry.register(Registries.ITEM, Identifier.of("husj", name),
-            new BlockItem(block, new Item.Settings()));
+        return block;
     }
 
     public static void registerModBlocks() {

+ 2 - 37
src/main/java/com/husj/block/entity/DisassemblerBlockEntity.java

@@ -20,6 +20,8 @@ import net.minecraft.text.Text;
 import net.minecraft.util.collection.DefaultedList;
 import net.minecraft.util.math.BlockPos;
 import net.minecraft.world.World;
+import net.minecraft.registry.RegistryEntryLookup;
+import net.minecraft.registry.RegistryWrapper;
 import org.jetbrains.annotations.Nullable;
 
 public class DisassemblerBlockEntity extends BlockEntity implements NamedScreenHandlerFactory, ImplementedInventory {
@@ -83,43 +85,6 @@ public class DisassemblerBlockEntity extends BlockEntity implements NamedScreenH
         return new com.husj.screen.DisassemblerScreenHandler(syncId, playerInventory, this, this.propertyDelegate);
     }
 
-    @Override
-    protected void writeNbt(NbtCompound nbt) {
-        super.writeNbt(nbt);
-        
-        // 手动保存物品栏
-        NbtList itemList = new NbtList();
-        for (int i = 0; i < inventory.size(); i++) {
-            ItemStack stack = inventory.get(i);
-            if (!stack.isEmpty()) {
-                NbtCompound itemNbt = new NbtCompound();
-                itemNbt.putByte("Slot", (byte) i);
-                stack.writeNbt(itemNbt);
-                itemList.add(itemNbt);
-            }
-        }
-        nbt.put("Items", itemList);
-        
-        nbt.putInt("disassembler.progress", progress);
-    }
-
-    @Override
-    protected void readNbt(NbtCompound nbt) {
-        super.readNbt(nbt);
-        
-        // 手动读取物品栏
-        inventory.clear();
-        NbtList itemList = nbt.getList("Items", NbtElement.COMPOUND_TYPE);
-        for (int i = 0; i < itemList.size(); i++) {
-            NbtCompound itemNbt = itemList.getCompound(i);
-            int slot = itemNbt.getByte("Slot") & 0xFF;
-            if (slot >= 0 && slot < inventory.size()) {
-                inventory.set(slot, ItemStack.fromNbt(itemNbt));
-            }
-        }
-        
-        progress = nbt.getInt("disassembler.progress");
-    }
 
     public static void tick(World world, BlockPos pos, BlockState state, DisassemblerBlockEntity blockEntity) {
         if (world.isClient()) {