pre-fix for guis, large chests

This commit is contained in:
Sen 2025-07-14 17:01:04 +02:00
parent ab3bc0407c
commit 2e43f24e23
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
99 changed files with 756 additions and 3619 deletions

View file

@ -11,6 +11,7 @@ import common.block.Block;
import common.block.artificial.BlockFence;
import common.block.artificial.BlockFenceGate;
import common.block.artificial.BlockWall;
import common.block.tech.InteractionObject;
import common.collect.Lists;
import common.color.TextColor;
import common.dimension.Dimension;
@ -37,7 +38,9 @@ import common.inventory.ContainerChest;
import common.inventory.ContainerEnchantment;
import common.inventory.ContainerEntityInventory;
import common.inventory.ContainerMerchant;
import common.inventory.ContainerTile;
import common.inventory.IInventory;
import common.inventory.InventoryBasic;
import common.inventory.InventoryPlayer;
import common.inventory.Slot;
import common.inventory.SlotCrafting;
@ -99,10 +102,10 @@ import common.packet.SPacketUpdateHealth;
import common.packet.CPacketAction.Action;
import common.packet.SPacketMessage.Type;
import common.tags.TagObject;
import common.tileentity.IInteractionObject;
import common.tileentity.ILockableContainer;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityDevice;
import common.tileentity.TileEntityChest;
import common.tileentity.TileEntityInventory;
import common.tileentity.Device;
import common.tileentity.TileEntitySign;
import common.util.BlockPos;
import common.util.BlockPos.MutableBlockPos;
@ -394,35 +397,16 @@ public class Player extends User implements Executor, IPlayer
this.entity.updateEntityFall(p_71122_1_, p_71122_3_, block, blockpos);
}
private void getNextWindowId()
private int getNextWindowId()
{
this.currentWindowId = this.currentWindowId % 100 + 1;
return this.currentWindowId;
}
private void getNextFormId()
{
this.currentFormId = this.currentFormId % 100 + 1;
}
public void displayTradeGui(EntityNPC npc)
{
this.getNextWindowId();
this.entity.openContainer = new ContainerMerchant(this.entity.inventory, npc, this.entity.worldObj);
this.entity.openContainer.windowId = this.currentWindowId;
this.entity.openContainer.onCraftGuiOpened(this);
IInventory iinventory = ((ContainerMerchant)this.entity.openContainer).getMerchantInventory();
String ichatcomponent = npc.getName();
this.sendPacket(new SPacketOpenWindow(this.currentWindowId, "trade", ichatcomponent, iinventory.getSizeInventory()));
MerchantRecipeList merchantrecipelist = npc.getTrades(this.entity);
if (merchantrecipelist != null)
{
// PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
// packetbuffer.writeInt(this.currentWindowId);
// merchantrecipelist.writeToBuf(packetbuffer);
this.sendPacket(new SPacketTrades(merchantrecipelist, this.currentWindowId));
}
}
public void updateHeldItem()
{
@ -431,12 +415,6 @@ public class Player extends User implements Executor, IPlayer
this.sendPacket(new SPacketSetSlot(-1, -1, this.entity.inventory.getItemStack()));
}
}
public void closeContainer()
{
this.entity.openContainer.onContainerClosed(this.entity);
this.entity.openContainer = this.entity.inventoryContainer;
}
public void setEntityActionState(float p_110430_1_, float p_110430_2_, boolean p_110430_3_, boolean sneaking)
{
@ -668,92 +646,71 @@ public class Player extends User implements Executor, IPlayer
this.sendPacket(new SPacketEntityAttach(0, this.entity, this.entity.vehicle));
this.setPlayerLocation(this.entity.posX, this.entity.posY, this.entity.posZ, this.entity.rotYaw, this.entity.rotPitch);
}
public void openEditSign(TileEntitySign signTile)
{
signTile.setPlayer(this.entity);
this.sendPacket(new SPacketSignEditorOpen(signTile.getPos()));
}
public void displayGui(IInteractionObject guiOwner)
{
this.getNextWindowId();
this.sendPacket(new SPacketOpenWindow(this.currentWindowId, guiOwner.getGuiID(), guiOwner.getCommandName()));
this.entity.openContainer = guiOwner.createContainer(this.entity.inventory, this.entity);
this.entity.openContainer.windowId = this.currentWindowId;
this.entity.openContainer.onCraftGuiOpened(this);
}
public void displayGUIChest(IInventory chestInventory)
public void show(Object object)
{
if (this.entity.openContainer != this.entity.inventoryContainer)
{
this.closeScreen();
if(object == null || this.entity.openContainer != this.entity.inventoryContainer) {
this.sendPacket(new SPacketCloseWindow(this.entity.openContainer.windowId));
this.entity.openContainer.onContainerClosed(this.entity);
this.entity.openContainer = this.entity.inventoryContainer;
if(object == null)
return;
}
if(object instanceof TileEntitySign sign) {
sign.setPlayer(this.entity);
this.sendPacket(new SPacketSignEditorOpen(sign.getPos()));
return;
}
if (chestInventory instanceof ILockableContainer)
else if(object instanceof EntityNPC npc) {
this.getNextWindowId();
this.entity.openContainer = new ContainerMerchant(this.entity.inventory, npc, this.entity.worldObj);
}
else if(object instanceof Entity entity) {
InventoryBasic inv = entity.getEntityInventory();
this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), entity.getId(), entity.getName(), inv.getSizeInventory()));
this.entity.openContainer = new ContainerEntityInventory(this.entity.inventory, inv, entity, this.entity);
}
else if (object instanceof Device device)
{
ILockableContainer ilockablecontainer = (ILockableContainer)chestInventory;
if (ilockablecontainer.isLocked() && !this.entity.canOpen(ilockablecontainer.getLockCode())) // && !this.isSpectator())
this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), device.getPos(), device.getBlockType().getDisplay(), device.getSizeInventory()));
this.entity.openContainer = new ContainerTile(this.entity.inventory, device, device, this.entity);
}
else if (object instanceof TileEntityChest chest)
{
if (chest.getLockCode() != null && !this.entity.canOpen(chest.getLockCode()))
{
this.addHotbar(TextColor.RED + "%s ist verschlossen!", chestInventory.getCommandName());
this.addHotbar(TextColor.RED + "%s ist verschlossen!", chest.getName());
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.entity.openContainer = new ContainerChest(this.entity.inventory, chest, this.entity);
}
this.getNextWindowId();
if (chestInventory instanceof TileEntityDevice)
else if (object instanceof TileEntityInventory tile)
{
this.sendPacket(new SPacketOpenWindow(this.currentWindowId, "tile", chestInventory.getCommandName(), chestInventory.getSizeInventory(),
((TileEntityDevice)chestInventory).getPos()));
this.entity.openContainer = ((IInteractionObject)chestInventory).createContainer(this.entity.inventory, this.entity);
this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), tile.getBlockType(), tile.getBlockType().getDisplay(), tile.getSizeInventory()));
this.entity.openContainer = tile.createContainer(this.entity.inventory, this.entity);
}
else if (chestInventory instanceof IInteractionObject)
else if (object instanceof InteractionObject obj)
{
this.sendPacket(new SPacketOpenWindow(this.currentWindowId, ((IInteractionObject)chestInventory).getGuiID(), chestInventory.getCommandName(), chestInventory.getSizeInventory()));
this.entity.openContainer = ((IInteractionObject)chestInventory).createContainer(this.entity.inventory, this.entity);
this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), obj.getBlock(), obj.getBlock().getDisplay(), 0));
this.entity.openContainer = obj.createContainer(this.entity.inventory, this.entity);
}
else
{
this.sendPacket(new SPacketOpenWindow(this.currentWindowId, "container", chestInventory.getCommandName(), chestInventory.getSizeInventory()));
this.entity.openContainer = new ContainerChest(this.entity.inventory, chestInventory, this.entity);
else {
return;
}
this.entity.openContainer.windowId = this.currentWindowId;
this.entity.openContainer.onCraftGuiOpened(this);
}
public void displayEntityGui(Entity entity, IInventory inventory)
{
if (this.entity.openContainer != this.entity.inventoryContainer)
{
this.closeScreen();
if(object instanceof EntityNPC npc) {
IInventory merchant = ((ContainerMerchant)this.entity.openContainer).getMerchantInventory();
this.sendPacket(new SPacketOpenWindow(this.currentWindowId, npc.getId(), npc.getName(), merchant.getSizeInventory()));
MerchantRecipeList trades = npc.getTrades(this.entity);
if(trades != null)
this.sendPacket(new SPacketTrades(trades, this.currentWindowId));
}
this.getNextWindowId();
this.sendPacket(new SPacketOpenWindow(this.currentWindowId, "entity", inventory.getCommandName(), inventory.getSizeInventory(), entity.getId()));
this.entity.openContainer = new ContainerEntityInventory(this.entity.inventory, inventory, entity, this.entity);
this.entity.openContainer.windowId = this.currentWindowId;
this.entity.openContainer.onCraftGuiOpened(this);
}
// public void displayGUIBook(ItemStack bookStack)
// {
// Item item = bookStack.getItem();
//
// if (item == Items.writable_book)
// {
// this.sendPacket(new SPacketBook());
// }
// }
public void closeScreen()
{
this.sendPacket(new SPacketCloseWindow(this.entity.openContainer.windowId));
this.closeContainer();
}
// public void addStat(int amount)
@ -980,8 +937,7 @@ public class Player extends User implements Executor, IPlayer
if (/* !this.worldObj.client && */ !this.entity.openContainer.canInteractWith(this.entity))
{
this.closeScreen();
this.entity.openContainer = this.entity.inventoryContainer;
this.show(null);
}
while (!this.destroyedItemsNetCache.isEmpty())
@ -2599,32 +2555,6 @@ public class Player extends User implements Executor, IPlayer
}
break;
// case SET_BEACON:
// if (this.entity.openContainer instanceof ContainerBeacon)
// {
// try
// {
// int k = packetIn.getAuxData() & 255;
// int l = packetIn.getAuxData() >> 8;
// ContainerBeacon containerbeacon = (ContainerBeacon)this.entity.openContainer;
// Slot slot = containerbeacon.getSlot(0);
//
// if (slot.getHasStack())
// {
// slot.decrStackSize(1);
// IInventory iinventory = containerbeacon.func_180611_e();
// iinventory.setField(1, k);
// iinventory.setField(2, l);
// iinventory.markDirty();
// }
// }
// catch (Exception exception)
// {
// SKC.error((String)"Konnte Leuchtfeuer nicht ändern", (Throwable)exception);
// }
// }
// break;
case SWING_ARM:
this.entity.swingItem();
// if(packetIn.getAuxData() != 0)
@ -2650,8 +2580,10 @@ public class Player extends User implements Executor, IPlayer
break;
case CLOSE_CONTAINER:
if(this.entity.openContainer.windowId == packetIn.getAuxData())
this.closeContainer();
if(this.entity.openContainer.windowId == packetIn.getAuxData()) {
this.entity.openContainer.onContainerClosed(this.entity);
this.entity.openContainer = this.entity.inventoryContainer;
}
break;
case CONFIRM_TRANSACTION:

