public static void checkForElevators(World world, ChunkPosition pos, int numSolid) { if (checkedBlocks.contains(pos)) { return; } checkedBlocks.add(pos); boolean isCeiling = false; if (world.getBlockId(pos.x, pos.y, pos.z) == DECore.Elevator.blockID) { if (!BlockElevator.isCeiling(world, pos)) { elvs.add(pos); return; } else { isCeiling = true; } } if (isCeiling || DECore.isBlockOpeningMaterial(world, pos)) { if (pos.y > 0 && !DECore.isBlockLedgeMaterial(world, pos.x, pos.y - 1, pos.z)) { checkForElevators(world, new ChunkPosition(pos.x, pos.y - 1, pos.z), numSolid); } if (pos.y < DECore.max_elevator_Y && !DECore.isBlockLedgeMaterial(world, pos.x, pos.y + 1, pos.z)) { checkForElevators(world, new ChunkPosition(pos.x, pos.y + 1, pos.z), numSolid); } } else { numSolid++; if (numSolid > 2) { return; } for (int iter = 0; iter < 4; iter++) { int tempX = pos.x; int tempZ = pos.z; if (iter == 0) { tempZ--; } else if (iter == 1) { tempZ++; } else if (iter == 2) { tempX--; } else if (iter == 3) { tempX++; } ChunkPosition curPos = new ChunkPosition(tempX, pos.y, tempZ); checkForElevators(world, curPos, numSolid); } } }
/** Called to update the entity's position/logic. */ public void onUpdate() { boolean var1 = true; int var2 = MathHelper.floor_double(this.posX); int var3 = MathHelper.floor_double(this.posY); int var4 = MathHelper.floor_double(this.posZ); ++this.ticksExisted; ++this.tickcount; if (this.tickcount > 45) { --this.startStops; if (this.startStops < 0) { this.startStops = 0; } this.tickcount = 0; } if (this.unUpdated) { if (this.worldObj.getBlockId(var2, var3, var4) == blockID) { if (!this.isCeiling()) { BlockElevator var5 = (BlockElevator) Block.blocksList[blockID]; TileEntityElevator var6 = BlockElevator.getTileEntity(this.worldObj, var2, var3, var4); if (var6 != null) { this.namedFloors = var6.convertFloorMapToArray(); this.properties = var6.convertBooleanPropertiesToArray(); } } if (!this.isCeiling() && this.properties != null && this.properties.length > 2 && this.properties[2]) { this.worldObj.setBlockWithNotify(var2, var3, var4, ElevatorsCore.Transient.blockID); } else { this.worldObj.setBlockWithNotify(var2, var3, var4, 0); } this.worldObj.notifyBlocksOfNeighborChange(var2 - 1, var3, var4, blockID); this.worldObj.notifyBlocksOfNeighborChange(var2 + 1, var3, var4, blockID); this.worldObj.notifyBlocksOfNeighborChange(var2, var3, var4 - 1, blockID); this.worldObj.notifyBlocksOfNeighborChange(var2, var3, var4 + 1, blockID); } this.conjoinAllNeighbors(); this.unUpdated = false; } if (!this.emerHalt) { if (!this.isDead && !this.isCeiling()) { this.refreshRiders(); if (this.properties != null && this.properties.length > 2 && this.properties[2]) { int var7; int var9; int var11; if (this.motionY > 0.0D) { var9 = (int) Math.ceil(this.posX - 0.5D); var11 = (int) Math.ceil(this.posY - 0.5D); var7 = (int) Math.ceil(this.posZ - 0.5D); } else { var9 = (int) Math.floor(this.posX - 0.5D); var11 = (int) Math.floor(this.posY - 0.5D); var7 = (int) Math.floor(this.posZ - 0.5D); } int var8 = this.worldObj.getBlockId(var9, var11, var7); if (var8 == 0) { this.worldObj.setBlockWithNotify(var9, var11, var7, ElevatorsCore.Transient.blockID); } } } if (this.worldObj.isRemote) { this.setPosition(this.posX, this.posY, this.posZ, true); this.say("Speed: " + this.motionY + ", posY: " + this.posY + ", destY: " + this.destY); this.say("End Entity Update - Control is remote"); } else if (!this.center) { if (this.centerElevator.isDead) { this.setDead(); } this.say("End Entity Update - Not Center"); } else { if (!this.conjoinedHasBeenSet) { this.conjoinAllNeighbors(); } if (this.waitToAccelerate < 15) { if (this.waitToAccelerate < 10) { this.elevatorSpeed = 0.0F; } else { this.elevatorSpeed = 0.016F; } ++this.waitToAccelerate; if (!this.conjoinedelevators.contains(this)) { this.conjoinedelevators.add(this); } this.say("Waiting to accelerate"); } else { float var10 = this.elevatorSpeed + 0.01F; if (var10 > 0.4F) { var10 = 0.4F; } float var12 = (var10 * var10 - 2.5600003E-4F) / 0.02F + 0.125F; this.say( "Speed: " + this.motionY + ", posY: " + this.posY + ", destY: " + this.destY + ", range: " + var12); if (!this.slowingDown && MathHelper.abs((float) (this.destY - this.posY)) >= var12) { this.elevatorSpeed = var10; } else { this.elevatorSpeed -= 0.01F; this.slowingDown = true; } if (this.elevatorSpeed > 0.4F) { this.elevatorSpeed = 0.4F; } if (this.elevatorSpeed < 0.016F) { this.elevatorSpeed = 0.016F; } } this.atDestination = this.onGround || MathHelper.abs((float) (this.destY - this.posY)) < this.elevatorSpeed; if (this.destY < 1.0F || this.destY > ElevatorsCore.max_elevator_Y) { this.atDestination = true; this.say("Requested destination is too high or too low!"); this.say("Requested: " + this.destY + ", max: " + ElevatorsCore.max_elevator_Y); } if (!this.atDestination) { this.motionY = this.destY > this.posY ? (double) this.elevatorSpeed : (double) (-this.elevatorSpeed); this.updateAllConjoined(); } else if (this.atDestination) { this.killAllConjoined(); return; } if (MathHelper.abs((float) this.motionY) < 0.016F && this.stillcount++ > 10) { this.killAllConjoined(); } else { this.stillcount = 0; } super.onUpdate(); this.say("End Entity Update"); } } }
public static boolean findAndActivateElevator(World world, int i, int j, int k, int depth) { if (depth > 32) { return false; } if (depth == 0) { checkedCallers.clear(); checkedBlocks.clear(); elvs.clear(); } checkedCallers.add(new ChunkPosition(i, j, k)); // Look for adjacent elevator caller blocks - if any are found, activate // them. // Also, if any are found, do not search at this location boolean foundOtherCallerBlock = false; for (int iter = 0; iter < 6; iter++) { int tempX = i; int tempY = j; int tempZ = k; if (iter == 0) { tempY--; } else if (iter == 1) { tempY++; } else if (iter == 2) { tempZ--; } else if (iter == 3) { tempZ++; } else if (iter == 4) { tempX--; } else if (iter == 5) { tempX++; } if (world.getBlockId(tempX, tempY, tempZ) == DECore.ElevatorCaller.blockID && !checkedCallers.contains(new ChunkPosition(tempX, tempY, tempZ))) { findAndActivateElevator(world, tempX, tempY, tempZ, depth + 1); foundOtherCallerBlock = true; } } clearSets(depth); if (foundOtherCallerBlock) { return true; } // No uncalled elevator callers were found, so search for elevators here checkForElevators(world, new ChunkPosition(i, j, k), 0); DECore.say("ElevatorCaller activated at: " + i + ", " + j + ", " + k); DECore.say( (new StringBuilder()) .append("Checked ") .append(checkedBlocks.size()) .append(" blocks") .toString()); DECore.say( (new StringBuilder()).append("Found ").append(elvs.size()).append(" elevators").toString()); int dist = 500; int destY = -1; ChunkPosition newPos = null; if (!elvs.isEmpty()) { Iterator<ChunkPosition> iter = elvs.iterator(); while (iter.hasNext()) { ChunkPosition curPos = iter.next(); BlockElevator.refreshAndCombineAllAdjacentElevators(world, curPos); TileEntityElevator curTile = BlockElevator.getTileEntity(world, curPos.x, curPos.y, curPos.z); if (curTile != null) { int suggestedY = curTile.getClosestYFromYCoor(j); if (MathHelper.abs(suggestedY - curPos.y) < dist) { dist = (int) MathHelper.abs(suggestedY - curPos.y); newPos = curPos; destY = suggestedY; } } } } if (newPos != null) { DECore.elevator_demandY(world, newPos, j); clearSets(depth); return true; } return false; }