From 96674df39110737f9d18ea75b0096cd8e2abb164 Mon Sep 17 00:00:00 2001 From: Sen Date: Tue, 12 Aug 2025 20:02:43 +0200 Subject: [PATCH] te cleanup --- .../java/client/gui/container/GuiDevice.java | 2 +- .../java/client/network/ClientPlayer.java | 4 +- .../client/renderer/RegionRenderCache.java | 2 +- .../renderer/tileentity/DisplayRenderer.java | 4 +- .../renderer/tileentity/SignRenderer.java | 2 +- .../main/java/client/world/ChunkClient.java | 2 +- .../main/java/client/world/ChunkEmpty.java | 2 +- .../common/packet/SPacketUpdateDevice.java | 2 +- .../main/java/common/tileentity/Device.java | 10 +- .../common/tileentity/DeviceDispenser.java | 113 ++++----- .../tileentity/DeviceEffectGenerator.java | 2 +- .../java/common/tileentity/DeviceFurnace.java | 8 +- .../common/tileentity/DeviceMobSpawner.java | 14 +- .../common/tileentity/DeviceTianReactor.java | 4 +- .../java/common/tileentity/ITickable.java | 5 +- .../java/common/tileentity/TileEntity.java | 234 +++++++----------- .../common/tileentity/TileEntityChest.java | 28 +-- .../common/tileentity/TileEntityPipe.java | 160 ++++-------- common/src/main/java/common/world/Chunk.java | 18 +- common/src/main/java/common/world/World.java | 4 +- .../server/command/commands/CommandBlock.java | 2 +- .../server/command/commands/CommandSet.java | 2 +- .../src/main/java/server/network/Player.java | 2 +- server/src/main/java/server/world/Region.java | 2 +- .../main/java/server/world/WorldServer.java | 2 +- 25 files changed, 246 insertions(+), 384 deletions(-) diff --git a/client/src/main/java/client/gui/container/GuiDevice.java b/client/src/main/java/client/gui/container/GuiDevice.java index 9cd98771..af39c767 100755 --- a/client/src/main/java/client/gui/container/GuiDevice.java +++ b/client/src/main/java/client/gui/container/GuiDevice.java @@ -30,7 +30,7 @@ public class GuiDevice extends GuiContainer { public void updateScreen() { super.updateScreen(); - this.header.setText(this.tile.getStatus().color + this.tile.getBlockType().getDisplay()); + this.header.setText(this.tile.getStatus().color + this.tile.getBlock().getDisplay()); this.desc.setText(this.tile.formatDisplay((ContainerTile)this.inventorySlots)); if(this.progress != null) { this.progress.setText(this.tile.getTotal() <= 0 || this.tile.getProgress() < 0 ? "" : String.format("%d/%d (%.1f %%)", diff --git a/client/src/main/java/client/network/ClientPlayer.java b/client/src/main/java/client/network/ClientPlayer.java index f9af99f6..dfdc97d5 100755 --- a/client/src/main/java/client/network/ClientPlayer.java +++ b/client/src/main/java/client/network/ClientPlayer.java @@ -1200,7 +1200,7 @@ public class ClientPlayer implements IClientPlayer if (!(tileentity instanceof TileEntitySign)) { tileentity = new TileEntitySign(); - tileentity.setWorldObj(this.world); + tileentity.setWorld(this.world); tileentity.setPos(packetIn.getSignPosition()); } @@ -1262,7 +1262,7 @@ public class ClientPlayer implements IClientPlayer NetHandler.checkThread(packet, this, this.gm, this.world); if(this.gm.world.isBlockLoaded(packet.getPos())) { TileEntity te = this.gm.world.getTileEntity(packet.getPos()); - if(te != null && packet.getType() == te.getBlockType()) + if(te != null && packet.getType() == te.getBlock()) te.readTags(packet.getTag()); } } diff --git a/client/src/main/java/client/renderer/RegionRenderCache.java b/client/src/main/java/client/renderer/RegionRenderCache.java index 74707314..ef9397e5 100755 --- a/client/src/main/java/client/renderer/RegionRenderCache.java +++ b/client/src/main/java/client/renderer/RegionRenderCache.java @@ -67,7 +67,7 @@ public class RegionRenderCache implements IWorldAccess { int i = (pos.getX() >> 4) - this.xPos; int j = (pos.getZ() >> 4) - this.zPos; - return this.chunks[i][j].getTileEntity(pos, TileEntity.EnumCreateEntityType.QUEUED); + return this.chunks[i][j].getTileEntity(pos, TileEntity.CreateMode.QUEUED); } public int getCombinedLight(BlockPos pos, int lightValue) diff --git a/client/src/main/java/client/renderer/tileentity/DisplayRenderer.java b/client/src/main/java/client/renderer/tileentity/DisplayRenderer.java index da491bbb..0df29532 100644 --- a/client/src/main/java/client/renderer/tileentity/DisplayRenderer.java +++ b/client/src/main/java/client/renderer/tileentity/DisplayRenderer.java @@ -80,9 +80,9 @@ public class DisplayRenderer extends ElementRenderer { } public void renderElements(TileEntityDisplay te, double x, double y, double z, float partialTicks) { - Block block = te.getBlockType(); + Block block = te.getBlock(); - State state = te.getBlockState(); + State state = te.getState(); Facing dir = state.getBlock() instanceof BlockDisplay ? state.getValue(BlockDisplay.FACING) : Facing.SOUTH; float rot = 0.0F; if(dir == Facing.NORTH) diff --git a/client/src/main/java/client/renderer/tileentity/SignRenderer.java b/client/src/main/java/client/renderer/tileentity/SignRenderer.java index b944dc16..3c1ffa3a 100755 --- a/client/src/main/java/client/renderer/tileentity/SignRenderer.java +++ b/client/src/main/java/client/renderer/tileentity/SignRenderer.java @@ -17,7 +17,7 @@ public class SignRenderer extends ElementRenderer GL11.glPushMatrix(); float f = 0.6666667F; - State state = te.getBlockState(); + State state = te.getState(); if (state.getBlock() instanceof BlockStandingSign) { GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F * f, (float)z + 0.5F); diff --git a/client/src/main/java/client/world/ChunkClient.java b/client/src/main/java/client/world/ChunkClient.java index a6420192..1221620f 100644 --- a/client/src/main/java/client/world/ChunkClient.java +++ b/client/src/main/java/client/world/ChunkClient.java @@ -127,7 +127,7 @@ public class ChunkClient extends Chunk { this.genHeights(); for(TileEntity tile : this.tiles.values()) { - tile.updateContainingBlockInfo(); + tile.resetBlock(); } } diff --git a/client/src/main/java/client/world/ChunkEmpty.java b/client/src/main/java/client/world/ChunkEmpty.java index 1f881757..76cffbd8 100755 --- a/client/src/main/java/client/world/ChunkEmpty.java +++ b/client/src/main/java/client/world/ChunkEmpty.java @@ -94,7 +94,7 @@ public class ChunkEmpty extends ChunkClient { return pos.getY() > this.liquidY; } - public TileEntity getTileEntity(BlockPos pos, TileEntity.EnumCreateEntityType type) { + public TileEntity getTileEntity(BlockPos pos, TileEntity.CreateMode type) { return null; } diff --git a/common/src/main/java/common/packet/SPacketUpdateDevice.java b/common/src/main/java/common/packet/SPacketUpdateDevice.java index 2623676c..69c2f0be 100755 --- a/common/src/main/java/common/packet/SPacketUpdateDevice.java +++ b/common/src/main/java/common/packet/SPacketUpdateDevice.java @@ -22,7 +22,7 @@ public class SPacketUpdateDevice implements Packet { public SPacketUpdateDevice(TileEntity tile) { this.position = tile.getPos(); - this.type = tile.getBlockType(); + this.type = tile.getBlock(); tile.writeTags(this.tag = new TagObject()); } diff --git a/common/src/main/java/common/tileentity/Device.java b/common/src/main/java/common/tileentity/Device.java index 9b7d57c8..d8c98483 100755 --- a/common/src/main/java/common/tileentity/Device.java +++ b/common/src/main/java/common/tileentity/Device.java @@ -220,7 +220,7 @@ public abstract class Device extends TileEntity implements IInventory, ITickable } public boolean isUseableByPlayer(EntityNPC player) { - return this.worldObj.getTileEntity(this.pos) != this ? false + return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; } @@ -229,13 +229,13 @@ public abstract class Device extends TileEntity implements IInventory, ITickable } public void detonate() { - this.worldObj.setBlockToAir(getPos()); - this.worldObj.newExplosion(null, this.getXPos(), this.getYPos(), this.getZPos(), 5.0f, true, true, false); + this.world.setBlockToAir(getPos()); + this.world.newExplosion(null, this.getXPos(), this.getYPos(), this.getZPos(), 5.0f, true, true, false); } public void update() { - if(this.worldObj != null && !this.worldObj.client && this.status != Status.BROKEN) { - int envTemp = (int)this.worldObj.getTemperatureC(this.getPos()); + if(this.world != null && !this.world.client && this.status != Status.BROKEN) { + int envTemp = (int)this.world.getTemperatureC(this.getPos()); if(this.executeFunction()) { if(this.hasTemperature()) { if(this.getTempIncrement() < 0) diff --git a/common/src/main/java/common/tileentity/DeviceDispenser.java b/common/src/main/java/common/tileentity/DeviceDispenser.java index a47d4892..d0b8eaae 100755 --- a/common/src/main/java/common/tileentity/DeviceDispenser.java +++ b/common/src/main/java/common/tileentity/DeviceDispenser.java @@ -10,76 +10,69 @@ import common.vars.Vars; import common.world.AWorldServer; import common.world.State; -public class DeviceDispenser extends Device -{ +public class DeviceDispenser extends Device { private static final Random RNG = new Random(); - + private final boolean dropItems; - - private int cooldown = 0; - - public DeviceDispenser(boolean dropItems) { + + private int cooldown = 0; + + public DeviceDispenser(boolean dropItems) { super(1, 0); this.dropItems = dropItems; } - public boolean addItemStack(ItemStack stack) - { - if (this.getStackInSlot(0) == null) - { - this.setInventorySlotContents(0, stack); - return true; - } - return false; - } + public boolean addItemStack(ItemStack stack) { + if(this.getStackInSlot(0) == null) { + this.setInventorySlotContents(0, stack); + return true; + } + return false; + } - public void readTags(TagObject compound) - { - super.readTags(compound); - this.cooldown = compound.getInt("Cooldown"); - } + public void readTags(TagObject compound) { + super.readTags(compound); + this.cooldown = compound.getInt("Cooldown"); + } - public void writeTags(TagObject compound) - { - super.writeTags(compound); - compound.setInt("Cooldown", this.cooldown); - } + public void writeTags(TagObject compound) { + super.writeTags(compound); + compound.setInt("Cooldown", this.cooldown); + } - private ItemStack dispenseStack(ItemStack stack, AWorldServer world, BlockPos pos) - { - Facing facing = world.getState(pos).getValue(BlockDispenser.FACING); - if(this.dropItems) { - BlockDispenser.dispense(world, 6.0, facing, BlockDispenser.getDispensePosition(pos, facing), stack.split(1)); - world.playEffect(1000, pos, 0); - world.playEffect(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3); - return stack; - } - ItemStack nstack = stack.getItem().dispenseStack(world, world.getTileEntity(pos), BlockDispenser.getDispensePosition(pos, facing), pos, facing, stack); - int id = stack.getItem().getDispenseSoundId(); - if(id != 0) - world.playEffect(id, pos, 0); - world.playEffect(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3); - return nstack; - } + private ItemStack dispenseStack(ItemStack stack, AWorldServer world, BlockPos pos) { + Facing facing = world.getState(pos).getValue(BlockDispenser.FACING); + if(this.dropItems) { + BlockDispenser.dispense(world, 6.0, facing, BlockDispenser.getDispensePosition(pos, facing), stack.split(1)); + world.playEffect(1000, pos, 0); + world.playEffect(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3); + return stack; + } + ItemStack nstack = stack.getItem().dispenseStack(world, world.getTileEntity(pos), BlockDispenser.getDispensePosition(pos, facing), pos, facing, stack); + int id = stack.getItem().getDispenseSoundId(); + if(id != 0) + world.playEffect(id, pos, 0); + world.playEffect(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3); + return nstack; + } public boolean executeFunction() { - if (this.cooldown <= 0) - { - State state = this.getBlockState(); - if(!(state.getBlock() instanceof BlockDispenser) /* || !this.decrPower() */) //TODO: energy - return false; - ItemStack stack = this.getStackInSlot(0); - if(stack != null) { - ItemStack nstack = this.dispenseStack(stack, (AWorldServer)this.worldObj, this.pos); - this.setInventorySlotContents(0, nstack != null && nstack.isEmpty() ? null : nstack); - this.cooldown = Vars.dispenserDelay; - return true; - } - return false; - } - else { - this.cooldown--; - return true; - } + if(this.cooldown <= 0) { + State state = this.getState(); + if(!(state.getBlock() instanceof BlockDispenser) /* || !this.decrPower() */) // TODO: energy + return false; + ItemStack stack = this.getStackInSlot(0); + if(stack != null) { + ItemStack nstack = this.dispenseStack(stack, (AWorldServer)this.world, this.pos); + this.setInventorySlotContents(0, nstack != null && nstack.isEmpty() ? null : nstack); + this.cooldown = Vars.dispenserDelay; + return true; + } + return false; + } + else { + this.cooldown--; + return true; + } } } diff --git a/common/src/main/java/common/tileentity/DeviceEffectGenerator.java b/common/src/main/java/common/tileentity/DeviceEffectGenerator.java index 87b4cc26..91e5cf89 100755 --- a/common/src/main/java/common/tileentity/DeviceEffectGenerator.java +++ b/common/src/main/java/common/tileentity/DeviceEffectGenerator.java @@ -32,7 +32,7 @@ public class DeviceEffectGenerator extends Device { double y = this.pos.getY(); double z = this.pos.getZ(); BoundingBox bb = new BoundingBox(x + 0.5 - r, y - 16.0, z + 0.5 - r, x + 0.5 + r, (double)World.MAX_SIZE_Y, z + 0.5 + r); - List list = this.worldObj.getEntitiesWithinAABB(EntityNPC.class, bb); + List list = this.world.getEntitiesWithinAABB(EntityNPC.class, bb); for(EntityNPC entity : list) { if(!entity.hasEffect(effect.getPotion()) || entity.getEffect(effect.getPotion()).getAmplifier() < effect.getAmplifier() || entity.getEffect(effect.getPotion()).getRemaining() < 40) { entity.addEffect(new StatusEffect(effect.getPotion(), 180, effect.getAmplifier())); diff --git a/common/src/main/java/common/tileentity/DeviceFurnace.java b/common/src/main/java/common/tileentity/DeviceFurnace.java index f5a754a6..43dac84b 100755 --- a/common/src/main/java/common/tileentity/DeviceFurnace.java +++ b/common/src/main/java/common/tileentity/DeviceFurnace.java @@ -81,8 +81,8 @@ public class DeviceFurnace extends Device implements ISidedInventory if (this.getStackInSlot(1) != null) { if(Vars.itemExplosion && this.getStackInSlot(1).getItem().getExplosive() > 0 && !this.getStackInSlot(1).isEmpty()) { - this.worldObj.setBlockToAir(getPos()); - this.worldObj.newExplosion(null, this.getXPos(), this.getYPos(), this.getZPos(), (float)this.getStackInSlot(1).getItem().getExplosive() * (1.0f + (float)(this.getStackInSlot(1).getSize() - 1) / 24.0f), true, true, true); + this.world.setBlockToAir(getPos()); + this.world.newExplosion(null, this.getXPos(), this.getYPos(), this.getZPos(), (float)this.getStackInSlot(1).getItem().getExplosive() * (1.0f + (float)(this.getStackInSlot(1).getSize() - 1) / 24.0f), true, true, true); this.setInventorySlotContents(1, null); return false; } @@ -120,9 +120,9 @@ public class DeviceFurnace extends Device implements ISidedInventory if (flag != this.isBurning()) { flag1 = true; - Block block = this.getBlockType(); + Block block = this.getBlock(); if(block instanceof BlockFurnace furnace) - furnace.setState(this.isBurning(), this.worldObj, this.pos); + furnace.setState(this.isBurning(), this.world, this.pos); } if (flag1) diff --git a/common/src/main/java/common/tileentity/DeviceMobSpawner.java b/common/src/main/java/common/tileentity/DeviceMobSpawner.java index 036c45b8..d045f678 100755 --- a/common/src/main/java/common/tileentity/DeviceMobSpawner.java +++ b/common/src/main/java/common/tileentity/DeviceMobSpawner.java @@ -9,7 +9,7 @@ import common.item.spawner.ItemCharTemplate; import common.tags.TagObject; import common.vars.Vars; -public class DeviceMobSpawner extends Device implements ITickable +public class DeviceMobSpawner extends Device { public DeviceMobSpawner() { super(1, 0); @@ -43,14 +43,14 @@ public class DeviceMobSpawner extends Device implements ITickable ItemStack stack = this.getStackInSlot(0); if(stack == null) return true; - double x = (double)this.pos.getX() + (this.worldObj.rand.doublev() - this.worldObj.rand.doublev()) * (double)this.spawnRange + 0.5D; - double y = (double)(this.pos.getY() + this.worldObj.rand.zrange(3) - 1); - double z = (double)this.pos.getZ() + (this.worldObj.rand.doublev() - this.worldObj.rand.doublev()) * (double)this.spawnRange + 0.5D; + double x = (double)this.pos.getX() + (this.world.rand.doublev() - this.world.rand.doublev()) * (double)this.spawnRange + 0.5D; + double y = (double)(this.pos.getY() + this.world.rand.zrange(3) - 1); + double z = (double)this.pos.getZ() + (this.world.rand.doublev() - this.world.rand.doublev()) * (double)this.spawnRange + 0.5D; EntityLiving entity = null; if(stack.getItem() instanceof ItemMobTemplate egg) - entity = ItemMobTemplate.spawnCreature(this.worldObj, egg.getSpawnedId(), x, y, z, true); + entity = ItemMobTemplate.spawnCreature(this.world, egg.getSpawnedId(), x, y, z, true); else if(stack.getItem() instanceof ItemCharTemplate egg) - entity = ItemCharTemplate.spawnNpc(this.worldObj, egg.getSpawnedChar(), x, y, z, true); + entity = ItemCharTemplate.spawnNpc(this.world, egg.getSpawnedChar(), x, y, z, true); if (entity == null) return true; this.decrStackSize(0, 1); @@ -68,7 +68,7 @@ public class DeviceMobSpawner extends Device implements ITickable else { int i = this.maxSpawnDelay - this.minSpawnDelay; - this.spawnDelay = this.minSpawnDelay + this.worldObj.rand.zrange(i); + this.spawnDelay = this.minSpawnDelay + this.world.rand.zrange(i); } } diff --git a/common/src/main/java/common/tileentity/DeviceTianReactor.java b/common/src/main/java/common/tileentity/DeviceTianReactor.java index 6a54af03..8f59afb4 100755 --- a/common/src/main/java/common/tileentity/DeviceTianReactor.java +++ b/common/src/main/java/common/tileentity/DeviceTianReactor.java @@ -43,8 +43,8 @@ public class DeviceTianReactor extends Device { } public void detonate() { - this.worldObj.setBlockToAir(getPos()); - this.worldObj.newExplosion(this.getXPos(), this.getYPos(), this.getZPos(), 120); + this.world.setBlockToAir(getPos()); + this.world.newExplosion(this.getXPos(), this.getYPos(), this.getZPos(), 120); } public String formatDisplay(ContainerTile inv) { diff --git a/common/src/main/java/common/tileentity/ITickable.java b/common/src/main/java/common/tileentity/ITickable.java index 7227b5e8..2a345741 100755 --- a/common/src/main/java/common/tileentity/ITickable.java +++ b/common/src/main/java/common/tileentity/ITickable.java @@ -1,6 +1,5 @@ package common.tileentity; -public interface ITickable -{ - void update(); +public interface ITickable { + void update(); } diff --git a/common/src/main/java/common/tileentity/TileEntity.java b/common/src/main/java/common/tileentity/TileEntity.java index caf96ffa..5f6edbd4 100755 --- a/common/src/main/java/common/tileentity/TileEntity.java +++ b/common/src/main/java/common/tileentity/TileEntity.java @@ -12,110 +12,69 @@ import common.world.Chunk; import common.world.State; import common.world.World; -public abstract class TileEntity -{ - public static enum EnumCreateEntityType - { - IMMEDIATE, - QUEUED, - CHECK; +public abstract class TileEntity { + public static enum CreateMode { + IMMEDIATE, + QUEUED, + CHECK; } - /** the instance of the world the tile entity is in. */ - protected World worldObj; - protected BlockPos pos = BlockPos.ORIGIN; - protected boolean tileEntityInvalid; - private State blockState = null; + protected World world; + protected BlockPos pos = BlockPos.ORIGIN; + private boolean invalid; + private State state = null; + private Block block = null; - /** the Block type that this TileEntity is contained within */ - protected Block blockType; + public static TileEntity createTile(AWorldServer world, Chunk chunk, BlockPos pos, TagObject tag) { + Block block = chunk.getState(pos).getBlock(); + if(!(block instanceof ITileEntityProvider provider)) { + Log.TICK.warn("Ignoriere Block-Objekt von unbekanntem Block %s in Chunk %d, %d", BlockRegistry.getName(block), chunk.xPos, chunk.zPos); + return null; + } + TileEntity te = provider.createNewTileEntity(); + te.setPos(pos); + te.readTags(tag); + return te; + } - /** - * Returns the worldObj for this tileEntity. - */ - public World getWorld() - { - return this.worldObj; - } + public final World getWorld() { + return this.world; + } - /** - * Sets the worldObj for this tileEntity. - */ - public void setWorldObj(World worldIn) - { - this.worldObj = worldIn; - } + public final void setWorld(World world) { + this.world = world; + } - /** - * Returns true if the worldObj isn't null. - */ - public boolean hasWorldObj() - { - return this.worldObj != null; - } + public final State getState() { + if(this.state == null) + this.state = this.world.getState(this.pos); + return this.state; + } - public void readTags(TagObject compound) - { - } + public final Block getBlock() { + if(this.block == null) + this.block = this.world.getState(this.pos).getBlock(); + return this.block; + } - public void writeTags(TagObject compound) - { - } + public final void markDirty() { + if(this.world != null) { + this.state = this.world.getState(this.pos); + if(!this.world.client) + ((AWorldServer)this.world).markChunkDirty(this.pos); + } + } - public static TileEntity createAndLoadEntity(AWorldServer world, Chunk chunk, BlockPos pos, TagObject tag) - { - Block block = chunk.getState(pos).getBlock(); - if(!(block instanceof ITileEntityProvider provider)) { - Log.TICK.warn("Ignoriere Block-Objekt von unbekanntem Block %s in Chunk %d, %d", BlockRegistry.getName(block), chunk.xPos, chunk.zPos); - return null; - } - TileEntity te = provider.createNewTileEntity(); - te.setPos(pos); - te.readTags(tag); - return te; - } + public final double getDistanceSq(double x, double y, double z) { + double dx = (double)this.pos.getX() + 0.5D - x; + double dy = (double)this.pos.getY() + 0.5D - y; + double dz = (double)this.pos.getZ() + 0.5D - z; + return dx * dx + dy * dy + dz * dz; + } - public State getBlockState() - { - if(this.blockState == null) - this.blockState = this.worldObj.getState(this.pos); - return this.blockState; - } - - /** - * For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it - * hasn't changed and skip it. - */ - public void markDirty() - { - if (this.worldObj != null) - { - this.blockState = this.worldObj.getState(this.pos); - if(!this.worldObj.client) - ((AWorldServer)this.worldObj).markChunkDirty(this.pos); - } - } - - /** - * Returns the square of the distance between this entity and the passed in coordinates. - */ - public double getDistanceSq(double x, double y, double z) - { - double d0 = (double)this.pos.getX() + 0.5D - x; - double d1 = (double)this.pos.getY() + 0.5D - y; - double d2 = (double)this.pos.getZ() + 0.5D - z; - return d0 * d0 + d1 * d1 + d2 * d2; - } - - public double getMaxRenderDistanceSquared() - { - return 4096.0D; - } - - public final BlockPos getPos() - { - return this.pos; - } + public final BlockPos getPos() { + return this.pos; + } public final double getXPos() { return (double)this.pos.getX() + 0.5D; @@ -129,68 +88,41 @@ public abstract class TileEntity return (double)this.pos.getZ() + 0.5D; } - /** - * Gets the block type at the location of this entity (client-only). - */ - public Block getBlockType() - { - if (this.blockType == null) - { - this.blockType = this.worldObj.getState(this.pos).getBlock(); - } + public final boolean isInvalid() { + return this.invalid; + } - return this.blockType; - } + public final void invalidate() { + this.invalid = true; + } - /** - * Allows for a specialized description packet to be created. This is often used to sync tile entity data from the - * server to the client easily. For example this is used by signs to synchronise the text to be displayed. - */ - public Packet getDescriptionPacket() - { - return null; - } + public final boolean validate() { + this.invalid = false; + return false; + } - public boolean isInvalid() - { - return this.tileEntityInvalid; - } + public final void resetBlock() { + this.block = null; + this.state = null; + } - /** - * invalidates a tile entity - */ - public void invalidate() - { - this.tileEntityInvalid = true; - } + public final void setPos(BlockPos posIn) { + this.pos = posIn; + } - /** - * validates a tile entity - */ - public boolean validate() - { - this.tileEntityInvalid = false; - return false; - } + public void readTags(TagObject compound) { + } - public void updateContainingBlockInfo() - { - this.blockType = null; - this.blockState = null; - } + public void writeTags(TagObject compound) { + } - public void setPos(BlockPos posIn) - { - this.pos = posIn; - } - - public abstract int getColor(); - - public boolean hasPower() { - return true; - } - - public boolean decrPower() { - return true; - } + public double getMaxRenderDistanceSquared() { + return 4096.0D; + } + + public Packet getDescriptionPacket() { + return null; + } + + public abstract int getColor(); } diff --git a/common/src/main/java/common/tileentity/TileEntityChest.java b/common/src/main/java/common/tileentity/TileEntityChest.java index 520edf3c..19d81237 100755 --- a/common/src/main/java/common/tileentity/TileEntityChest.java +++ b/common/src/main/java/common/tileentity/TileEntityChest.java @@ -106,7 +106,7 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory public String getName() { - return this.customName != null && !this.customName.isEmpty() ? this.customName : this.getBlockType().getDisplay(); + return this.customName != null && !this.customName.isEmpty() ? this.customName : this.getBlock().getDisplay(); } public void setCustomName(String name) @@ -170,7 +170,7 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory */ public boolean isUseableByPlayer(EntityNPC player) { - return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; + return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; } /** @@ -183,12 +183,12 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory int k = this.pos.getZ(); ++this.ticksSinceSync; - if (!this.worldObj.client && this.numPlayersUsing != 0 && (this.ticksSinceSync + i + j + k) % 200 == 0) + if (!this.world.client && this.numPlayersUsing != 0 && (this.ticksSinceSync + i + j + k) % 200 == 0) { this.numPlayersUsing = 0; float f = 5.0F; - for (EntityNPC entityplayer : this.worldObj.getEntitiesWithinAABB(EntityNPC.class, new BoundingBox((double)((float)i - f), (double)((float)j - f), (double)((float)k - f), (double)((float)(i + 1) + f), (double)((float)(j + 1) + f), (double)((float)(k + 1) + f)))) + for (EntityNPC entityplayer : this.world.getEntitiesWithinAABB(EntityNPC.class, new BoundingBox((double)((float)i - f), (double)((float)j - f), (double)((float)k - f), (double)((float)(i + 1) + f), (double)((float)(j + 1) + f), (double)((float)(k + 1) + f)))) { if (entityplayer.isPlayer() && entityplayer.openContainer instanceof ContainerChest) { @@ -206,7 +206,7 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory { double d3 = (double)i + 0.5D; double d0 = (double)k + 0.5D; - this.worldObj.sendSound((this.wasOpen = this.numPlayersUsing > 0) ? SoundEvent.CHESTOPEN : SoundEvent.CHESTCLOSED, d3, (double)j + 0.5D, d0, 0.5F); + this.world.sendSound((this.wasOpen = this.numPlayersUsing > 0) ? SoundEvent.CHESTOPEN : SoundEvent.CHESTCLOSED, d3, (double)j + 0.5D, d0, 0.5F); } } @@ -225,23 +225,23 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory } ++this.numPlayersUsing; - this.worldObj.playEffect(2016, this.pos, this.numPlayersUsing); - if(!this.worldObj.client) { - ((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos, this.getBlockType()); - ((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType()); + this.world.playEffect(2016, this.pos, this.numPlayersUsing); + if(!this.world.client) { + ((AWorldServer)this.world).notifyNeighborsOfStateChange(this.pos, this.getBlock()); + ((AWorldServer)this.world).notifyNeighborsOfStateChange(this.pos.down(), this.getBlock()); } // } } public void onClosed() { - if (/* !player.isSpectator() && */ this.getBlockType() instanceof BlockChest) + if (/* !player.isSpectator() && */ this.getBlock() instanceof BlockChest) { --this.numPlayersUsing; - this.worldObj.playEffect(2016, this.pos, this.numPlayersUsing); - if(!this.worldObj.client) { - ((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos, this.getBlockType()); - ((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType()); + this.world.playEffect(2016, this.pos, this.numPlayersUsing); + if(!this.world.client) { + ((AWorldServer)this.world).notifyNeighborsOfStateChange(this.pos, this.getBlock()); + ((AWorldServer)this.world).notifyNeighborsOfStateChange(this.pos.down(), this.getBlock()); } } } diff --git a/common/src/main/java/common/tileentity/TileEntityPipe.java b/common/src/main/java/common/tileentity/TileEntityPipe.java index c9e241ef..90a879e2 100755 --- a/common/src/main/java/common/tileentity/TileEntityPipe.java +++ b/common/src/main/java/common/tileentity/TileEntityPipe.java @@ -7,7 +7,6 @@ import common.block.Block; import common.block.ITileEntityProvider; import common.block.tech.BlockChest; import common.block.tech.BlockPipe; -import common.collect.Lists; import common.entity.Entity; import common.entity.item.EntityItem; import common.entity.npc.EntityNPC; @@ -25,85 +24,55 @@ import common.world.World; public class TileEntityPipe extends TileEntity implements IInventory, ITickable { - private ItemStack[] inventory = new ItemStack[5]; - private int transferCooldown = -1; + private ItemStack inventory = null; + private int cooldown = -1; - public void readTags(TagObject compound) + public void readTags(TagObject tag) { - super.readTags(compound); - List nbttaglist = compound.getList("Items"); - this.inventory = new ItemStack[this.getSizeInventory()]; + super.readTags(tag); + this.cooldown = tag.getInt("Cooldown"); + this.inventory = ItemStack.readFromTag(tag.getObject("Item")); + } - this.transferCooldown = compound.getInt("TransferCooldown"); - - for (int i = 0; i < nbttaglist.size(); ++i) + public void writeTags(TagObject tag) + { + super.writeTags(tag); + tag.setInt("Cooldown", this.cooldown); + if (this.inventory != null) { - TagObject nbttagcompound = nbttaglist.get(i); - int j = nbttagcompound.getByte("Slot"); - - if (j >= 0 && j < this.inventory.length) - { - this.inventory[j] = ItemStack.readFromTag(nbttagcompound); - } + TagObject item = new TagObject(); + this.inventory.writeTags(item); + tag.setObject("Item", item); } } - public void writeTags(TagObject compound) - { - super.writeTags(compound); - List nbttaglist = Lists.newArrayList(); - - for (int i = 0; i < this.inventory.length; ++i) - { - if (this.inventory[i] != null) - { - TagObject nbttagcompound = new TagObject(); - nbttagcompound.setByte("Slot", (byte)i); - this.inventory[i].writeTags(nbttagcompound); - nbttaglist.add(nbttagcompound); - } - } - - compound.setList("Items", nbttaglist); - compound.setInt("TransferCooldown", this.transferCooldown); - } - - /** - * Returns the number of slots in the inventory. - */ public int getSizeInventory() { - return this.inventory.length; + return 1; } - /** - * Returns the stack in the given slot. - */ public ItemStack getStackInSlot(int index) { - return this.inventory[index]; + return this.inventory; } - /** - * Removes up to a specified number of items from an inventory slot and returns them in a new stack. - */ public ItemStack decrStackSize(int index, int count) { - if (this.inventory[index] != null) + if (this.inventory != null) { - if (this.inventory[index].getSize() <= count) + if (this.inventory.getSize() <= count) { - ItemStack itemstack1 = this.inventory[index]; - this.inventory[index] = null; + ItemStack itemstack1 = this.inventory; + this.inventory = null; return itemstack1; } else { - ItemStack itemstack = this.inventory[index].split(count); + ItemStack itemstack = this.inventory.split(count); - if (this.inventory[index].isEmpty()) + if (this.inventory.isEmpty()) { - this.inventory[index] = null; + this.inventory = null; } return itemstack; @@ -115,15 +84,12 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable } } - /** - * Removes a stack from the given slot and returns it. - */ public ItemStack removeStackFromSlot(int index) { - if (this.inventory[index] != null) + if (this.inventory != null) { - ItemStack itemstack = this.inventory[index]; - this.inventory[index] = null; + ItemStack itemstack = this.inventory; + this.inventory = null; return itemstack; } else @@ -132,30 +98,26 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable } } - /** - * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). - */ public void setInventorySlotContents(int index, ItemStack stack) { - this.inventory[index] = stack; + this.inventory = stack; + } + + public void clear() + { + this.inventory = null; } - /** - * Do not make give this method the name canInteractWith because it clashes with Container - */ public boolean isUseableByPlayer(EntityNPC player) { - return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; + return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; } - /** - * Like the old updateEntity(), except more generic. - */ public void update() { - if (this.worldObj != null && !this.worldObj.client) + if (this.world != null && !this.world.client) { - --this.transferCooldown; + --this.cooldown; if (!this.isOnTransferCooldown()) { @@ -167,12 +129,12 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable public boolean updatePipe() { - if (this.worldObj != null && !this.worldObj.client) + if (this.world != null && !this.world.client) { if (!this.isOnTransferCooldown()) { - State state = this.getBlockState(); - if(!(state.getBlock() instanceof BlockPipe) || !this.decrPower()) + State state = this.getState(); + if(!(state.getBlock() instanceof BlockPipe) /* || !this.decrPower() */) // TODO: power return false; boolean flag = false; @@ -204,28 +166,12 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable private boolean isEmpty() { - for (ItemStack itemstack : this.inventory) - { - if (itemstack != null) - { - return false; - } - } - - return true; + return this.inventory == null; } private boolean isFull() { - for (ItemStack itemstack : this.inventory) - { - if (itemstack == null || !itemstack.isFull()) - { - return false; - } - } - - return true; + return this.inventory != null && this.inventory.isFull(); } private boolean transferItemsOut() @@ -238,7 +184,7 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable } else { - State state = this.getBlockState(); + State state = this.getState(); Facing enumfacing = state.getBlock() instanceof BlockPipe ? state.getValue(BlockPipe.FACING).getOpposite() : Facing.DOWN; if (isInventoryFull(iinventory, enumfacing)) @@ -376,7 +322,7 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable } else if(down) { - for (EntityItem entityitem : func_181556_a(te.getWorld(), te.getXPos(), te.getYPos() + 1.0D, te.getZPos())) + for (EntityItem entityitem : findDroppedItems(te.getWorld(), te.getXPos(), te.getYPos() + 1.0D, te.getZPos())) { if (putDropInInventoryAllSlots(te, entityitem)) { @@ -522,7 +468,7 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable private IInventory getInventoryForTransfer() { - State state = this.getBlockState(); + State state = this.getState(); Facing enumfacing = state.getBlock() instanceof BlockPipe ? state.getValue(BlockPipe.FACING) : Facing.DOWN; return getInventoryAtPosition(this.getWorld(), (double)(this.pos.getX() + enumfacing.getFrontOffsetX()), (double)(this.pos.getY() + enumfacing.getFrontOffsetY()), (double)(this.pos.getZ() + enumfacing.getFrontOffsetZ())); } @@ -532,9 +478,9 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable return getInventoryAtPosition(pipe.getWorld(), pipe.getXPos(), pipe.getYPos() + (down ? -1.0 : 1.0), pipe.getZPos()); } - public static List func_181556_a(World p_181556_0_, double p_181556_1_, double p_181556_3_, double p_181556_5_) + public static List findDroppedItems(World world, double x, double y, double z) { - return p_181556_0_.getEntitiesWithinAABB(EntityItem.class, new BoundingBox(p_181556_1_ - 0.5D, p_181556_3_ - 0.5D, p_181556_5_ - 0.5D, p_181556_1_ + 0.5D, p_181556_3_ + 0.5D, p_181556_5_ + 0.5D), new Predicate() { + return world.getEntitiesWithinAABB(EntityItem.class, new BoundingBox(x - 0.5D, y - 0.5D, z - 0.5D, x + 0.5D, y + 0.5D, z + 0.5D), new Predicate() { public boolean test(EntityItem entity) { return entity.isEntityAlive(); } @@ -589,25 +535,17 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable public void setTransferCooldown(int ticks) { - this.transferCooldown = ticks; + this.cooldown = ticks; } public boolean isOnTransferCooldown() { - return this.transferCooldown > 0; + return this.cooldown > 0; } public boolean mayTransfer() { - return this.transferCooldown <= 1; - } - - public void clear() - { - for (int i = 0; i < this.inventory.length; ++i) - { - this.inventory[i] = null; - } + return this.cooldown <= 1; } public int getColor() { diff --git a/common/src/main/java/common/world/Chunk.java b/common/src/main/java/common/world/Chunk.java index 55601a79..9410020b 100755 --- a/common/src/main/java/common/world/Chunk.java +++ b/common/src/main/java/common/world/Chunk.java @@ -376,10 +376,10 @@ public abstract class Chunk { } if(oldb instanceof ITileEntityProvider) { - TileEntity tile = this.getTileEntity(pos, TileEntity.EnumCreateEntityType.CHECK); + TileEntity tile = this.getTileEntity(pos, TileEntity.CreateMode.CHECK); if(tile != null) { - tile.updateContainingBlockInfo(); + tile.resetBlock(); } } @@ -388,7 +388,7 @@ public abstract class Chunk { } if(block instanceof ITileEntityProvider) { - TileEntity tile = this.getTileEntity(pos, TileEntity.EnumCreateEntityType.CHECK); + TileEntity tile = this.getTileEntity(pos, TileEntity.CreateMode.CHECK); if(tile == null) { tile = ((ITileEntityProvider)block).createNewTileEntity(); @@ -396,7 +396,7 @@ public abstract class Chunk { } if(tile != null) { - tile.updateContainingBlockInfo(); + tile.resetBlock(); } } @@ -519,15 +519,15 @@ public abstract class Chunk { return !(block instanceof ITileEntityProvider provider) ? null : provider.createNewTileEntity(); } - public TileEntity getTileEntity(BlockPos pos, TileEntity.EnumCreateEntityType type) { + public TileEntity getTileEntity(BlockPos pos, TileEntity.CreateMode type) { TileEntity tile = this.tiles.get(pos); if(tile == null) { - if(type == TileEntity.EnumCreateEntityType.IMMEDIATE) { + if(type == TileEntity.CreateMode.IMMEDIATE) { tile = this.createNewTileEntity(pos); this.world.setTileEntity(pos, tile); } - else if(type == TileEntity.EnumCreateEntityType.QUEUED) { + else if(type == TileEntity.CreateMode.QUEUED) { this.tileQueue.add(pos); } } @@ -540,7 +540,7 @@ public abstract class Chunk { } public void addTileEntity(BlockPos pos, TileEntity tile) { - tile.setWorldObj(this.world); + tile.setWorld(this.world); tile.setPos(pos); if(this.getBlock(pos) instanceof ITileEntityProvider) { @@ -655,7 +655,7 @@ public abstract class Chunk { while(!this.tileQueue.isEmpty()) { BlockPos pos = (BlockPos)this.tileQueue.poll(); - if(this.getTileEntity(pos, TileEntity.EnumCreateEntityType.CHECK) == null && this.getBlock(pos) instanceof ITileEntityProvider) { + if(this.getTileEntity(pos, TileEntity.CreateMode.CHECK) == null && this.getBlock(pos) instanceof ITileEntityProvider) { TileEntity tile = this.createNewTileEntity(pos); this.world.setTileEntity(pos, tile); this.world.markBlockRangeForRenderUpdate(pos, pos); diff --git a/common/src/main/java/common/world/World.java b/common/src/main/java/common/world/World.java index a34b87d1..f6645486 100755 --- a/common/src/main/java/common/world/World.java +++ b/common/src/main/java/common/world/World.java @@ -914,7 +914,7 @@ public abstract class World implements IWorldAccess { while(iterator.hasNext()) { TileEntity tileentity = (TileEntity)iterator.next(); - if(!tileentity.isInvalid() && tileentity.hasWorldObj()) { + if(!tileentity.isInvalid() && tileentity.getWorld() != null) { BlockPos blockpos = tileentity.getPos(); if(this.isBlockLoaded(blockpos)) { // && this.border.contains(blockpos)) { @@ -1329,7 +1329,7 @@ public abstract class World implements IWorldAccess { } if(tileentity == null) { - tileentity = this.getChunk(pos).getTileEntity(pos, TileEntity.EnumCreateEntityType.IMMEDIATE); + tileentity = this.getChunk(pos).getTileEntity(pos, TileEntity.CreateMode.IMMEDIATE); } if(tileentity == null) { diff --git a/server/src/main/java/server/command/commands/CommandBlock.java b/server/src/main/java/server/command/commands/CommandBlock.java index bf03a5ec..ada18702 100644 --- a/server/src/main/java/server/command/commands/CommandBlock.java +++ b/server/src/main/java/server/command/commands/CommandBlock.java @@ -50,7 +50,7 @@ public class CommandBlock extends Command { TagObject te = new TagObject(); tile.writeTags(te); te.merge(tag); - TileEntity newTile = TileEntity.createAndLoadEntity(world, world.getChunk(position), position, te); + TileEntity newTile = TileEntity.createTile(world, world.getChunk(position), position, te); if(newTile != null) { world.removeTileEntity(position); world.setTileEntity(position, newTile); diff --git a/server/src/main/java/server/command/commands/CommandSet.java b/server/src/main/java/server/command/commands/CommandSet.java index dc239a44..59c8e238 100644 --- a/server/src/main/java/server/command/commands/CommandSet.java +++ b/server/src/main/java/server/command/commands/CommandSet.java @@ -67,7 +67,7 @@ public class CommandSet extends Command { TagObject te = new TagObject(); tile.writeTags(te); te.merge(tag); - TileEntity newTile = TileEntity.createAndLoadEntity(world, world.getChunk(pos), pos, te); + TileEntity newTile = TileEntity.createTile(world, world.getChunk(pos), pos, te); if(newTile != null) { world.removeTileEntity(pos); world.setTileEntity(pos, newTile); diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index b135781e..d8f2f6eb 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -734,7 +734,7 @@ public class Player extends User implements Executor, IPlayer } else if (object instanceof TileEntityChest chest) { - this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), chest.getBlockType(), chest.getSizeInventory())); + this.sendPacket(new SPacketOpenWindow(this.getNextWindowId(), chest.getBlock(), chest.getSizeInventory())); this.entity.openContainer = new ContainerChest(this.entity, chest); } else if (object instanceof InteractionObject obj) diff --git a/server/src/main/java/server/world/Region.java b/server/src/main/java/server/world/Region.java index 8a6842f4..4f0657e8 100755 --- a/server/src/main/java/server/world/Region.java +++ b/server/src/main/java/server/world/Region.java @@ -553,7 +553,7 @@ public class Region { continue; } pos = new BlockPos(chunk.xPos << 4 | pos.getX(), pos.getY(), chunk.zPos << 4 | pos.getZ()); - TileEntity tileentity = TileEntity.createAndLoadEntity(world, chunk, pos, tile); + TileEntity tileentity = TileEntity.createTile(world, chunk, pos, tile); if(tileentity != null) { chunk.addTileEntity(tileentity); diff --git a/server/src/main/java/server/world/WorldServer.java b/server/src/main/java/server/world/WorldServer.java index b4f1704c..adad5fba 100755 --- a/server/src/main/java/server/world/WorldServer.java +++ b/server/src/main/java/server/world/WorldServer.java @@ -1900,7 +1900,7 @@ public final class WorldServer extends AWorldServer { if(block.getData() != null) { this.removeTileEntity(pos); TagObject tag = block.getData(); - TileEntity tileEntity = TileEntity.createAndLoadEntity(this, chunk, pos, tag); + TileEntity tileEntity = TileEntity.createTile(this, chunk, pos, tag); if(tileEntity != null) { this.setTileEntity(pos, tileEntity); }