View file

@ -112,13 +112,12 @@ import common.log.Log;
import common.rng.Random;
import common.tags.TagObject;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityBeacon;
import common.tileentity.DeviceEffectGenerator;
import common.tileentity.TileEntityChest;
import common.tileentity.TileEntityComparator;
import common.tileentity.TileEntityDaylightDetector;
import common.tileentity.TileEntityDispenser;
import common.tileentity.TileEntityDropper;
import common.tileentity.TileEntityEnchantmentTable;
import common.tileentity.TileEntityFurnace;
import common.tileentity.TileEntityHopper;
import common.tileentity.TileEntitySign;
@ -374,8 +373,7 @@ public abstract class Converter {
mapTile(TileEntityDropper.class, "Dropper", "dropper");
mapTile(TileEntitySign.class, "Sign", "sign");
// mapTile(TileEntityPiston.class, "Piston", "piston");
mapTile(TileEntityEnchantmentTable.class, "EnchantTable", "enchanting_table");
mapTile(TileEntityBeacon.class, "Beacon", "beacon");
mapTile(DeviceEffectGenerator.class, "Beacon", "beacon");
mapTile(TileEntityDaylightDetector.class, "DLDetector", "daylight_detector");
mapTile(TileEntityHopper.class, "Hopper", "hopper");
mapTile(TileEntityComparator.class, "Comparator", "comparator");
@ -1174,7 +1172,7 @@ public abstract class Converter {
mapBlock(Blocks.spruce_stairs.getState().withProperty(BlockStairs.FACING, Facing.SOUTH).withProperty(BlockStairs.HALF, EnumHalf.TOP), 136, 6, 14);
mapBlock(Blocks.spruce_stairs.getState().withProperty(BlockStairs.FACING, Facing.NORTH).withProperty(BlockStairs.HALF, EnumHalf.TOP), 136, 7, 15);
mapBlock(Blocks.obsidian, 137);
mapBlock(Blocks.beacon, 138);
mapBlock(Blocks.effect_generator, 138);
mapBlock(Blocks.cobblestone_wall, 139);
mapBlock(Blocks.mossy_cobblestone_wall, 139, 1);
mapBlock(Blocks.flowerpot, 140);
@ -1214,10 +1212,10 @@ public abstract class Converter {
mapBlock(Blocks.anvil.getState().withProperty(BlockAnvil.FACING, Facing.WEST), 145, 1, 5, 9, 13);
mapBlock(Blocks.anvil.getState().withProperty(BlockAnvil.FACING, Facing.NORTH), 145, 2, 6, 10, 14);
mapBlock(Blocks.anvil.getState().withProperty(BlockAnvil.FACING, Facing.EAST), 145, 3, 7, 11, 15);
mapBlock(Blocks.trapped_chest.getState().withProperty(BlockChest.FACING, Facing.NORTH), 146);
mapBlock(Blocks.trapped_chest.getState().withProperty(BlockChest.FACING, Facing.SOUTH), 146, 3, 9, 15);
mapBlock(Blocks.trapped_chest.getState().withProperty(BlockChest.FACING, Facing.WEST), 146, 4, 10);
mapBlock(Blocks.trapped_chest.getState().withProperty(BlockChest.FACING, Facing.EAST), 146, 5, 11);
mapBlock(Blocks.chest.getState().withProperty(BlockChest.FACING, Facing.NORTH), 146);
mapBlock(Blocks.chest.getState().withProperty(BlockChest.FACING, Facing.SOUTH), 146, 3, 9, 15);
mapBlock(Blocks.chest.getState().withProperty(BlockChest.FACING, Facing.WEST), 146, 4, 10);
mapBlock(Blocks.chest.getState().withProperty(BlockChest.FACING, Facing.EAST), 146, 5, 11);
mapBlock(Blocks.light_weighted_pressure_plate.getState().withProperty(BlockPressurePlateWeighted.POWER, 0), 147, 0);
mapBlock(Blocks.light_weighted_pressure_plate.getState().withProperty(BlockPressurePlateWeighted.POWER, 1), 147, 1);
mapBlock(Blocks.light_weighted_pressure_plate.getState().withProperty(BlockPressurePlateWeighted.POWER, 2), 147, 2);

View file

@ -2,6 +2,7 @@ package server.worldgen.feature;
import common.block.Block;
import common.block.Material;
import common.block.tech.BlockChest;
import common.init.Blocks;
import common.item.RngLoot;
import common.rng.Random;
@ -9,6 +10,7 @@ import common.rng.WeightedList;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityChest;
import common.util.BlockPos;
import common.util.Facing;
import server.world.WorldServer;
import server.worldgen.FeatureGenerator;
import server.worldgen.LootConstants;
@ -49,10 +51,10 @@ public class WorldGenAbandonedChest extends FeatureGenerator
BlockPos blockpos = position.add(rand.zrange(4) - rand.zrange(4), rand.zrange(3) - rand.zrange(3), rand.zrange(4) - rand.zrange(4));
if (worldIn.isAirBlock(blockpos) && worldIn.isBlockSolid(blockpos.down()))
{
worldIn.setState(blockpos, Blocks.chest.getState(), 2);
worldIn.setState(blockpos, Blocks.chest.getState().withProperty(BlockChest.FACING, Facing.randHorizontal(rand)), 2);
TileEntity tileentity = worldIn.getTileEntity(blockpos);
if(tileentity instanceof TileEntityChest)
RngLoot.generateChestContents(rand, this.items, (TileEntityChest)tileentity, this.amount);
if(tileentity instanceof TileEntityChest chest)
RngLoot.generateChestContents(rand, this.items, chest, this.amount);
return true;
}
}

View file

@ -3,10 +3,10 @@ package server.worldgen.structure;
import java.util.LinkedList;
import java.util.List;
import common.block.tech.BlockChest;
import common.block.tech.BlockRail;
import common.block.tech.BlockRailBase;
import common.block.tech.BlockTorch;
import common.entity.item.EntityChestCart;
import common.entity.npc.EntityArachnoid;
import common.init.Blocks;
import common.item.RngLoot;
@ -14,6 +14,8 @@ import common.item.material.ItemEnchantedBook;
import common.rng.Random;
import common.rng.WeightedList;
import common.tags.TagObject;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityChest;
import common.util.BlockPos;
import common.util.Facing;
import common.vars.Vars;
@ -291,13 +293,12 @@ public class StructureMineshaft
{
BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
if (boundingBoxIn.isVecInside(blockpos) && worldIn.getState(blockpos).getBlock() == Blocks.air)
if (boundingBoxIn.isVecInside(blockpos) && worldIn.getState(blockpos).getBlock() == Blocks.air && worldIn.isBlockSolid(blockpos.down()))
{
BlockRailBase.EnumRailDirection i = rand.chance() ? BlockRailBase.EnumRailDirection.EAST_WEST : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
worldIn.setState(blockpos, this.getMetadataWithOffset(Blocks.rail.getState().withProperty(BlockRail.SHAPE, i)), 2);
EntityChestCart entityminecartchest = new EntityChestCart(worldIn, (double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 0.5F), (double)((float)blockpos.getZ() + 0.5F));
RngLoot.generateChestContents(rand, listIn, entityminecartchest, max);
worldIn.spawnEntityInWorld(entityminecartchest);
worldIn.setState(blockpos, Blocks.chest.getState().withProperty(BlockChest.FACING, Facing.randHorizontal(rand)), 2);
TileEntity tileentity = worldIn.getTileEntity(blockpos);
if(tileentity instanceof TileEntityChest chest)
RngLoot.generateChestContents(rand, listIn, chest, max);
return true;
}
else