initial large chests

This commit is contained in:
Sen 2025-07-14 17:57:06 +02:00
parent 2e43f24e23
commit 92b7214c69
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
8 changed files with 99 additions and 58 deletions

View file

@ -14,7 +14,8 @@ public class GuiChest extends GuiContainer {
this.block = block; this.block = block;
int i = 222; int i = 222;
int j = i - 108; int j = i - 108;
this.ySize = j + (chest.getSizeInventory() / 9) * 18; this.xSize += (((ContainerChest)this.inventorySlots).getWidth() - 9) * 18;
this.ySize = j + ((ContainerChest)this.inventorySlots).getHeight() * 18;
} }
public void addElements() { public void addElements() {

View file

@ -1,8 +1,11 @@
package common.block.tech; package common.block.tech;
import java.util.Map;
import common.block.BlockContainer; import common.block.BlockContainer;
import common.block.Rotatable; import common.block.Rotatable;
import common.block.SoundType; import common.block.SoundType;
import common.collect.Maps;
import common.block.Material; import common.block.Material;
import common.color.TextColor; import common.color.TextColor;
import common.entity.Entity; import common.entity.Entity;
@ -32,17 +35,34 @@ import common.world.AWorldServer;
public class BlockChest extends BlockContainer implements Rotatable public class BlockChest extends BlockContainer implements Rotatable
{ {
private final int capacity; private static final Map<Integer, BlockChest> CHESTS = Maps.newHashMap();
private final int width;
private final int height;
public static BlockChest getChest(int size) {
return CHESTS.get(size);
}
public BlockChest(int capacity) public BlockChest(int width, int height)
{ {
super(Material.WOOD); super(Material.WOOD);
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH)); this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH));
this.capacity = capacity * 27; this.width = width;
this.height = height;
this.setTab(CheatTab.TECHNOLOGY); this.setTab(CheatTab.TECHNOLOGY);
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
this.setHardness(2.5F); this.setHardness(2.5F);
this.setStepSound(SoundType.WOOD); this.setStepSound(SoundType.WOOD);
CHESTS.put(this.width * this.height, this);
}
public int getInventoryWidth() {
return this.width;
}
public int getInventoryHeight() {
return this.height;
} }
public boolean isOpaqueCube() public boolean isOpaqueCube()
@ -191,7 +211,7 @@ public class BlockChest extends BlockContainer implements Rotatable
public TileEntity createNewTileEntity() public TileEntity createNewTileEntity()
{ {
return new TileEntityChest(this.capacity); return new TileEntityChest(this.width * this.height);
} }
private boolean isBlocked(World worldIn, BlockPos pos) private boolean isBlocked(World worldIn, BlockPos pos)

View file

