// Simplified for speed by: // - assuming we won't use it to add a TileEntity to the same place repeatedly -> no iterating // over all TEs // - not checking World.field_147481_N (we know we're called from a TE's update()) public static void unsafeAddSpectre(World w, int x, int y, int z, TileEntity te) { w.addedTileEntityList.add(te); Chunk chunk = w.getChunkFromChunkCoords(x >> 4, z >> 4); if (chunk != null) { chunk.func_150812_a(x & 15, y, z & 15, te); } }
public void updateEntity() { // Check for ghost TEs if (dead) return; // Make sure the relays haven't been broken verifyRelay(); // Bounce if (linked && worldObj.getTotalWorldTime() % 100 == 0 && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) { // Target coordinates to check int targetX = xCoord + movementDirection.offsetX; int targetZ = zCoord + movementDirection.offsetZ; // Switch direction if at end of track if (worldObj.getBlock(targetX, yCoord, targetZ) != Block.getBlockFromName("air") || worldObj.getBlock(targetX, yCoord + 1, targetZ) != Block.getBlockFromName("air")) { movementDirection = movementDirection.getOpposite(); } } // Move if (linked && worldObj.getTotalWorldTime() % 100 == 1 && !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) { // Cache coordinated int targetX = xCoord + movementDirection.offsetX; int targetZ = zCoord + movementDirection.offsetZ; // Check for abandoned TEs if (worldObj.getBlock(xCoord, yCoord, zCoord) != ThaumicTinkerer.registry.getFirstBlockFromClass(BlockMobilizer.class)) { return; } // Check if the space the mobilizer will move into is empty if ((worldObj.isAirBlock(targetX, yCoord, targetZ) || worldObj.getBlock(targetX, yCoord, targetZ).isAir(worldObj, targetX, yCoord, targetZ) && (worldObj.isAirBlock(xCoord, yCoord + 1, zCoord) || worldObj.isAirBlock(targetX, yCoord + 1, targetZ) || worldObj .getBlock(targetX, yCoord + 1, targetZ) .isAir(worldObj, targetX, yCoord + 1, targetZ)))) { // Move Entities // List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class, // AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+3, zCoord+1)); // System.out.print(entities); // for(Entity e: entities){ // e.setPosition(e.posX+movementDirection.offsetX, e.posY, // e.posZ+movementDirection.offsetZ); // } // Move the block on top of the mobilizer if (!worldObj.isRemote) { TileEntity passenger = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord); IAppEngApi api = AEApi.instance(); // Prevent the passenger from popping off. Not sent to clients. worldObj.setBlock(targetX, yCoord, targetZ, Block.getBlockFromName("stone"), 0, 0); // Move non-TE blocks Block passengerId = worldObj.getBlock(xCoord, yCoord + 1, zCoord); if (worldObj.isAirBlock(xCoord, yCoord + 1, zCoord) || passengerId.canPlaceBlockAt(worldObj, targetX, yCoord + 1, targetZ)) { if (passenger == null) { if (passengerId != Block.getBlockFromName("bedrock") && passengerId != Block.getBlockFromName("")) { worldObj.setBlock( targetX, yCoord + 1, targetZ, passengerId, worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord), 3); if (passengerId != Block.getBlockFromName("air") && passengerId != Block.getBlockFromName("piston_head")) { worldObj.setBlock( xCoord, yCoord + 1, zCoord, Block.getBlockFromName("air"), 0, 2); } } // If AE is installed, use its handler } else if (api != null) { if (api.registries().moveable().askToMove(passenger)) { worldObj.setBlock( targetX, yCoord + 1, targetZ, worldObj.getBlock(xCoord, yCoord + 1, zCoord), worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord), 3); passenger.invalidate(); worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord); api.registries() .moveable() .getHandler(passenger) .moveTile(passenger, worldObj, targetX, yCoord + 1, targetZ); api.registries().moveable().doneMoving(passenger); passenger.validate(); } // Handler IMovableTiles and vanilla TEs without AE } else if (passenger instanceof IMovableTile || passenger.getClass().getName().startsWith("net.minecraft.tileentity")) { boolean imovable = passenger instanceof IMovableTile; if (imovable) ((IMovableTile) passenger).prepareToMove(); worldObj.setBlock( targetX, yCoord + 1, targetZ, worldObj.getBlock(xCoord, yCoord + 1, zCoord), worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord), 3); passenger.invalidate(); worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord); // IMovableHandler default code Chunk c = worldObj.getChunkFromBlockCoords(targetX, targetZ); c.func_150812_a(targetX & 0xF, yCoord + 1, targetZ & 0xF, passenger); if (c.isChunkLoaded) { worldObj.addTileEntity(passenger); worldObj.markBlockForUpdate(targetX, yCoord + 1, targetZ); } if (imovable) ((IMovableTile) passenger).doneMoving(); passenger.validate(); } } // Move self this.invalidate(); worldObj.removeTileEntity(xCoord, yCoord, zCoord); worldObj.setBlock(xCoord, yCoord, zCoord, Block.getBlockFromName("air"), 0, 2); worldObj.setBlock( targetX, yCoord, targetZ, ThaumicTinkerer.registry.getFirstBlockFromClass(BlockMobilizer.class)); int oldX = xCoord; int oldZ = zCoord; this.xCoord = targetX; this.zCoord = targetZ; this.validate(); worldObj.addTileEntity(this); worldObj.removeTileEntity(oldX, yCoord, oldZ); worldObj.notifyBlockChange(oldX, yCoord, oldZ, Block.getBlockFromName("air")); } } } }