@Override public void breakBlock(World world, int x0, int y0, int z0, Block var5, int var6) { final TileEntity tileAt = world.getTileEntity(x0, y0, z0); int fakeBlockCount = 0; for (int x = -1; x <= 1; x++) { for (int y = 0; y < 3; y += 2) { for (int z = -1; z <= 1; z++) { if (!(x == 0 && y == 0 && z == 0)) { if (world.getBlock(x0 + x, y0 + y, z0 + z) == AsteroidBlocks.fakeTelepad) { fakeBlockCount++; } } } } } if (fakeBlockCount > 0 && tileAt instanceof TileEntityShortRangeTelepad) { ((TileEntityShortRangeTelepad) tileAt).onDestroy(tileAt); ShortRangeTelepadHandler.removeShortRangeTeleporter((TileEntityShortRangeTelepad) tileAt); } super.breakBlock(world, x0, y0, z0, var5, var6); }
@Override public void onBlockPlacedBy( World world, int x0, int y0, int z0, EntityLivingBase entityLiving, ItemStack itemStack) { super.onBlockPlacedBy(world, x0, y0, z0, entityLiving, itemStack); TileEntity tile = world.getTileEntity(x0, y0, z0); boolean validSpot = true; for (int x = -1; x <= 1; x++) { for (int y = 0; y < 3; y += 2) { for (int z = -1; z <= 1; z++) { if (!(x == 0 && y == 0 && z == 0)) { Block blockAt = world.getBlock(x0 + x, y0 + y, z0 + z); if (!blockAt.getMaterial().isReplaceable()) { validSpot = false; } } } } } if (!validSpot) { world.setBlockToAir(x0, y0, z0); if (entityLiving instanceof EntityPlayer) { if (!world.isRemote) { ((EntityPlayer) entityLiving) .addChatMessage( new ChatComponentText( EnumColor.RED + GCCoreUtil.translate("gui.warning.noroom"))); } ((EntityPlayer) entityLiving) .inventory.addItemStackToInventory(new ItemStack(Item.getItemFromBlock(this), 1, 0)); } return; } if (tile instanceof TileEntityShortRangeTelepad) { ((TileEntityShortRangeTelepad) tile).onCreate(new BlockVec3(x0, y0, z0)); ((TileEntityShortRangeTelepad) tile) .setOwner(((EntityPlayer) entityLiving).getGameProfile().getName()); } }
@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(); }