From 8bd9370bab48cb7754f5ac1e3ace25465219fcbb Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 25 May 2025 00:10:02 +0200 Subject: [PATCH] make larger crafting grids possible --- .../src/client/gui/container/GuiCrafting.java | 46 +++++------------ client/src/client/network/ClientPlayer.java | 13 +++-- common/src/common/block/BlockWorkbench.java | 34 ++++++------- common/src/common/init/BlockRegistry.java | 4 +- common/src/common/init/Blocks.java | 4 +- common/src/common/init/CraftingRegistry.java | 40 ++++++++------- common/src/common/init/Items.java | 1 + .../common/inventory/ContainerWorkbench.java | 51 ++++++++++--------- server/src/server/world/Converter.java | 2 +- .../structure/StructureScattered.java | 2 +- .../worldgen/structure/StructureVillage.java | 2 +- 11 files changed, 97 insertions(+), 102 deletions(-) diff --git a/client/src/client/gui/container/GuiCrafting.java b/client/src/client/gui/container/GuiCrafting.java index d38e913..954e6cf 100755 --- a/client/src/client/gui/container/GuiCrafting.java +++ b/client/src/client/gui/container/GuiCrafting.java @@ -1,42 +1,22 @@ package client.gui.container; +import common.block.BlockWorkbench; import common.inventory.ContainerWorkbench; import common.inventory.InventoryPlayer; import common.util.BlockPos; import common.world.World; -public class GuiCrafting extends GuiContainer -{ -// private static final String craftingTableGuiTextures = "textures/gui/crafting_table.png"; +public class GuiCrafting extends GuiContainer { + private final BlockWorkbench type; + + public GuiCrafting(InventoryPlayer playerInv, World worldIn, BlockWorkbench type) { + super(new ContainerWorkbench(playerInv, worldIn, BlockPos.ORIGIN, type)); + this.type = type; + this.ySize = 112 + 18 * this.type.getSize(); + } - public GuiCrafting(InventoryPlayer playerInv, World worldIn) - { - this(playerInv, worldIn, BlockPos.ORIGIN); - } - - public GuiCrafting(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition) - { - super(new ContainerWorkbench(playerInv, worldIn, blockPosition)); - } - - /** - * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY - */ - public void drawGuiContainerForegroundLayer() - { - this.drawString("Handwerk", 28, 6); - this.drawString("Inventar", 8, this.ySize - 96 + 2); - } - -// /** -// * Args : renderPartialTicks, mouseX, mouseY -// */ -// protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) -// { -// GlState.color(1.0F, 1.0F, 1.0F, 1.0F); -// this.gm.getTextureManager().bindTexture(craftingTableGuiTextures); -// int i = (this.width - this.xSize) / 2; -// int j = (this.height - this.ySize) / 2; -//// this.rect(i, j, 0, 0, this.xSize, this.ySize); -// } + public void drawGuiContainerForegroundLayer() { + this.drawString("Handwerk (" + this.type.getDisplay() + ")", 26, 6); + this.drawString("Inventar", 8, this.ySize - 96 + 2); + } } diff --git a/client/src/client/network/ClientPlayer.java b/client/src/client/network/ClientPlayer.java index 2fbf084..94602af 100755 --- a/client/src/client/network/ClientPlayer.java +++ b/client/src/client/network/ClientPlayer.java @@ -34,6 +34,8 @@ import common.attributes.Attribute; import common.attributes.AttributeInstance; import common.attributes.AttributeMap; import common.attributes.AttributeModifier; +import common.block.Block; +import common.block.BlockWorkbench; import common.collect.Lists; import common.collect.Maps; import common.dimension.Dimension; @@ -47,6 +49,7 @@ import common.entity.npc.EntityNPC; import common.entity.npc.PlayerCharacter; import common.entity.projectile.EntityProjectile; import common.entity.types.EntityLiving; +import common.init.BlockRegistry; import common.init.EntityRegistry; import common.init.ItemRegistry; import common.init.SoundEvent; @@ -2047,11 +2050,11 @@ public class ClientPlayer extends NetHandler implements IClientPlayer public void displayGui(IInteractionObject guiOwner, InventoryPlayer inventory, World worldObj) { String s = guiOwner.getGuiID(); - if ("crafting_table".equals(s)) - { - this.gameController.displayGuiScreen(new GuiCrafting(inventory, worldObj)); - } - else if ("enchanting_table".equals(s)) + Block block = BlockRegistry.getRegisteredBlock(s); + if(block instanceof BlockWorkbench) { + this.gameController.displayGuiScreen(new GuiCrafting(inventory, worldObj, (BlockWorkbench)block)); + } + else if ("enchanting_table".equals(s)) { this.gameController.displayGuiScreen(new GuiEnchant(inventory, worldObj, guiOwner)); } diff --git a/common/src/common/block/BlockWorkbench.java b/common/src/common/block/BlockWorkbench.java index 3ac24c8..3280f32 100755 --- a/common/src/common/block/BlockWorkbench.java +++ b/common/src/common/block/BlockWorkbench.java @@ -1,6 +1,7 @@ package common.block; import common.entity.npc.EntityNPC; +import common.init.BlockRegistry; import common.inventory.Container; import common.inventory.ContainerWorkbench; import common.inventory.InventoryPlayer; @@ -16,11 +17,18 @@ import common.world.World; public class BlockWorkbench extends Block { - public BlockWorkbench() + private final int size; + + public BlockWorkbench(int size) { super(Material.wood); this.setTab(CheatTab.tabTech); + this.size = size; } + + public int getSize() { + return this.size; + } public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) { @@ -30,7 +38,7 @@ public class BlockWorkbench extends Block } else { - playerIn.displayGui(new BlockWorkbench.InterfaceCraftingTable(worldIn, pos)); + playerIn.displayGui(new BlockWorkbench.InterfaceCraftingTable(worldIn, pos, this)); // playerIn.triggerAchievement(StatRegistry.craftingTableStat); return true; } @@ -45,36 +53,28 @@ public class BlockWorkbench extends Block { private final World world; private final BlockPos position; + private final BlockWorkbench block; - public InterfaceCraftingTable(World worldIn, BlockPos pos) + public InterfaceCraftingTable(World worldIn, BlockPos pos, BlockWorkbench block) { this.world = worldIn; this.position = pos; + this.block = block; } - - public String getName() - { - return null; - } - - public boolean hasCustomName() - { - return false; - } - + public String getCommandName() { - return "Werkbank"; + return this.block.getDisplay(); } public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) { - return new ContainerWorkbench(playerInventory, this.world, this.position); + return new ContainerWorkbench(playerInventory, this.world, this.position, this.block); } public String getGuiID() { - return "crafting_table"; + return BlockRegistry.REGISTRY.getNameForObject(this.block); } } } diff --git a/common/src/common/init/BlockRegistry.java b/common/src/common/init/BlockRegistry.java index c348564..ec7703a 100755 --- a/common/src/common/init/BlockRegistry.java +++ b/common/src/common/init/BlockRegistry.java @@ -527,7 +527,7 @@ public abstract class BlockRegistry { .setDisplay("Chunk-Lade-Kern")); registerBlock(2001, "mob_spawner", (new BlockMobSpawner()).setHardness(5.0F).setStepSound(SoundType.STONE).setDisplay("Monsterspawner")); - registerBlock(2002, "crafting_table", (new BlockWorkbench()).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Werkbank")); + registerBlock(2002, "workbench", (new BlockWorkbench(3)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Werkbank")); registerBlock(2003, "furnace", (new BlockFurnace(false)).setHardness(3.5F).setStepSound(SoundType.STONE).setDisplay("Ofen") .setTab(CheatTab.tabTech)); registerBlock(2004, "lit_furnace", (new BlockFurnace(true)).setHardness(3.5F).setStepSound(SoundType.STONE).setLightLevel(0.875F) @@ -542,6 +542,8 @@ public abstract class BlockRegistry { registerBlock(2010, "noteblock", (new BlockNote()).setHardness(0.8F).setDisplay("Notenblock")); registerBlock(2011, "jukebox", (new BlockJukebox()).setHardness(2.0F).setResistance(10.0F).setStepSound(SoundType.STONE).setDisplay("Plattenspieler")); + registerBlock(2012, "construction_table", (new BlockWorkbench(4)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Konstruktionstisch")); + registerBlock(2013, "assembly_unit", (new BlockWorkbench(5)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Fertigungseinheit")); registerBlock(2100, "chest", (new BlockChest(0)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Truhe")); registerBlock(2101, "trapped_chest", (new BlockChest(1)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Redstonetruhe")); diff --git a/common/src/common/init/Blocks.java b/common/src/common/init/Blocks.java index 056473c..508ec50 100755 --- a/common/src/common/init/Blocks.java +++ b/common/src/common/init/Blocks.java @@ -142,7 +142,9 @@ public abstract class Blocks { public static final BlockRedstoneWire redstone = (BlockRedstoneWire)get("redstone"); public static final BlockOre diamond_ore = (BlockOre)get("diamond_ore"); public static final Block diamond_block = get("diamond_block"); - public static final Block crafting_table = get("crafting_table"); + public static final Block workbench = get("workbench"); + public static final Block construction_table = get("construction_table"); + public static final Block assembly_unit = get("assembly_unit"); public static final Block wheat = get("wheat"); public static final Block farmland = get("farmland"); public static final Block furnace = get("furnace"); diff --git a/common/src/common/init/CraftingRegistry.java b/common/src/common/init/CraftingRegistry.java index 7e5ea06..e76ddfb 100755 --- a/common/src/common/init/CraftingRegistry.java +++ b/common/src/common/init/CraftingRegistry.java @@ -315,7 +315,8 @@ public abstract class CraftingRegistry add(new ItemStack(Blocks.daylight_detector), "GGG", "QQQ", "WWW", 'G', Blocks.glass, 'Q', Items.quartz, 'W', slab); add(new ItemStack(Blocks.chest), "###", "# #", "###", '#', planks); - addBasic(new ItemStack(Blocks.crafting_table), "##", "##", '#', planks); + addBasic(new ItemStack(Blocks.workbench), "##", "##", '#', planks); + add(new ItemStack(Blocks.assembly_unit), "----", "XXXX", "X##X", '#', Blocks.construction_table, '-', Items.titanium_ingot, 'X', planks); add(new ItemStack(Blocks.jukebox, 1), "###", "#X#", "###", '#', planks, 'X', Items.diamond); @@ -466,6 +467,9 @@ public abstract class CraftingRegistry add(new ItemStack(Items.magnet, 1), "I I", "N N", " R ", 'I', Items.iron_ingot, 'N', Items.neodymium_ingot, 'R', Items.redstone); addShapeless(new ItemStack(Items.potion, 1, 16384), new ItemStack(Items.potion, 1, 0), Items.gunpowder); + + add(new ItemStack(Blocks.construction_table), "---", "-#-", "---", '#', Blocks.workbench, '-', Items.iron_ingot); + add(new ItemStack(Blocks.bedrock), "#####", "#####", "#####", "#####", "#####", '#', Blocks.obsidian); Collections.sort(recipes, new Comparator() { @@ -1570,9 +1574,9 @@ public abstract class CraftingRegistry */ public boolean matches(InventoryCrafting inv, World worldIn) { - for (int i = 0; i <= 3 - this.recipeWidth; ++i) + for (int i = 0; i <= inv.getWidth() - this.recipeWidth; ++i) { - for (int j = 0; j <= 3 - this.recipeHeight; ++j) + for (int j = 0; j <= inv.getHeight() - this.recipeHeight; ++j) { if (this.checkMatch(inv, i, j, true)) { @@ -1592,43 +1596,43 @@ public abstract class CraftingRegistry /** * Checks if the region of a crafting inventory is match for the recipe. */ - private boolean checkMatch(InventoryCrafting p_77573_1_, int p_77573_2_, int p_77573_3_, boolean p_77573_4_) + private boolean checkMatch(InventoryCrafting inv, int xPos, int yPos, boolean mirror) { - for (int i = 0; i < 3; ++i) + for (int x = 0; x < inv.getWidth(); ++x) { - for (int j = 0; j < 3; ++j) + for (int y = 0; y < inv.getHeight(); ++y) { - int k = i - p_77573_2_; - int l = j - p_77573_3_; - ItemStack itemstack = null; + int rx = x - xPos; + int ry = y - yPos; + ItemStack stack = null; - if (k >= 0 && l >= 0 && k < this.recipeWidth && l < this.recipeHeight) + if (rx >= 0 && ry >= 0 && rx < this.recipeWidth && ry < this.recipeHeight) { - if (p_77573_4_) + if (mirror) { - itemstack = this.recipeItems[this.recipeWidth - k - 1 + l * this.recipeWidth]; + stack = this.recipeItems[this.recipeWidth - rx - 1 + ry * this.recipeWidth]; } else { - itemstack = this.recipeItems[k + l * this.recipeWidth]; + stack = this.recipeItems[rx + ry * this.recipeWidth]; } } - ItemStack itemstack1 = p_77573_1_.getStackInRowAndColumn(i, j); + ItemStack ingredient = inv.getStackInRowAndColumn(x, y); - if (itemstack1 != null || itemstack != null) + if (ingredient != null || stack != null) { - if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null) + if (ingredient == null && stack != null || ingredient != null && stack == null) { return false; } - if (itemstack.getItem() != itemstack1.getItem()) + if (stack.getItem() != ingredient.getItem()) { return false; } - if (itemstack.getMetadata() != 32767 && itemstack.getMetadata() != itemstack1.getMetadata()) + if (stack.getMetadata() != 32767 && stack.getMetadata() != ingredient.getMetadata()) { return false; } diff --git a/common/src/common/init/Items.java b/common/src/common/init/Items.java index 4f9779b..50f5534 100755 --- a/common/src/common/init/Items.java +++ b/common/src/common/init/Items.java @@ -120,6 +120,7 @@ public abstract class Items { public static final Item iron_hoe = get("iron_hoe"); public static final Item iron_horse_armor = get("iron_horse_armor"); public static final Item iron_ingot = get("iron_ingot"); + public static final Item titanium_ingot = get("titanium_ingot"); public static final ItemArmor iron_leggings = (ItemArmor)get("iron_leggings"); public static final Item iron_pickaxe = get("iron_pickaxe"); public static final ItemShears iron_shears = (ItemShears)get("iron_shears"); diff --git a/common/src/common/inventory/ContainerWorkbench.java b/common/src/common/inventory/ContainerWorkbench.java index 2dce2fc..4450495 100755 --- a/common/src/common/inventory/ContainerWorkbench.java +++ b/common/src/common/inventory/ContainerWorkbench.java @@ -1,7 +1,7 @@ package common.inventory; +import common.block.BlockWorkbench; import common.entity.npc.EntityNPC; -import common.init.Blocks; import common.init.CraftingRegistry; import common.item.ItemStack; import common.util.BlockPos; @@ -9,25 +9,28 @@ import common.world.World; public class ContainerWorkbench extends Container { - /** The crafting matrix inventory (3x3). */ - public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); - public IInventory craftResult = new InventoryCraftResult(); - private World worldObj; + private final int craftSlots; + public final InventoryCrafting craftMatrix; + public final IInventory craftResult = new InventoryCraftResult(); + private final World worldObj; + private final BlockPos pos; + private final BlockWorkbench block; - /** Position of the workbench */ - private BlockPos pos; - - public ContainerWorkbench(InventoryPlayer playerInventory, World worldIn, BlockPos posIn) + public ContainerWorkbench(InventoryPlayer playerInventory, World worldIn, BlockPos posIn, BlockWorkbench block) { + int size = block.getSize(); + this.block = block; this.worldObj = worldIn; this.pos = posIn; - this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35)); + this.craftSlots = size * size; + this.craftMatrix = new InventoryCrafting(this, size, size); + this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 134, 17 + ((size - 1) * 18) / 2)); - for (int i = 0; i < 3; ++i) + for (int i = 0; i < size; ++i) { - for (int j = 0; j < 3; ++j) + for (int j = 0; j < size; ++j) { - this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18)); + this.addSlotToContainer(new Slot(this.craftMatrix, j + i * size, 26 + j * 18, 17 + i * 18)); } } @@ -35,13 +38,13 @@ public class ContainerWorkbench extends Container { for (int i1 = 0; i1 < 9; ++i1) { - this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18)); + this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 30 + size * 18 + k * 18)); } } for (int l = 0; l < 9; ++l) { - this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142)); + this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 88 + size * 18)); } this.onCraftMatrixChanged(this.craftMatrix); @@ -64,7 +67,7 @@ public class ContainerWorkbench extends Container if (!this.worldObj.client) { - for (int i = 0; i < 9; ++i) + for (int i = 0; i < this.craftSlots; ++i) { ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i); @@ -78,7 +81,7 @@ public class ContainerWorkbench extends Container public boolean canInteractWith(EntityNPC playerIn) { - return this.worldObj.getState(this.pos).getBlock() != Blocks.crafting_table ? false : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; + return this.worldObj.getState(this.pos).getBlock() != this.block ? false : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; } /** @@ -87,7 +90,7 @@ public class ContainerWorkbench extends Container public ItemStack transferStackInSlot(EntityNPC playerIn, int index) { ItemStack itemstack = null; - Slot slot = (Slot)this.inventorySlots.get(index); + Slot slot = this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { @@ -96,28 +99,28 @@ public class ContainerWorkbench extends Container if (index == 0) { - if (!this.mergeItemStack(itemstack1, 10, 46, true)) + if (!this.mergeItemStack(itemstack1, this.craftSlots + 1, this.craftSlots + 37, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } - else if (index >= 10 && index < 37) + else if (index >= this.craftSlots + 1 && index < this.craftSlots + 28) { - if (!this.mergeItemStack(itemstack1, 37, 46, false)) + if (!this.mergeItemStack(itemstack1, this.craftSlots + 28, this.craftSlots + 37, false)) { return null; } } - else if (index >= 37 && index < 46) + else if (index >= this.craftSlots + 28 && index < this.craftSlots + 37) { - if (!this.mergeItemStack(itemstack1, 10, 37, false)) + if (!this.mergeItemStack(itemstack1, this.craftSlots + 1, this.craftSlots + 28, false)) { return null; } } - else if (!this.mergeItemStack(itemstack1, 10, 46, false)) + else if (!this.mergeItemStack(itemstack1, this.craftSlots + 1, this.craftSlots + 37, false)) { return null; } diff --git a/server/src/server/world/Converter.java b/server/src/server/world/Converter.java index 7564a9e..d5f31c0 100644 --- a/server/src/server/world/Converter.java +++ b/server/src/server/world/Converter.java @@ -521,7 +521,7 @@ public abstract class Converter { mapBlockData(Blocks.redstone, 55); mapBlock(Blocks.diamond_ore, 56); mapBlock(Blocks.diamond_block, 57); - mapBlock(Blocks.crafting_table, 58); + mapBlock(Blocks.workbench, 58); mapBlockData(Blocks.wheat, 59); mapBlockData(Blocks.farmland, 60); mapBlockData(Blocks.furnace, 61); diff --git a/server/src/server/worldgen/structure/StructureScattered.java b/server/src/server/worldgen/structure/StructureScattered.java index 8723035..8b30816 100755 --- a/server/src/server/worldgen/structure/StructureScattered.java +++ b/server/src/server/worldgen/structure/StructureScattered.java @@ -650,7 +650,7 @@ public class StructureScattered this.setBlockState(worldIn, Blocks.air.getState(), 5, 3, 4, structureBoundingBoxIn); this.setBlockState(worldIn, Blocks.air.getState(), 5, 3, 5, structureBoundingBoxIn); this.setBlockState(worldIn, Blocks.flower_pot.getState().withProperty(BlockFlowerPot.CONTENTS, 2 + BlockFlower.EnumFlowerType.BLACK_LOTUS.getMeta()), 1, 3, 5, structureBoundingBoxIn); - this.setBlockState(worldIn, Blocks.crafting_table.getState(), 3, 2, 6, structureBoundingBoxIn); + this.setBlockState(worldIn, Blocks.workbench.getState(), 3, 2, 6, structureBoundingBoxIn); this.setBlockState(worldIn, Blocks.cauldron.getState(), 4, 2, 6, structureBoundingBoxIn); this.setBlockState(worldIn, Blocks.oak_fence.getState(), 1, 2, 1, structureBoundingBoxIn); this.setBlockState(worldIn, Blocks.oak_fence.getState(), 5, 2, 1, structureBoundingBoxIn); diff --git a/server/src/server/worldgen/structure/StructureVillage.java b/server/src/server/worldgen/structure/StructureVillage.java index 0fb61ae..905d5ca 100755 --- a/server/src/server/worldgen/structure/StructureVillage.java +++ b/server/src/server/worldgen/structure/StructureVillage.java @@ -806,7 +806,7 @@ public class StructureVillage this.setBlockState(worldIn, Blocks.wooden_pressure_plate.getState(), 6, 2, 3, structureBoundingBoxIn); this.setBlockState(worldIn, Blocks.oak_fence.getState(), 4, 1, 3, structureBoundingBoxIn); this.setBlockState(worldIn, Blocks.wooden_pressure_plate.getState(), 4, 2, 3, structureBoundingBoxIn); - this.setBlockState(worldIn, Blocks.crafting_table.getState(), 7, 1, 1, structureBoundingBoxIn); + this.setBlockState(worldIn, Blocks.workbench.getState(), 7, 1, 1, structureBoundingBoxIn); this.setBlockState(worldIn, Blocks.air.getState(), 1, 1, 0, structureBoundingBoxIn); this.setBlockState(worldIn, Blocks.air.getState(), 1, 2, 0, structureBoundingBoxIn); this.placeDoorCurrentPosition(worldIn, structureBoundingBoxIn, randomIn, 1, 1, 0, Facing.getHorizontal(this.getMetadataWithOffset(Blocks.oak_door, 1)));