1
0
Fork 0

te cleanup

This commit is contained in:
Sen 2025-08-12 20:02:43 +02:00
parent bed1537d9a
commit 96674df391
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
25 changed files with 246 additions and 384 deletions

View file

@ -30,7 +30,7 @@ public class GuiDevice extends GuiContainer {
public void updateScreen() { public void updateScreen() {
super.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)); this.desc.setText(this.tile.formatDisplay((ContainerTile)this.inventorySlots));
if(this.progress != null) { if(this.progress != null) {
this.progress.setText(this.tile.getTotal() <= 0 || this.tile.getProgress() < 0 ? "" : String.format("%d/%d (%.1f %%)", this.progress.setText(this.tile.getTotal() <= 0 || this.tile.getProgress() < 0 ? "" : String.format("%d/%d (%.1f %%)",

View file

@ -1200,7 +1200,7 @@ public class ClientPlayer implements IClientPlayer
if (!(tileentity instanceof TileEntitySign)) if (!(tileentity instanceof TileEntitySign))
{ {
tileentity = new TileEntitySign(); tileentity = new TileEntitySign();
tileentity.setWorldObj(this.world); tileentity.setWorld(this.world);
tileentity.setPos(packetIn.getSignPosition()); tileentity.setPos(packetIn.getSignPosition());
} }
@ -1262,7 +1262,7 @@ public class ClientPlayer implements IClientPlayer
NetHandler.checkThread(packet, this, this.gm, this.world); NetHandler.checkThread(packet, this, this.gm, this.world);
if(this.gm.world.isBlockLoaded(packet.getPos())) { if(this.gm.world.isBlockLoaded(packet.getPos())) {
TileEntity te = this.gm.world.getTileEntity(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()); te.readTags(packet.getTag());
} }
} }

View file

@ -67,7 +67,7 @@ public class RegionRenderCache implements IWorldAccess
{ {
int i = (pos.getX() >> 4) - this.xPos; int i = (pos.getX() >> 4) - this.xPos;
int j = (pos.getZ() >> 4) - this.zPos; 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) public int getCombinedLight(BlockPos pos, int lightValue)

View file

@ -80,9 +80,9 @@ public class DisplayRenderer extends ElementRenderer<TileEntityDisplay> {
} }
public void renderElements(TileEntityDisplay te, double x, double y, double z, float partialTicks) { 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; Facing dir = state.getBlock() instanceof BlockDisplay ? state.getValue(BlockDisplay.FACING) : Facing.SOUTH;
float rot = 0.0F; float rot = 0.0F;
if(dir == Facing.NORTH) if(dir == Facing.NORTH)

View file

@ -17,7 +17,7 @@ public class SignRenderer extends ElementRenderer<TileEntitySign>
GL11.glPushMatrix(); GL11.glPushMatrix();
float f = 0.6666667F; float f = 0.6666667F;
State state = te.getBlockState(); State state = te.getState();
if (state.getBlock() instanceof BlockStandingSign) if (state.getBlock() instanceof BlockStandingSign)
{ {
GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F * f, (float)z + 0.5F); GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F * f, (float)z + 0.5F);

View file

@ -127,7 +127,7 @@ public class ChunkClient extends Chunk {
this.genHeights(); this.genHeights();
for(TileEntity tile : this.tiles.values()) { for(TileEntity tile : this.tiles.values()) {
tile.updateContainingBlockInfo(); tile.resetBlock();
} }
} }

View file

@ -94,7 +94,7 @@ public class ChunkEmpty extends ChunkClient {
return pos.getY() > this.liquidY; return pos.getY() > this.liquidY;
} }
public TileEntity getTileEntity(BlockPos pos, TileEntity.EnumCreateEntityType type) { public TileEntity getTileEntity(BlockPos pos, TileEntity.CreateMode type) {
return null; return null;
} }

View file

@ -22,7 +22,7 @@ public class SPacketUpdateDevice implements Packet<IClientPlayer> {
public SPacketUpdateDevice(TileEntity tile) { public SPacketUpdateDevice(TileEntity tile) {
this.position = tile.getPos(); this.position = tile.getPos();
this.type = tile.getBlockType(); this.type = tile.getBlock();
tile.writeTags(this.tag = new TagObject()); tile.writeTags(this.tag = new TagObject());
} }

View file

@ -220,7 +220,7 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
} }
public boolean isUseableByPlayer(EntityNPC player) { 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; : 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() { public void detonate() {
this.worldObj.setBlockToAir(getPos()); this.world.setBlockToAir(getPos());
this.worldObj.newExplosion(null, this.getXPos(), this.getYPos(), this.getZPos(), 5.0f, true, true, false); this.world.newExplosion(null, this.getXPos(), this.getYPos(), this.getZPos(), 5.0f, true, true, false);
} }
public void update() { public void update() {
if(this.worldObj != null && !this.worldObj.client && this.status != Status.BROKEN) { if(this.world != null && !this.world.client && this.status != Status.BROKEN) {
int envTemp = (int)this.worldObj.getTemperatureC(this.getPos()); int envTemp = (int)this.world.getTemperatureC(this.getPos());
if(this.executeFunction()) { if(this.executeFunction()) {
if(this.hasTemperature()) { if(this.hasTemperature()) {
if(this.getTempIncrement() < 0) if(this.getTempIncrement() < 0)

View file

@ -10,76 +10,69 @@ import common.vars.Vars;
import common.world.AWorldServer; import common.world.AWorldServer;
import common.world.State; import common.world.State;
public class DeviceDispenser extends Device public class DeviceDispenser extends Device {
{
private static final Random RNG = new Random(); private static final Random RNG = new Random();
private final boolean dropItems; private final boolean dropItems;
private int cooldown = 0; private int cooldown = 0;
public DeviceDispenser(boolean dropItems) { public DeviceDispenser(boolean dropItems) {
super(1, 0); super(1, 0);
this.dropItems = dropItems; this.dropItems = dropItems;
} }
public boolean addItemStack(ItemStack stack) public boolean addItemStack(ItemStack stack) {
{ if(this.getStackInSlot(0) == null) {
if (this.getStackInSlot(0) == null) this.setInventorySlotContents(0, stack);
{ return true;
this.setInventorySlotContents(0, stack); }
return true; return false;
} }
return false;
}
public void readTags(TagObject compound) public void readTags(TagObject compound) {
{ super.readTags(compound);
super.readTags(compound); this.cooldown = compound.getInt("Cooldown");
this.cooldown = compound.getInt("Cooldown"); }
}
public void writeTags(TagObject compound) public void writeTags(TagObject compound) {
{ super.writeTags(compound);
super.writeTags(compound); compound.setInt("Cooldown", this.cooldown);
compound.setInt("Cooldown", this.cooldown); }
}
private ItemStack dispenseStack(ItemStack stack, AWorldServer world, BlockPos pos) private ItemStack dispenseStack(ItemStack stack, AWorldServer world, BlockPos pos) {
{ Facing facing = world.getState(pos).getValue(BlockDispenser.FACING);
Facing facing = world.getState(pos).getValue(BlockDispenser.FACING); if(this.dropItems) {
if(this.dropItems) { BlockDispenser.dispense(world, 6.0, facing, BlockDispenser.getDispensePosition(pos, facing), stack.split(1));
BlockDispenser.dispense(world, 6.0, facing, BlockDispenser.getDispensePosition(pos, facing), stack.split(1)); world.playEffect(1000, pos, 0);
world.playEffect(1000, pos, 0); world.playEffect(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3);
world.playEffect(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3); return stack;
return stack; }
} ItemStack nstack = stack.getItem().dispenseStack(world, world.getTileEntity(pos), BlockDispenser.getDispensePosition(pos, facing), pos, facing, stack);
ItemStack nstack = stack.getItem().dispenseStack(world, world.getTileEntity(pos), BlockDispenser.getDispensePosition(pos, facing), pos, facing, stack); int id = stack.getItem().getDispenseSoundId();
int id = stack.getItem().getDispenseSoundId(); if(id != 0)
if(id != 0) world.playEffect(id, pos, 0);
world.playEffect(id, pos, 0); world.playEffect(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3);
world.playEffect(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3); return nstack;
return nstack; }
}
public boolean executeFunction() { public boolean executeFunction() {
if (this.cooldown <= 0) if(this.cooldown <= 0) {
{ State state = this.getState();
State state = this.getBlockState(); if(!(state.getBlock() instanceof BlockDispenser) /* || !this.decrPower() */) // TODO: energy
if(!(state.getBlock() instanceof BlockDispenser) /* || !this.decrPower() */) //TODO: energy return false;
return false; ItemStack stack = this.getStackInSlot(0);
ItemStack stack = this.getStackInSlot(0); if(stack != null) {
if(stack != null) { ItemStack nstack = this.dispenseStack(stack, (AWorldServer)this.world, this.pos);
ItemStack nstack = this.dispenseStack(stack, (AWorldServer)this.worldObj, this.pos); this.setInventorySlotContents(0, nstack != null && nstack.isEmpty() ? null : nstack);
this.setInventorySlotContents(0, nstack != null && nstack.isEmpty() ? null : nstack); this.cooldown = Vars.dispenserDelay;
this.cooldown = Vars.dispenserDelay; return true;
return true; }
} return false;
return false; }
} else {
else { this.cooldown--;
this.cooldown--; return true;
return true; }
}
} }
} }

View file

@ -32,7 +32,7 @@ public class DeviceEffectGenerator extends Device {
double y = this.pos.getY(); double y = this.pos.getY();
double z = this.pos.getZ(); 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); 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<EntityNPC> list = this.worldObj.<EntityNPC>getEntitiesWithinAABB(EntityNPC.class, bb); List<EntityNPC> list = this.world.<EntityNPC>getEntitiesWithinAABB(EntityNPC.class, bb);
for(EntityNPC entity : list) { for(EntityNPC entity : list) {
if(!entity.hasEffect(effect.getPotion()) || entity.getEffect(effect.getPotion()).getAmplifier() < effect.getAmplifier() || entity.getEffect(effect.getPotion()).getRemaining() < 40) { 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())); entity.addEffect(new StatusEffect(effect.getPotion(), 180, effect.getAmplifier()));

View file

@ -81,8 +81,8 @@ public class DeviceFurnace extends Device implements ISidedInventory
if (this.getStackInSlot(1) != null) if (this.getStackInSlot(1) != null)
{ {
if(Vars.itemExplosion && this.getStackInSlot(1).getItem().getExplosive() > 0 && !this.getStackInSlot(1).isEmpty()) { if(Vars.itemExplosion && this.getStackInSlot(1).getItem().getExplosive() > 0 && !this.getStackInSlot(1).isEmpty()) {
this.worldObj.setBlockToAir(getPos()); this.world.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.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); this.setInventorySlotContents(1, null);
return false; return false;
} }
@ -120,9 +120,9 @@ public class DeviceFurnace extends Device implements ISidedInventory
if (flag != this.isBurning()) if (flag != this.isBurning())
{ {
flag1 = true; flag1 = true;
Block block = this.getBlockType(); Block block = this.getBlock();
if(block instanceof BlockFurnace furnace) if(block instanceof BlockFurnace furnace)
furnace.setState(this.isBurning(), this.worldObj, this.pos); furnace.setState(this.isBurning(), this.world, this.pos);
} }
if (flag1) if (flag1)

View file

@ -9,7 +9,7 @@ import common.item.spawner.ItemCharTemplate;
import common.tags.TagObject; import common.tags.TagObject;
import common.vars.Vars; import common.vars.Vars;
public class DeviceMobSpawner extends Device implements ITickable public class DeviceMobSpawner extends Device
{ {
public DeviceMobSpawner() { public DeviceMobSpawner() {
super(1, 0); super(1, 0);
@ -43,14 +43,14 @@ public class DeviceMobSpawner extends Device implements ITickable
ItemStack stack = this.getStackInSlot(0); ItemStack stack = this.getStackInSlot(0);
if(stack == null) if(stack == null)
return true; return true;
double x = (double)this.pos.getX() + (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.worldObj.rand.zrange(3) - 1); double y = (double)(this.pos.getY() + this.world.rand.zrange(3) - 1);
double z = (double)this.pos.getZ() + (this.worldObj.rand.doublev() - this.worldObj.rand.doublev()) * (double)this.spawnRange + 0.5D; double z = (double)this.pos.getZ() + (this.world.rand.doublev() - this.world.rand.doublev()) * (double)this.spawnRange + 0.5D;
EntityLiving entity = null; EntityLiving entity = null;
if(stack.getItem() instanceof ItemMobTemplate egg) 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) 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) if (entity == null)
return true; return true;
this.decrStackSize(0, 1); this.decrStackSize(0, 1);
@ -68,7 +68,7 @@ public class DeviceMobSpawner extends Device implements ITickable
else else
{ {
int i = this.maxSpawnDelay - this.minSpawnDelay; int i = this.maxSpawnDelay - this.minSpawnDelay;
this.spawnDelay = this.minSpawnDelay + this.worldObj.rand.zrange(i); this.spawnDelay = this.minSpawnDelay + this.world.rand.zrange(i);
} }
} }

View file

@ -43,8 +43,8 @@ public class DeviceTianReactor extends Device {
} }
public void detonate() { public void detonate() {
this.worldObj.setBlockToAir(getPos()); this.world.setBlockToAir(getPos());
this.worldObj.newExplosion(this.getXPos(), this.getYPos(), this.getZPos(), 120); this.world.newExplosion(this.getXPos(), this.getYPos(), this.getZPos(), 120);
} }
public String formatDisplay(ContainerTile inv) { public String formatDisplay(ContainerTile inv) {

View file

@ -1,6 +1,5 @@
package common.tileentity; package common.tileentity;
public interface ITickable public interface ITickable {
{ void update();
void update();
} }

View file

@ -12,110 +12,69 @@ import common.world.Chunk;
import common.world.State; import common.world.State;
import common.world.World; import common.world.World;
public abstract class TileEntity public abstract class TileEntity {
{ public static enum CreateMode {
public static enum EnumCreateEntityType IMMEDIATE,
{ QUEUED,
IMMEDIATE, CHECK;
QUEUED,
CHECK;
} }
/** the instance of the world the tile entity is in. */ protected World world;
protected World worldObj; protected BlockPos pos = BlockPos.ORIGIN;
protected BlockPos pos = BlockPos.ORIGIN; private boolean invalid;
protected boolean tileEntityInvalid; private State state = null;
private State blockState = null; private Block block = null;
/** the Block type that this TileEntity is contained within */ public static TileEntity createTile(AWorldServer world, Chunk chunk, BlockPos pos, TagObject tag) {
protected Block blockType; 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 World getWorld() {
* Returns the worldObj for this tileEntity. return this.world;
*/ }
public World getWorld()
{
return this.worldObj;
}
/** public final void setWorld(World world) {
* Sets the worldObj for this tileEntity. this.world = world;
*/ }
public void setWorldObj(World worldIn)
{
this.worldObj = worldIn;
}
/** public final State getState() {
* Returns true if the worldObj isn't null. if(this.state == null)
*/ this.state = this.world.getState(this.pos);
public boolean hasWorldObj() return this.state;
{ }
return this.worldObj != null;
}
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) public final double getDistanceSq(double x, double y, double z) {
{ double dx = (double)this.pos.getX() + 0.5D - x;
Block block = chunk.getState(pos).getBlock(); double dy = (double)this.pos.getY() + 0.5D - y;
if(!(block instanceof ITileEntityProvider provider)) { double dz = (double)this.pos.getZ() + 0.5D - z;
Log.TICK.warn("Ignoriere Block-Objekt von unbekanntem Block %s in Chunk %d, %d", BlockRegistry.getName(block), chunk.xPos, chunk.zPos); return dx * dx + dy * dy + dz * dz;
return null; }
}
TileEntity te = provider.createNewTileEntity();
te.setPos(pos);
te.readTags(tag);
return te;
}
public State getBlockState() public final BlockPos getPos() {
{ return this.pos;
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 double getXPos() { public final double getXPos() {
return (double)this.pos.getX() + 0.5D; return (double)this.pos.getX() + 0.5D;
@ -129,68 +88,41 @@ public abstract class TileEntity
return (double)this.pos.getZ() + 0.5D; return (double)this.pos.getZ() + 0.5D;
} }
/** public final boolean isInvalid() {
* Gets the block type at the location of this entity (client-only). return this.invalid;
*/ }
public Block getBlockType()
{
if (this.blockType == null)
{
this.blockType = this.worldObj.getState(this.pos).getBlock();
}
return this.blockType; public final void invalidate() {
} this.invalid = true;
}
/** public final boolean validate() {
* Allows for a specialized description packet to be created. This is often used to sync tile entity data from the this.invalid = false;
* server to the client easily. For example this is used by signs to synchronise the text to be displayed. return false;
*/ }
public Packet getDescriptionPacket()
{
return null;
}
public boolean isInvalid() public final void resetBlock() {
{ this.block = null;
return this.tileEntityInvalid; this.state = null;
} }
/** public final void setPos(BlockPos posIn) {
* invalidates a tile entity this.pos = posIn;
*/ }
public void invalidate()
{
this.tileEntityInvalid = true;
}
/** public void readTags(TagObject compound) {
* validates a tile entity }
*/
public boolean validate()
{
this.tileEntityInvalid = false;
return false;
}
public void updateContainingBlockInfo() public void writeTags(TagObject compound) {
{ }
this.blockType = null;
this.blockState = null;
}
public void setPos(BlockPos posIn) public double getMaxRenderDistanceSquared() {
{ return 4096.0D;
this.pos = posIn; }
}
public Packet getDescriptionPacket() {
public abstract int getColor(); return null;
}
public boolean hasPower() {
return true; public abstract int getColor();
}
public boolean decrPower() {
return true;
}
} }

View file

@ -106,7 +106,7 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory
public String getName() 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) public void setCustomName(String name)
@ -170,7 +170,7 @@ public class TileEntityChest extends TileEntity implements ITickable, IInventory
*/ */
public boolean isUseableByPlayer(EntityNPC player) 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(); int k = this.pos.getZ();
++this.ticksSinceSync; ++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; this.numPlayersUsing = 0;
float f = 5.0F; 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) 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 d3 = (double)i + 0.5D;
double d0 = (double)k + 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.numPlayersUsing;
this.worldObj.playEffect(2016, this.pos, this.numPlayersUsing); this.world.playEffect(2016, this.pos, this.numPlayersUsing);
if(!this.worldObj.client) { if(!this.world.client) {
((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos, this.getBlockType()); ((AWorldServer)this.world).notifyNeighborsOfStateChange(this.pos, this.getBlock());
((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType()); ((AWorldServer)this.world).notifyNeighborsOfStateChange(this.pos.down(), this.getBlock());
} }
// } // }
} }
public void onClosed() public void onClosed()
{ {
if (/* !player.isSpectator() && */ this.getBlockType() instanceof BlockChest) if (/* !player.isSpectator() && */ this.getBlock() instanceof BlockChest)
{ {
--this.numPlayersUsing; --this.numPlayersUsing;
this.worldObj.playEffect(2016, this.pos, this.numPlayersUsing); this.world.playEffect(2016, this.pos, this.numPlayersUsing);
if(!this.worldObj.client) { if(!this.world.client) {
((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos, this.getBlockType()); ((AWorldServer)this.world).notifyNeighborsOfStateChange(this.pos, this.getBlock());
((AWorldServer)this.worldObj).notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType()); ((AWorldServer)this.world).notifyNeighborsOfStateChange(this.pos.down(), this.getBlock());
} }
} }
} }

View file

@ -7,7 +7,6 @@ import common.block.Block;
import common.block.ITileEntityProvider; import common.block.ITileEntityProvider;
import common.block.tech.BlockChest; import common.block.tech.BlockChest;
import common.block.tech.BlockPipe; import common.block.tech.BlockPipe;
import common.collect.Lists;
import common.entity.Entity; import common.entity.Entity;
import common.entity.item.EntityItem; import common.entity.item.EntityItem;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
@ -25,85 +24,55 @@ import common.world.World;
public class TileEntityPipe extends TileEntity implements IInventory, ITickable public class TileEntityPipe extends TileEntity implements IInventory, ITickable
{ {
private ItemStack[] inventory = new ItemStack[5]; private ItemStack inventory = null;
private int transferCooldown = -1; private int cooldown = -1;
public void readTags(TagObject compound) public void readTags(TagObject tag)
{ {
super.readTags(compound); super.readTags(tag);
List<TagObject> nbttaglist = compound.getList("Items"); this.cooldown = tag.getInt("Cooldown");
this.inventory = new ItemStack[this.getSizeInventory()]; this.inventory = ItemStack.readFromTag(tag.getObject("Item"));
}
this.transferCooldown = compound.getInt("TransferCooldown"); public void writeTags(TagObject tag)
{
for (int i = 0; i < nbttaglist.size(); ++i) super.writeTags(tag);
tag.setInt("Cooldown", this.cooldown);
if (this.inventory != null)
{ {
TagObject nbttagcompound = nbttaglist.get(i); TagObject item = new TagObject();
int j = nbttagcompound.getByte("Slot"); this.inventory.writeTags(item);
tag.setObject("Item", item);
if (j >= 0 && j < this.inventory.length)
{
this.inventory[j] = ItemStack.readFromTag(nbttagcompound);
}
} }
} }
public void writeTags(TagObject compound)
{
super.writeTags(compound);
List<TagObject> 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() public int getSizeInventory()
{ {
return this.inventory.length; return 1;
} }
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index) 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) 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]; ItemStack itemstack1 = this.inventory;
this.inventory[index] = null; this.inventory = null;
return itemstack1; return itemstack1;
} }
else 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; 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) public ItemStack removeStackFromSlot(int index)
{ {
if (this.inventory[index] != null) if (this.inventory != null)
{ {
ItemStack itemstack = this.inventory[index]; ItemStack itemstack = this.inventory;
this.inventory[index] = null; this.inventory = null;
return itemstack; return itemstack;
} }
else 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) 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) 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() public void update()
{ {
if (this.worldObj != null && !this.worldObj.client) if (this.world != null && !this.world.client)
{ {
--this.transferCooldown; --this.cooldown;
if (!this.isOnTransferCooldown()) if (!this.isOnTransferCooldown())
{ {
@ -167,12 +129,12 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
public boolean updatePipe() public boolean updatePipe()
{ {
if (this.worldObj != null && !this.worldObj.client) if (this.world != null && !this.world.client)
{ {
if (!this.isOnTransferCooldown()) if (!this.isOnTransferCooldown())
{ {
State state = this.getBlockState(); State state = this.getState();
if(!(state.getBlock() instanceof BlockPipe) || !this.decrPower()) if(!(state.getBlock() instanceof BlockPipe) /* || !this.decrPower() */) // TODO: power
return false; return false;
boolean flag = false; boolean flag = false;
@ -204,28 +166,12 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
private boolean isEmpty() private boolean isEmpty()
{ {
for (ItemStack itemstack : this.inventory) return this.inventory == null;
{
if (itemstack != null)
{
return false;
}
}
return true;
} }
private boolean isFull() private boolean isFull()
{ {
for (ItemStack itemstack : this.inventory) return this.inventory != null && this.inventory.isFull();
{
if (itemstack == null || !itemstack.isFull())
{
return false;
}
}
return true;
} }
private boolean transferItemsOut() private boolean transferItemsOut()
@ -238,7 +184,7 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
} }
else else
{ {
State state = this.getBlockState(); State state = this.getState();
Facing enumfacing = state.getBlock() instanceof BlockPipe ? state.getValue(BlockPipe.FACING).getOpposite() : Facing.DOWN; Facing enumfacing = state.getBlock() instanceof BlockPipe ? state.getValue(BlockPipe.FACING).getOpposite() : Facing.DOWN;
if (isInventoryFull(iinventory, enumfacing)) if (isInventoryFull(iinventory, enumfacing))
@ -376,7 +322,7 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
} }
else if(down) 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)) if (putDropInInventoryAllSlots(te, entityitem))
{ {
@ -522,7 +468,7 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
private IInventory getInventoryForTransfer() private IInventory getInventoryForTransfer()
{ {
State state = this.getBlockState(); State state = this.getState();
Facing enumfacing = state.getBlock() instanceof BlockPipe ? state.getValue(BlockPipe.FACING) : Facing.DOWN; 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())); 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()); return getInventoryAtPosition(pipe.getWorld(), pipe.getXPos(), pipe.getYPos() + (down ? -1.0 : 1.0), pipe.getZPos());
} }
public static List<EntityItem> func_181556_a(World p_181556_0_, double p_181556_1_, double p_181556_3_, double p_181556_5_) public static List<EntityItem> findDroppedItems(World world, double x, double y, double z)
{ {
return p_181556_0_.<EntityItem>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<EntityItem>() { return world.<EntityItem>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<EntityItem>() {
public boolean test(EntityItem entity) { public boolean test(EntityItem entity) {
return entity.isEntityAlive(); return entity.isEntityAlive();
} }
@ -589,25 +535,17 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
public void setTransferCooldown(int ticks) public void setTransferCooldown(int ticks)
{ {
this.transferCooldown = ticks; this.cooldown = ticks;
} }
public boolean isOnTransferCooldown() public boolean isOnTransferCooldown()
{ {
return this.transferCooldown > 0; return this.cooldown > 0;
} }
public boolean mayTransfer() public boolean mayTransfer()
{ {
return this.transferCooldown <= 1; return this.cooldown <= 1;
}
public void clear()
{
for (int i = 0; i < this.inventory.length; ++i)
{
this.inventory[i] = null;
}
} }
public int getColor() { public int getColor() {

View file

@ -376,10 +376,10 @@ public abstract class Chunk {
} }
if(oldb instanceof ITileEntityProvider) { if(oldb instanceof ITileEntityProvider) {
TileEntity tile = this.getTileEntity(pos, TileEntity.EnumCreateEntityType.CHECK); TileEntity tile = this.getTileEntity(pos, TileEntity.CreateMode.CHECK);
if(tile != null) { if(tile != null) {
tile.updateContainingBlockInfo(); tile.resetBlock();
} }
} }
@ -388,7 +388,7 @@ public abstract class Chunk {
} }
if(block instanceof ITileEntityProvider) { if(block instanceof ITileEntityProvider) {
TileEntity tile = this.getTileEntity(pos, TileEntity.EnumCreateEntityType.CHECK); TileEntity tile = this.getTileEntity(pos, TileEntity.CreateMode.CHECK);
if(tile == null) { if(tile == null) {
tile = ((ITileEntityProvider)block).createNewTileEntity(); tile = ((ITileEntityProvider)block).createNewTileEntity();
@ -396,7 +396,7 @@ public abstract class Chunk {
} }
if(tile != null) { if(tile != null) {
tile.updateContainingBlockInfo(); tile.resetBlock();
} }
} }
@ -519,15 +519,15 @@ public abstract class Chunk {
return !(block instanceof ITileEntityProvider provider) ? null : provider.createNewTileEntity(); 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); TileEntity tile = this.tiles.get(pos);
if(tile == null) { if(tile == null) {
if(type == TileEntity.EnumCreateEntityType.IMMEDIATE) { if(type == TileEntity.CreateMode.IMMEDIATE) {
tile = this.createNewTileEntity(pos); tile = this.createNewTileEntity(pos);
this.world.setTileEntity(pos, tile); this.world.setTileEntity(pos, tile);
} }
else if(type == TileEntity.EnumCreateEntityType.QUEUED) { else if(type == TileEntity.CreateMode.QUEUED) {
this.tileQueue.add(pos); this.tileQueue.add(pos);
} }
} }
@ -540,7 +540,7 @@ public abstract class Chunk {
} }
public void addTileEntity(BlockPos pos, TileEntity tile) { public void addTileEntity(BlockPos pos, TileEntity tile) {
tile.setWorldObj(this.world); tile.setWorld(this.world);
tile.setPos(pos); tile.setPos(pos);
if(this.getBlock(pos) instanceof ITileEntityProvider) { if(this.getBlock(pos) instanceof ITileEntityProvider) {
@ -655,7 +655,7 @@ public abstract class Chunk {
while(!this.tileQueue.isEmpty()) { while(!this.tileQueue.isEmpty()) {
BlockPos pos = (BlockPos)this.tileQueue.poll(); 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); TileEntity tile = this.createNewTileEntity(pos);
this.world.setTileEntity(pos, tile); this.world.setTileEntity(pos, tile);
this.world.markBlockRangeForRenderUpdate(pos, pos); this.world.markBlockRangeForRenderUpdate(pos, pos);

View file

@ -914,7 +914,7 @@ public abstract class World implements IWorldAccess {
while(iterator.hasNext()) { while(iterator.hasNext()) {
TileEntity tileentity = (TileEntity)iterator.next(); TileEntity tileentity = (TileEntity)iterator.next();
if(!tileentity.isInvalid() && tileentity.hasWorldObj()) { if(!tileentity.isInvalid() && tileentity.getWorld() != null) {
BlockPos blockpos = tileentity.getPos(); BlockPos blockpos = tileentity.getPos();
if(this.isBlockLoaded(blockpos)) { // && this.border.contains(blockpos)) { if(this.isBlockLoaded(blockpos)) { // && this.border.contains(blockpos)) {
@ -1329,7 +1329,7 @@ public abstract class World implements IWorldAccess {
} }
if(tileentity == null) { if(tileentity == null) {
tileentity = this.getChunk(pos).getTileEntity(pos, TileEntity.EnumCreateEntityType.IMMEDIATE); tileentity = this.getChunk(pos).getTileEntity(pos, TileEntity.CreateMode.IMMEDIATE);
} }
if(tileentity == null) { if(tileentity == null) {

View file

@ -50,7 +50,7 @@ public class CommandBlock extends Command {
TagObject te = new TagObject(); TagObject te = new TagObject();
tile.writeTags(te); tile.writeTags(te);
te.merge(tag); 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) { if(newTile != null) {
world.removeTileEntity(position); world.removeTileEntity(position);
world.setTileEntity(position, newTile); world.setTileEntity(position, newTile);

View file

@ -67,7 +67,7 @@ public class CommandSet extends Command {
TagObject te = new TagObject(); TagObject te = new TagObject();
tile.writeTags(te); tile.writeTags(te);
te.merge(tag); 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) { if(newTile != null) {
world.removeTileEntity(pos); world.removeTileEntity(pos);
world.setTileEntity(pos, newTile); world.setTileEntity(pos, newTile);

View file

@ -734,7 +734,7 @@ public class Player extends User implements Executor, IPlayer
} }
else if (object instanceof TileEntityChest chest) 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); this.entity.openContainer = new ContainerChest(this.entity, chest);
} }
else if (object instanceof InteractionObject obj) else if (object instanceof InteractionObject obj)

View file

@ -553,7 +553,7 @@ public class Region {
continue; continue;
} }
pos = new BlockPos(chunk.xPos << 4 | pos.getX(), pos.getY(), chunk.zPos << 4 | pos.getZ()); 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) { if(tileentity != null) {
chunk.addTileEntity(tileentity); chunk.addTileEntity(tileentity);

View file

@ -1900,7 +1900,7 @@ public final class WorldServer extends AWorldServer {
if(block.getData() != null) { if(block.getData() != null) {
this.removeTileEntity(pos); this.removeTileEntity(pos);
TagObject tag = block.getData(); TagObject tag = block.getData();
TileEntity tileEntity = TileEntity.createAndLoadEntity(this, chunk, pos, tag); TileEntity tileEntity = TileEntity.createTile(this, chunk, pos, tag);
if(tileEntity != null) { if(tileEntity != null) {
this.setTileEntity(pos, tileEntity); this.setTileEntity(pos, tileEntity);
} }