@Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (!player.capabilities.isCreativeMode) { --stack.stackSize; } if (!world.isRemote) { EntityLivingBase entity = null; switch (stack.getItemDamage()) { case 0: entity = new EntityGrub(world); break; case 1: entity = new EntityLostMiner(world); break; case 2: entity = new EntityBoar(world); break; case 3: entity = new EntityGhostSpider(world); break; case 4: entity = new EntityGiantSpider(world); break; case 5: entity = new EntitySpiderQueen(world); break; case 6: entity = new EntityAbandonedGolem(world); break; case 7: entity = new EntityShroomSkeleton(world); break; case 8: entity = new EntityShroomZombie(world); break; case 9: entity = new EntityVampireBat(world); break; case 10: entity = new EntityWhale(world); break; default: entity = new EntitySheep(world); break; } entity.setPosition(player.posX, player.posY, player.posZ); world.spawnEntityInWorld(entity); } return stack; }
@Override public void update() { if (this.ticks % 40 == 0 && !worldObj.isRemote) { this.setAddress(this.address); this.setTargetAddress(this.targetAddress); } if (!this.worldObj.isRemote) { if (this.targetAddressResult == EnumTelepadSearchResult.VALID && (this.ticks % 5 == 0 || teleporting)) { List containedEntities = worldObj.getEntitiesWithinAABB( EntityLivingBase.class, AxisAlignedBB.fromBounds( this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getPos().getX() + 1, this.getPos().getY() + 2, this.getPos().getZ() + 1)); if (containedEntities.size() > 0 && this.getEnergyStoredGC() >= ENERGY_USE_ON_TELEPORT) { ShortRangeTelepadHandler.TelepadEntry entry = ShortRangeTelepadHandler.getLocationFromAddress(this.targetAddress); if (entry != null) { teleporting = true; } } else { teleporting = false; } } if (this.teleporting) { this.teleportTime++; if (teleportTime >= MAX_TELEPORT_TIME) { ShortRangeTelepadHandler.TelepadEntry entry = ShortRangeTelepadHandler.getLocationFromAddress(this.targetAddress); BlockVec3 finalPos = (entry == null) ? null : entry.position; if (finalPos != null) { TileEntity tileAt = finalPos.getTileEntity(this.worldObj); List<EntityLivingBase> containedEntities = worldObj.getEntitiesWithinAABB( EntityLivingBase.class, AxisAlignedBB.fromBounds( this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getPos().getX() + 1, this.getPos().getY() + 2, this.getPos().getZ() + 1)); if (tileAt != null && tileAt instanceof TileEntityShortRangeTelepad) { TileEntityShortRangeTelepad destTelepad = (TileEntityShortRangeTelepad) tileAt; int teleportResult = destTelepad.canTeleportHere(); if (teleportResult == 0) { for (EntityLivingBase e : containedEntities) { e.setPosition(finalPos.x + 0.5F, finalPos.y + 1.0F, finalPos.z + 0.5F); this.worldObj.updateEntityWithOptionalForce(e, true); if (e instanceof EntityPlayerMP) { ((EntityPlayerMP) e) .playerNetServerHandler.setPlayerLocation( finalPos.x, finalPos.y, finalPos.z, e.rotationYaw, e.rotationPitch); } GalacticraftCore.packetPipeline.sendToDimension( new PacketSimpleAsteroids( PacketSimpleAsteroids.EnumSimplePacketAsteroids.C_TELEPAD_SEND, this.worldObj.provider.getDimensionId(), new Object[] {finalPos, e.getEntityId()}), this.worldObj.provider.getDimensionId()); } if (containedEntities.size() > 0) { this.storage.setEnergyStored( this.storage.getEnergyStoredGC() - ENERGY_USE_ON_TELEPORT); destTelepad.storage.setEnergyStored( this.storage.getEnergyStoredGC() - ENERGY_USE_ON_TELEPORT); } } else { switch (teleportResult) { case -1: for (EntityLivingBase e : containedEntities) { if (e instanceof EntityPlayer) { ((EntityPlayer) e) .addChatComponentMessage( new ChatComponentText( "Cannot Send client-side")); // No need for translation, since // this should never happen } } break; case 1: for (EntityLivingBase e : containedEntities) { if (e instanceof EntityPlayer) { ((EntityPlayer) e) .addChatComponentMessage( new ChatComponentText( "Target address invalid")); // No need for translation, since // this should never happen } } break; case 2: for (EntityLivingBase e : containedEntities) { if (e instanceof EntityPlayer) { ((EntityPlayer) e) .addChatComponentMessage( new ChatComponentText( GCCoreUtil.translate("gui.message.target_no_energy.name"))); } } break; } } } } this.teleportTime = 0; this.teleporting = false; } } else { this.teleportTime = Math.max(--this.teleportTime, 0); } } super.update(); }
private boolean teleportTo(EntityLivingBase mob, double destX, double destY, double destZ) { double oldX = mob.posX; double oldY = mob.posY; double oldZ = mob.posZ; boolean success = false; mob.posX = destX; mob.posY = destY; mob.posZ = destZ; int x = MathHelper.floor_double(mob.posX); int y = MathHelper.floor_double(mob.posY); int z = MathHelper.floor_double(mob.posZ); Block blockID; if (mob.worldObj.blockExists(x, y, z)) { boolean hitGround = false; while (!hitGround && y < 96) { blockID = mob.worldObj.getBlock(x, y - 1, z); if (blockID.getMaterial().blocksMovement()) { hitGround = true; } else { --mob.posY; --y; } } if (hitGround) { mob.setPosition(mob.posX, mob.posY, mob.posZ); if (mob.worldObj.getCollidingBoundingBoxes(mob, mob.boundingBox).isEmpty() && !mob.worldObj.isAnyLiquid(mob.boundingBox)) { success = true; } } else { return false; } } if (!success) { mob.setPosition(oldX, oldY, oldZ); return false; } else { short range = 128; for (int i = 0; i < range; ++i) { double var19 = (double) i / ((double) range - 1.0D); float var21 = (mob.worldObj.rand.nextFloat() - 0.5F) * 0.2F; float var22 = (mob.worldObj.rand.nextFloat() - 0.5F) * 0.2F; float var23 = (mob.worldObj.rand.nextFloat() - 0.5F) * 0.2F; double var24 = oldX + (mob.posX - oldX) * var19 + (mob.worldObj.rand.nextDouble() - 0.5D) * (double) mob.width * 2.0D; double var26 = oldY + (mob.posY - oldY) * var19 + mob.worldObj.rand.nextDouble() * (double) mob.height; double var28 = oldZ + (mob.posZ - oldZ) * var19 + (mob.worldObj.rand.nextDouble() - 0.5D) * (double) mob.width * 2.0D; mob.worldObj.spawnParticle( "portal", var24, var26, var28, (double) var21, (double) var22, (double) var23); } mob.worldObj.playSoundEffect(oldX, oldY, oldZ, "mob.endermen.portal", 1.0F, 1.0F); mob.worldObj.playSoundAtEntity(mob, "mob.endermen.portal", 1.0F, 1.0F); } return true; }