initial large chests
This commit is contained in:
parent
2e43f24e23
commit
92b7214c69
8 changed files with 99 additions and 58 deletions
|
@ -14,7 +14,8 @@ public class GuiChest extends GuiContainer {
|
|||
this.block = block;
|
||||
int i = 222;
|
||||
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() {
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package common.block.tech;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import common.block.BlockContainer;
|
||||
import common.block.Rotatable;
|
||||
import common.block.SoundType;
|
||||
import common.collect.Maps;
|
||||
import common.block.Material;
|
||||
import common.color.TextColor;
|
||||
import common.entity.Entity;
|
||||
|
@ -32,17 +35,34 @@ import common.world.AWorldServer;
|
|||
|
||||
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);
|
||||
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH));
|
||||
this.capacity = capacity * 27;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.setTab(CheatTab.TECHNOLOGY);
|
||||
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
|
||||
this.setHardness(2.5F);
|
||||
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()
|
||||
|
@ -191,7 +211,7 @@ public class BlockChest extends BlockContainer implements Rotatable
|
|||
|
||||
public TileEntity createNewTileEntity()
|
||||
{
|
||||
return new TileEntityChest(this.capacity);
|
||||
return new TileEntityChest(this.width * this.height);
|
||||
}
|
||||
|
||||
private boolean isBlocked(World worldIn, BlockPos pos)
|
||||
|
|
|
@ -623,8 +623,14 @@ public abstract class BlockRegistry {
|
|||
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("chest", new BlockChest(1).setDisplay("Truhe"));
|
||||
register("large_chest", new BlockChest(2).setDisplay("Große Truhe"));
|
||||
register("chest", new BlockChest(9, 3).setDisplay("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)
|
||||
.setDisplay("Warptruhe").setLightLevel(0.5F));
|
||||
|
||||
|
|
|
@ -595,6 +595,12 @@ public abstract class Blocks {
|
|||
public static final BlockActiveDisplay display2_on = get("display2_on");
|
||||
public static final BlockActiveDisplay display4_on = get("display4_on");
|
||||
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) {
|
||||
T block = (T)BlockRegistry.byNameExact(id);
|
||||
|
|
|
@ -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_extended = get("potion_weakness_extended");
|
||||
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) {
|
||||
T item = (T)ItemRegistry.byName(id);
|
||||
|
|
|
@ -1,25 +1,32 @@
|
|||
package common.inventory;
|
||||
|
||||
import common.block.tech.BlockChest;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.item.ItemStack;
|
||||
|
||||
public class ContainerChest extends Container
|
||||
{
|
||||
private IInventory chest;
|
||||
private int numRows;
|
||||
private final IInventory chest;
|
||||
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.numRows = chestInventory.getSizeInventory() / 9;
|
||||
chestInventory.openInventory(player);
|
||||
int i = (this.numRows - 4) * 18;
|
||||
this.chest = chest;
|
||||
this.chestSize = chest.getSizeInventory();
|
||||
chest.openInventory(player);
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
public ItemStack transferStackInSlot(EntityNPC player, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot)this.inventorySlots.get(index);
|
||||
Slot slot = this.inventorySlots.get(index);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
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;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 9, false))
|
||||
else if (!this.mergeItemStack(itemstack1, 0, this.chestSize, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.isEmpty())
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
slot.putStack(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -80,17 +84,24 @@ public class ContainerChest extends Container
|
|||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the container is closed.
|
||||
*/
|
||||
public void onContainerClosed(EntityNPC playerIn)
|
||||
public void onContainerClosed(EntityNPC player)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
this.chest.closeInventory(playerIn);
|
||||
super.onContainerClosed(player);
|
||||
this.chest.closeInventory(player);
|
||||
}
|
||||
|
||||
public IInventory getChestInventory()
|
||||
{
|
||||
return this.chest;
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return this.height;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ public class SPacketOpenWindow implements Packet<IClientPlayer>
|
|||
{
|
||||
private int windowId;
|
||||
private Block type;
|
||||
private String windowTitle;
|
||||
private int slotCount;
|
||||
private int entityId = -1;
|
||||
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.type = guiId;
|
||||
this.windowTitle = windowTitleIn;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -61,8 +59,7 @@ public class SPacketOpenWindow implements Packet<IClientPlayer>
|
|||
State state = BlockRegistry.byId(type);
|
||||
this.type = state == null ? Blocks.air : state.getBlock();
|
||||
}
|
||||
this.windowTitle = buf.readString(256);
|
||||
this.slotCount = buf.readUnsignedByte();
|
||||
this.slotCount = buf.readVarInt();
|
||||
}
|
||||
|
||||
public void writePacketData(PacketBuffer buf) throws IOException
|
||||
|
@ -73,8 +70,7 @@ public class SPacketOpenWindow implements Packet<IClientPlayer>
|
|||
buf.writeInt(this.entityId);
|
||||
else if(this.tilePos != null)
|
||||
buf.writeBlockPos(this.tilePos);
|
||||
buf.writeString(this.windowTitle);
|
||||
buf.writeByte(this.slotCount);
|
||||
buf.writeVarInt(this.slotCount);
|
||||
}
|
||||
|
||||
public int getWindowId()
|
||||
|
@ -87,11 +83,6 @@ public class SPacketOpenWindow implements Packet<IClientPlayer>
|
|||
return this.type;
|
||||
}
|
||||
|
||||
public String getWindowTitle()
|
||||
{
|
||||
return this.windowTitle;
|
||||
}
|
||||
|
||||
public int getSlotCount()
|
||||
{
|
||||
return this.slotCount;
|
||||
|
|
|
@ -668,12 +668,12 @@ public class Player extends User implements Executor, IPlayer
|
|||
}
|
||||
else if(object instanceof Entity entity) {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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));
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
else {
|
||||
|
@ -706,7 +706,7 @@ public class Player extends User implements Executor, IPlayer
|
|||
|
||||
if(object instanceof EntityNPC npc) {
|
||||
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);
|
||||
if(trades != null)
|
||||
this.sendPacket(new SPacketTrades(trades, this.currentWindowId));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue