protected boolean spawnMob(IBeeGenome genome, IBeeHousing housing) { boolean flag = false; World w = housing.getWorld(); int roll = 0; for (int i = 0; i < this.spawnChance.length && !flag; ++i) { roll = 100 - w.rand.nextInt(100) + 1; if (roll < this.spawnChance[i]) { flag = true; Entity mob = EntityList.createEntityByName(this.entityNames[i], w); // .createEntityByName method returns null when spawning a ghast in the overworld if (mob == null) return false; double[] coords = this.randomMobSpawnCoords(w, genome, housing); mob.setPositionAndRotation(coords[0], coords[1], coords[2], w.rand.nextFloat() * 360f, 0f); if (mob instanceof EntityLiving) { if (((EntityLiving) mob).getCanSpawnHere()) { w.spawnEntityInWorld(mob); } } else { w.spawnEntityInWorld(mob); } } } return flag; }
/** Process the contents of this packet */ public void handle(Entity entity) { double x = this.x / 32.0D; double y = this.y / 32.0D + 0.015625D; double z = this.z / 32.0D; float yaw = this.yaw * 360 / 256.0F; float pitch = this.pitch * 360 / 256.0F; if (Math.abs(entity.x - x) < 0.03125D && Math.abs(entity.y - y) < 0.015625D && Math.abs(entity.z - z) < 0.03125D) { entity.setPositionAndRotation(entity.x, entity.y, entity.z, yaw, pitch, 3, true); } else { entity.setPositionAndRotation(x, y, z, yaw, pitch, 3, true); } entity.onGround = this.onGround; }
public boolean teleport(Location location, TeleportCause cause) { if (entity.ridingEntity != null || entity.riddenByEntity != null || entity.isDead) { return false; } entity.worldObj = ((CraftWorld) location.getWorld()).getHandle(); entity.setPositionAndRotation( location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); // entity.setLocation() throws no event, and so cannot be cancelled return true; }
private void doTeleport(Entity entity) { deactivate(); AMVector3 newLocation = AMCore.instance.proxy.blocks.getNextKeystonePortalLocation( this.worldObj, xCoord, yCoord, zCoord, false, this.key); AMVector3 myLocation = new AMVector3(xCoord, yCoord, zCoord); double distance = myLocation.distanceTo(newLocation); float essenceCost = (float) (Math.pow(distance, 2) * 0.00175f); int meta = worldObj.getBlockMetadata((int) newLocation.x, (int) newLocation.y, (int) newLocation.z); if (AMCore.config.getHazardousGateways()) { // uh-oh! Not enough power! The teleporter will still send you though, but I wonder where... float charge = PowerNodeRegistry.For(this.worldObj).getHighestPower(this); if (charge < essenceCost) { essenceCost = charge; // get the distance that our charge *will* take us towards the next point double distanceWeCanGo = MathHelper.sqrt_double(charge / 0.00175); // get the angle between the 2 vectors double deltaZ = newLocation.z - myLocation.z; double deltaX = newLocation.x - myLocation.x; double angleH = Math.atan2(deltaZ, deltaX); // interpolate the distance at that angle - this is the new position double newX = myLocation.x + (Math.cos(angleH) * distanceWeCanGo); double newZ = myLocation.z + (Math.sin(angleH) * distanceWeCanGo); double newY = myLocation.y; while (worldObj.isAirBlock((int) newX, (int) newY, (int) newZ)) { newY++; } newLocation = new AMVector3(newX, newY, newZ); } } else { this.worldObj.playSoundEffect( newLocation.x, newLocation.y, newLocation.z, "mob.endermen.portal", 1.0F, 1.0F); return; } float newRotation = 0; switch (meta) { case 0: newRotation = 270; break; case 1: newRotation = 180; break; case 2: newRotation = 90; break; case 3: newRotation = 0; break; } entity.setPositionAndRotation( newLocation.x + 0.5, newLocation.y - entity.height, newLocation.z + 0.5, newRotation, entity.rotationPitch); PowerNodeRegistry.For(this.worldObj) .consumePower( this, PowerNodeRegistry.For(this.worldObj).getHighestPowerType(this), essenceCost); this.worldObj.playSoundEffect( myLocation.x, myLocation.y, myLocation.z, "mob.endermen.portal", 1.0F, 1.0F); this.worldObj.playSoundEffect( newLocation.x, newLocation.y, newLocation.z, "mob.endermen.portal", 1.0F, 1.0F); }