make larger crafting grids possible

This commit is contained in:
Sen 2025-05-25 00:10:02 +02:00
parent aa0ff6cf96
commit 8bd9370bab
11 changed files with 97 additions and 102 deletions

View file

@ -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);
}
}
}

View file

@ -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"));

View file

@ -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");

View file

@ -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<IRecipe>()
{
@ -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;
}

View file

@ -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");

View file

@ -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;
}