@ -623,8 +623,14 @@ public abstract class BlockRegistry {
register("construction_table", (new BlockWorkbench(4)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Konstruktionstisch")); register("construction_table", (new BlockWorkbench(4)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Konstruktionstisch"));
register("assembly_unit", (new BlockWorkbench(5)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Fertigungseinheit")); register("assembly_unit", (new BlockWorkbench(5)).setHardness(2.5F).setStepSound(SoundType.WOOD).setDisplay("Fertigungseinheit"));
register("chest", new BlockChest(1).setDisplay("Truhe")); register("chest", new BlockChest(9, 3).setDisplay("Truhe"));
register("large_chest", new BlockChest(2).setDisplay("Große Truhe")); register("large_chest", new BlockChest(9, 6).setDisplay("Große Truhe"));
register("xlarge_chest", new BlockChest(12, 8).setDisplay("Große Truhe"));
register("xxlarge_chest", new BlockChest(16, 10).setDisplay("Große Truhe"));
register("xxxlarge_chest", new BlockChest(18, 14).setDisplay("Große Truhe"));
register("huge_chest", new BlockChest(22, 18).setDisplay("Große Truhe"));
register("giant_chest", new BlockChest(24, 20).setDisplay("Große Truhe"));
register("toolarge_chest", new BlockChest(24, 24).setDisplay("Große Truhe"));
register("warp_chest", (new BlockWarpChest()).setHardness(22.5F).setResistance(1000.0F).setStepSound(SoundType.STONE) register("warp_chest", (new BlockWarpChest()).setHardness(22.5F).setResistance(1000.0F).setStepSound(SoundType.STONE)
.setDisplay("Warptruhe").setLightLevel(0.5F)); .setDisplay("Warptruhe").setLightLevel(0.5F));

View file

@ -595,6 +595,12 @@ public abstract class Blocks {
public static final BlockActiveDisplay display2_on = get("display2_on"); public static final BlockActiveDisplay display2_on = get("display2_on");
public static final BlockActiveDisplay display4_on = get("display4_on"); public static final BlockActiveDisplay display4_on = get("display4_on");
public static final BlockChest large_chest = get("large_chest"); public static final BlockChest large_chest = get("large_chest");
public static final BlockChest giant_chest = get("giant_chest");
public static final BlockChest huge_chest = get("huge_chest");
public static final BlockChest toolarge_chest = get("toolarge_chest");
public static final BlockChest xlarge_chest = get("xlarge_chest");
public static final BlockChest xxlarge_chest = get("xxlarge_chest");
public static final BlockChest xxxlarge_chest = get("xxxlarge_chest");
private static <T extends Block> T get(String id) { private static <T extends Block> T get(String id) {
T block = (T)BlockRegistry.byNameExact(id); T block = (T)BlockRegistry.byNameExact(id);

View file

@ -1004,6 +1004,12 @@ public abstract class Items {
public static final ItemPotion potion_weakness_base = get("potion_weakness_base"); public static final ItemPotion potion_weakness_base = get("potion_weakness_base");
public static final ItemPotion potion_weakness_extended = get("potion_weakness_extended"); public static final ItemPotion potion_weakness_extended = get("potion_weakness_extended");
public static final ItemChest large_chest = get("large_chest"); public static final ItemChest large_chest = get("large_chest");
public static final ItemChest giant_chest = get("giant_chest");
public static final ItemChest huge_chest = get("huge_chest");
public static final ItemChest toolarge_chest = get("toolarge_chest");
public static final ItemChest xlarge_chest = get("xlarge_chest");
public static final ItemChest xxlarge_chest = get("xxlarge_chest");
public static final ItemChest xxxlarge_chest = get("xxxlarge_chest");
private static <T extends Item> T get(String id) { private static <T extends Item> T get(String id) {
T item = (T)ItemRegistry.byName(id); T item = (T)ItemRegistry.byName(id);

View file

@ -1,25 +1,32 @@
package common.inventory; package common.inventory;
import common.block.tech.BlockChest;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.item.ItemStack; import common.item.ItemStack;
public class ContainerChest extends Container public class ContainerChest extends Container
{ {
private IInventory chest; private final IInventory chest;
private int numRows; private final int chestSize;
private final int width;
private final int height;
public ContainerChest(IInventory playerInventory, IInventory chestInventory, EntityNPC player) public ContainerChest(IInventory inv, IInventory chest, EntityNPC player)
{ {
this.chest = chestInventory; this.chest = chest;
this.numRows = chestInventory.getSizeInventory() / 9; this.chestSize = chest.getSizeInventory();
chestInventory.openInventory(player); chest.openInventory(player);
int i = (this.numRows - 4) * 18; BlockChest block = BlockChest.getChest(this.chestSize);
this.width = block.getInventoryWidth();
this.height = block.getInventoryHeight();
int xOffset = (this.width - 9) * 18 / 2;
int yoffset = (this.height - 4) * 18;
for (int j = 0; j < this.numRows; ++j) for (int j = 0; j < this.height; ++j)
{ {
for (int k = 0; k < 9; ++k) for (int k = 0; k < this.width; ++k)
{ {
this.addSlotToContainer(new Slot(chestInventory, k + j * 9, 8 + k * 18, 18 + j * 18)); this.addSlotToContainer(new Slot(chest, k + j * 9, 8 + k * 18, 18 + j * 18));
} }
} }
@ -27,49 +34,46 @@ public class ContainerChest extends Container
{ {
for (int j1 = 0; j1 < 9; ++j1) for (int j1 = 0; j1 < 9; ++j1)
{ {
this.addSlotToContainer(new Slot(playerInventory, j1 + l * 9 + 9, 8 + j1 * 18, 103 + l * 18 + i)); this.addSlotToContainer(new Slot(inv, j1 + l * 9 + 9, 8 + j1 * 18 + xOffset, 103 + l * 18 + yoffset));
} }
} }
for (int i1 = 0; i1 < 9; ++i1) for (int i1 = 0; i1 < 9; ++i1)
{ {
this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 161 + i)); this.addSlotToContainer(new Slot(inv, i1, 8 + i1 * 18 + xOffset, 161 + yoffset));
} }
} }
public boolean canInteractWith(EntityNPC playerIn) public boolean canInteractWith(EntityNPC player)
{ {
return this.chest.isUseableByPlayer(playerIn); return this.chest.isUseableByPlayer(player);
} }
/** public ItemStack transferStackInSlot(EntityNPC player, int index)
* Take a stack from the specified inventory slot.
*/
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
{ {
ItemStack itemstack = null; ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(index); Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack()) if (slot != null && slot.getHasStack())
{ {
ItemStack itemstack1 = slot.getStack(); ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy(); itemstack = itemstack1.copy();
if (index < this.numRows * 9) if (index < this.chestSize)
{ {
if (!this.mergeItemStack(itemstack1, this.numRows * 9, this.inventorySlots.size(), true)) if (!this.mergeItemStack(itemstack1, this.chestSize, this.inventorySlots.size(), true))
{ {
return null; return null;
} }
} }
else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false)) else if (!this.mergeItemStack(itemstack1, 0, this.chestSize, false))
{ {
return null; return null;
} }
if (itemstack1.isEmpty()) if (itemstack1.isEmpty())
{ {
slot.putStack((ItemStack)null); slot.putStack(null);
} }
else else
{ {
@ -80,17 +84,24 @@ public class ContainerChest extends Container
return itemstack; return itemstack;
} }
/** public void onContainerClosed(EntityNPC player)
* Called when the container is closed.
*/
public void onContainerClosed(EntityNPC playerIn)
{ {
super.onContainerClosed(playerIn); super.onContainerClosed(player);
this.chest.closeInventory(playerIn); this.chest.closeInventory(player);
} }
public IInventory getChestInventory() public IInventory getChestInventory()
{ {
return this.chest; return this.chest;
} }
public int getWidth()
{
return this.width;
}
public int getHeight()
{
return this.height;
}
} }

View file

@ -15,7 +15,6 @@ public class SPacketOpenWindow implements Packet<IClientPlayer>
{ {
private int windowId; private int windowId;
private Block type; private Block type;
private String windowTitle;
private int slotCount; private int slotCount;
private int entityId = -1; private int entityId = -1;
private BlockPos tilePos; private BlockPos tilePos;
@ -24,23 +23,22 @@ public class SPacketOpenWindow implements Packet<IClientPlayer>
{ {
} }
public SPacketOpenWindow(int windowIdIn, Block guiId, String windowTitleIn, int slotCountIn) public SPacketOpenWindow(int windowIdIn, Block guiId, int slotCountIn)
{ {
this.windowId = windowIdIn; this.windowId = windowIdIn;
this.type = guiId; this.type = guiId;
this.windowTitle = windowTitleIn;
this.slotCount = slotCountIn; this.slotCount = slotCountIn;
} }
public SPacketOpenWindow(int windowIdIn, int incomingEntityId, String windowTitleIn, int slotCountIn) public SPacketOpenWindow(int windowIdIn, int incomingEntityId, int slotCountIn)
{ {
this(windowIdIn, (Block)null, windowTitleIn, slotCountIn); this(windowIdIn, (Block)null, slotCountIn);
this.entityId = incomingEntityId; this.entityId = incomingEntityId;
} }
public SPacketOpenWindow(int windowIdIn, BlockPos incomingTilePos, String windowTitleIn, int slotCountIn) public SPacketOpenWindow(int windowIdIn, BlockPos incomingTilePos, int slotCountIn)
{ {
this(windowIdIn, (Block)null, windowTitleIn, slotCountIn); this(windowIdIn, (Block)null, slotCountIn);
this.tilePos = incomingTilePos; this.tilePos = incomingTilePos;
} }
@ -61,8 +59,7 @@ public class SPacketOpenWindow implements Packet<IClientPlayer>
State state = BlockRegistry.byId(type); State state = BlockRegistry.byId(type);
this.type = state == null ? Blocks.air : state.getBlock(); this.type = state == null ? Blocks.air : state.getBlock();
} }
this.windowTitle = buf.readString(256); this.slotCount = buf.readVarInt();
this.slotCount = buf.readUnsignedByte();
} }
public void writePacketData(PacketBuffer buf) throws IOException public void writePacketData(PacketBuffer buf) throws IOException
@ -73,8 +70,7 @@ public class SPacketOpenWindow implements Packet<IClientPlayer>
buf.writeInt(this.entityId); buf.writeInt(this.entityId);
else if(this.tilePos != null) else if(this.tilePos != null)
buf.writeBlockPos(this.tilePos); buf.writeBlockPos(this.tilePos);
buf.writeString(this.windowTitle); buf.writeVarInt(this.slotCount);
buf.writeByte(this.slotCount);
} }
public int getWindowId() public int getWindowId()
@ -87,11 +83,6 @@ public class SPacketOpenWindow implements Packet<IClientPlayer>
return this.type; return this.type;
} }
public String getWindowTitle()
{
return this.windowTitle;
}
public int getSlotCount() public int getSlotCount()
{ {
return this.slotCount; return this.slotCount;

View file

@ -668,12 +668,12 @@ public class Player extends User implements Executor, IPlayer
} }
else if(object instanceof Entity entity) { else if(object instanceof Entity entity) {
InventoryBasic inv = entity.getEntityInventory(); InventoryBasic inv = entity.getEntityInventory();
this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), entity.getId(), entity.getName(), inv.getSizeInventory())); this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), entity.getId(), inv.getSizeInventory()));
this.entity.openContainer = new ContainerEntityInventory(this.entity.inventory, inv, entity, this.entity); this.entity.openContainer = new ContainerEntityInventory(this.entity.inventory, inv, entity, this.entity);
} }
else if (object instanceof Device device) else if (object instanceof Device device)
{ {
this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), device.getPos(), device.getBlockType().getDisplay(), device.getSizeInventory())); this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), device.getPos(), device.getSizeInventory()));
this.entity.openContainer = new ContainerTile(this.entity.inventory, device, device, this.entity); this.entity.openContainer = new ContainerTile(this.entity.inventory, device, device, this.entity);
} }
else if (object instanceof TileEntityChest chest) else if (object instanceof TileEntityChest chest)
@ -684,17 +684,17 @@ public class Player extends User implements Executor, IPlayer
this.sendPacket(new SPacketSoundEffect(SoundEvent.DOOR, this.entity.posX, this.entity.posY, this.entity.posZ, 1.0F)); this.sendPacket(new SPacketSoundEffect(SoundEvent.DOOR, this.entity.posX, this.entity.posY, this.entity.posZ, 1.0F));
return; return;
} }
this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), chest.getBlockType(), chest.getName(), chest.getSizeInventory())); this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), chest.getBlockType(), chest.getSizeInventory()));
this.entity.openContainer = new ContainerChest(this.entity.inventory, chest, this.entity); this.entity.openContainer = new ContainerChest(this.entity.inventory, chest, this.entity);
} }
else if (object instanceof TileEntityInventory tile) else if (object instanceof TileEntityInventory tile)
{ {
this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), tile.getBlockType(), tile.getBlockType().getDisplay(), tile.getSizeInventory())); this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), tile.getBlockType(), tile.getSizeInventory()));
this.entity.openContainer = tile.createContainer(this.entity.inventory, this.entity); this.entity.openContainer = tile.createContainer(this.entity.inventory, this.entity);
} }
else if (object instanceof InteractionObject obj) else if (object instanceof InteractionObject obj)
{ {
this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), obj.getBlock(), obj.getBlock().getDisplay(), 0)); this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), obj.getBlock(), 0));
this.entity.openContainer = obj.createContainer(this.entity.inventory, this.entity); this.entity.openContainer = obj.createContainer(this.entity.inventory, this.entity);
} }
else { else {
@ -706,7 +706,7 @@ public class Player extends User implements Executor, IPlayer
if(object instanceof EntityNPC npc) { if(object instanceof EntityNPC npc) {
IInventory merchant = ((ContainerMerchant)this.entity.openContainer).getMerchantInventory(); IInventory merchant = ((ContainerMerchant)this.entity.openContainer).getMerchantInventory();
this.sendPacket(new SPacketOpenWindow(this.currentWindowId, npc.getId(), npc.getName(), merchant.getSizeInventory())); this.sendPacket(new SPacketOpenWindow(this.currentWindowId, npc.getId(), merchant.getSizeInventory()));
MerchantRecipeList trades = npc.getTrades(this.entity); MerchantRecipeList trades = npc.getTrades(this.entity);
if(trades != null) if(trades != null)
this.sendPacket(new SPacketTrades(trades, this.currentWindowId)); this.sendPacket(new SPacketTrades(trades, this.currentWindowId));