@Override
 protected void actionPerformed(GuiButton par1GuiButton) {
   if (par1GuiButton.enabled) {
     switch (par1GuiButton.id) {
       case 0:
         PacketDispatcher.sendPacketToServer(
             PacketUtil.createPacket(
                 GalacticraftCore.CHANNEL,
                 EnumPacketServer.UPDATE_DISABLEABLE_BUTTON,
                 new Object[] {
                   this.terraformer.xCoord, this.terraformer.yCoord, this.terraformer.zCoord, 0
                 }));
         break;
       case 1:
         PacketDispatcher.sendPacketToServer(
             PacketUtil.createPacket(
                 GalacticraftCore.CHANNEL,
                 EnumPacketServer.UPDATE_DISABLEABLE_BUTTON,
                 new Object[] {
                   this.terraformer.xCoord, this.terraformer.yCoord, this.terraformer.zCoord, 1
                 }));
         break;
     }
   }
 }
  @Override
  public void onTeleport(EntityPlayerMP player) {
    final GCCorePlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayer(player);

    player.playerNetServerHandler.sendPacketToPlayer(
        PacketUtil.createPacket(GalacticraftCore.CHANNEL, 22, new Object[] {0}));

    if (playerBase != null) {
      if (this.cargoItems == null || this.cargoItems.length == 0) {
        playerBase.setRocketStacks(new ItemStack[9]);
      } else {
        playerBase.setRocketStacks(this.cargoItems);
      }

      playerBase.setRocketType(this.rocketType.getIndex());
      int liquid =
          (int)
              Math.floor(
                  (this.spaceshipFuelTank.getFluid() == null
                          ? 0
                          : this.spaceshipFuelTank.getFluid().amount)
                      / 2.0D);
      playerBase.setFuelDamage(
          Math.max(
              Math.min(
                  GCCoreItems.fuelCanister.getMaxDamage() - liquid,
                  GCCoreItems.fuelCanister.getMaxDamage()),
              1));
    }
  }
  @Override
  public void tickStart(EnumSet<TickType> type, Object... tickData) {
    final Minecraft minecraft = FMLClientHandler.instance().getClient();

    final WorldClient world = minecraft.theWorld;

    final EntityClientPlayerMP player = minecraft.thePlayer;

    if (type.equals(EnumSet.of(TickType.CLIENT))) {
      if (GCCoreTickHandlerClient.tickCount >= Long.MAX_VALUE) {
        GCCoreTickHandlerClient.tickCount = 0;
      }

      GCCoreTickHandlerClient.tickCount++;

      if (GCCoreTickHandlerClient.tickCount % 20 == 0) {
        if (player != null
            && player.inventory.armorItemInSlot(3) != null
            && player.inventory.armorItemInSlot(3).getItem() instanceof GCCoreItemSensorGlasses) {
          ClientProxyCore.valueableBlocks.clear();

          for (int i = -4; i < 5; i++) {
            for (int j = -4; j < 5; j++) {
              for (int k = -4; k < 5; k++) {
                int x = MathHelper.floor_double(player.posX + i);
                int y = MathHelper.floor_double(player.posY + j);
                int z = MathHelper.floor_double(player.posZ + k);

                final int id = player.worldObj.getBlockId(x, y, z);

                if (id != 0) {
                  final Block block = Block.blocksList[id];
                  int metadata = world.getBlockMetadata(x, y, z);
                  boolean isDetectable = false;

                  for (BlockMetaList blockMetaList : ClientProxyCore.detectableBlocks) {
                    if (blockMetaList.getBlockID() == id
                        && blockMetaList.getMetaList().contains(metadata)) {
                      isDetectable = true;
                      break;
                    }
                  }

                  if (isDetectable) {
                    if (!this.alreadyContainsBlock(x, y, z)) {
                      ClientProxyCore.valueableBlocks.add(new Vector3(x, y, z));
                    }
                  } else if (block instanceof IDetectableResource
                      && ((IDetectableResource) block).isValueable(metadata)) {
                    if (!this.alreadyContainsBlock(x, y, z)) {
                      ClientProxyCore.valueableBlocks.add(new Vector3(x, y, z));
                    }

                    List<Integer> metaList = Lists.newArrayList();
                    metaList.add(metadata);

                    for (BlockMetaList blockMetaList : ClientProxyCore.detectableBlocks) {
                      if (blockMetaList.getBlockID() == id) {
                        metaList.addAll(blockMetaList.getMetaList());
                        break;
                      }
                    }

                    ClientProxyCore.detectableBlocks.add(new BlockMetaList(id, metaList));
                  }
                }
              }
            }
          }
        }
      }

      if (GCCoreTickHandlerClient.addTabsNextTick) {
        if (minecraft.currentScreen.getClass().equals(GuiInventory.class)) {
          GCCoreTickHandlerClient.addTabsToInventory((GuiContainer) minecraft.currentScreen);
        }

        GCCoreTickHandlerClient.addTabsNextTick = false;
      }

      if (minecraft.currentScreen != null && minecraft.currentScreen instanceof GuiMainMenu) {
        GalacticraftCore.playersServer.clear();
        GalacticraftCore.playersClient.clear();
        ClientProxyCore.playerItemData.clear();

        if (GCCoreTickHandlerClient.missingRequirementThread == null) {
          GCCoreTickHandlerClient.missingRequirementThread =
              new GCCoreThreadRequirementMissing(FMLCommonHandler.instance().getEffectiveSide());
          GCCoreTickHandlerClient.missingRequirementThread.start();
        }
      }

      if (world != null && GCCoreTickHandlerClient.checkedVersion) {
        GCCoreUtil.checkVersion(Side.CLIENT);
        GCCoreTickHandlerClient.checkedVersion = false;
      }

      if (player != null
          && player.ridingEntity != null
          && player.ridingEntity instanceof EntitySpaceshipBase) {
        final Object[] toSend = {player.ridingEntity.rotationPitch};
        PacketDispatcher.sendPacketToServer(
            PacketUtil.createPacket(
                GalacticraftCore.CHANNEL, EnumPacketServer.UPDATE_SHIP_PITCH, toSend));
        final Object[] toSend2 = {player.ridingEntity.rotationYaw};
        PacketDispatcher.sendPacketToServer(
            PacketUtil.createPacket(
                GalacticraftCore.CHANNEL, EnumPacketServer.UPDATE_SHIP_YAW, toSend2));
      }

      if (world != null && world.provider instanceof WorldProviderSurface) {
        if (world.provider.getSkyRenderer() == null
            && player.ridingEntity != null
            && player.ridingEntity.posY >= 200) {
          world.provider.setSkyRenderer(new GCCoreSkyProviderOverworld());
        } else if (world.provider.getSkyRenderer() != null
            && world.provider.getSkyRenderer() instanceof GCCoreSkyProviderOverworld
            && (player.ridingEntity == null || player.ridingEntity.posY < 200)) {
          world.provider.setSkyRenderer(null);
        }
      }

      if (world != null && world.provider instanceof GCCoreWorldProviderSpaceStation) {
        if (world.provider.getSkyRenderer() == null) {
          world.provider.setSkyRenderer(
              new GCCoreSkyProviderOrbit(
                  new ResourceLocation(
                      GalacticraftCore.ASSET_DOMAIN, "textures/gui/planets/overworld.png"),
                  true,
                  true));
        }

        if (world.provider.getCloudRenderer() == null) {
          world.provider.setCloudRenderer(new GCCoreCloudRenderer());
        }
      }

      if (player != null
          && player.ridingEntity != null
          && player.ridingEntity instanceof EntitySpaceshipBase) {
        final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.ridingEntity;

        if (minecraft.gameSettings.keyBindLeft.pressed) {
          ship.turnYaw(-1.0F);
          final Object[] toSend = {ship.rotationYaw};
          PacketDispatcher.sendPacketToServer(
              PacketUtil.createPacket(
                  GalacticraftCore.CHANNEL, EnumPacketServer.UPDATE_SHIP_YAW, toSend));
        }

        if (minecraft.gameSettings.keyBindRight.pressed) {
          ship.turnYaw(1.0F);
          final Object[] toSend = {ship.rotationYaw};
          PacketDispatcher.sendPacketToServer(
              PacketUtil.createPacket(
                  GalacticraftCore.CHANNEL, EnumPacketServer.UPDATE_SHIP_YAW, toSend));
        }

        if (minecraft.gameSettings.keyBindForward.pressed) {
          if (ship.getLaunched()) {
            ship.turnPitch(-0.7F);
            final Object[] toSend = {ship.rotationPitch};
            PacketDispatcher.sendPacketToServer(
                PacketUtil.createPacket(
                    GalacticraftCore.CHANNEL, EnumPacketServer.UPDATE_SHIP_PITCH, toSend));
          }
        }

        if (minecraft.gameSettings.keyBindBack.pressed) {
          if (ship.getLaunched()) {
            ship.turnPitch(0.7F);
            final Object[] toSend = {ship.rotationPitch};
            PacketDispatcher.sendPacketToServer(
                PacketUtil.createPacket(
                    GalacticraftCore.CHANNEL, EnumPacketServer.UPDATE_SHIP_PITCH, toSend));
          }
        }
      }

      if (world != null) {
        for (int i = 0; i < world.loadedEntityList.size(); i++) {
          final Entity e = (Entity) world.loadedEntityList.get(i);

          if (e != null) {
            if (e instanceof GCCoreEntityRocketT1) {
              final GCCoreEntityRocketT1 eship = (GCCoreEntityRocketT1) e;

              if (eship.rocketSoundUpdater == null) {
                eship.rocketSoundUpdater =
                    new GCCoreSoundUpdaterSpaceship(
                        FMLClientHandler.instance().getClient().sndManager,
                        eship,
                        FMLClientHandler.instance().getClient().thePlayer);
              }
            }
          }
        }
      }

      if (FMLClientHandler.instance().getClient().currentScreen instanceof GCCoreGuiChoosePlanet) {
        player.motionY = 0;
      }

      if (world != null && world.provider instanceof IGalacticraftWorldProvider) {
        world.setRainStrength(0.0F);
      }

      if (!minecraft.gameSettings.keyBindJump.pressed) {
        ClientProxyCore.lastSpacebarDown = false;
      }

      if (player != null
          && player.ridingEntity != null
          && minecraft.gameSettings.keyBindJump.pressed
          && !ClientProxyCore.lastSpacebarDown) {
        final Object[] toSend = {0};
        PacketDispatcher.sendPacketToServer(
            PacketUtil.createPacket(
                GalacticraftCore.CHANNEL, EnumPacketServer.IGNITE_ROCKET, toSend));
        ClientProxyCore.lastSpacebarDown = true;
      }
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  protected void onDeathUpdate() {
    ++this.deathTicks;

    this.headsRemaining = 0;

    if (this.deathTicks >= 180 && this.deathTicks <= 200) {
      final float f = (this.rand.nextFloat() - 0.5F) * 1.5F;
      final float f1 = (this.rand.nextFloat() - 0.5F) * 2.0F;
      final float f2 = (this.rand.nextFloat() - 0.5F) * 1.5F;
      this.worldObj.spawnParticle(
          "hugeexplosion", this.posX + f, this.posY + 2.0D + f1, this.posZ + f2, 0.0D, 0.0D, 0.0D);
    }

    int i;
    int j;

    if (!this.worldObj.isRemote) {
      if (this.deathTicks >= 180 && this.deathTicks % 5 == 0) {
        PacketDispatcher.sendPacketToAllAround(
            this.posX,
            this.posY,
            this.posZ,
            40.0,
            this.worldObj.provider.dimensionId,
            PacketUtil.createPacket(
                GalacticraftCore.CHANNEL, EnumPacketClient.PLAY_SOUND_EXPLODE, new Object[] {0}));
      }

      if (this.deathTicks > 150 && this.deathTicks % 5 == 0) {
        i = 30;

        while (i > 0) {
          j = EntityXPOrb.getXPSplit(i);
          i -= j;
          this.worldObj.spawnEntityInWorld(
              new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
        }
      }

      if (this.deathTicks == 1) {
        PacketDispatcher.sendPacketToAllAround(
            this.posX,
            this.posY,
            this.posZ,
            40.0,
            this.worldObj.provider.dimensionId,
            PacketUtil.createPacket(
                GalacticraftCore.CHANNEL,
                EnumPacketClient.PLAY_SOUND_BOSS_DEATH,
                new Object[] {0}));
      }
    }

    this.moveEntity(0.0D, 0.10000000149011612D, 0.0D);
    this.renderYawOffset = this.rotationYaw += 20.0F;

    if (this.deathTicks == 200 && !this.worldObj.isRemote) {
      i = 20;

      while (i > 0) {
        j = EntityXPOrb.getXPSplit(i);
        i -= j;
        this.worldObj.spawnEntityInWorld(
            new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
      }

      for (final TileEntity tile : (List<TileEntity>) this.worldObj.loadedTileEntityList) {
        if (tile instanceof GCCoreTileEntityTreasureChest) {
          final double d3 = tile.xCoord + 0.5D - this.posX;
          final double d4 = tile.yCoord + 0.5D - this.posY;
          final double d5 = tile.zCoord + 0.5D - this.posZ;
          final double dSq = d3 * d3 + d4 * d4 + d5 * d5;

          if (dSq < Math.pow(100.0D, 2)) {
            if (!((GCCoreTileEntityTreasureChest) tile).locked) {
              ((GCCoreTileEntityTreasureChest) tile).locked = true;
            }

            for (int k = 0; k < ((GCCoreTileEntityTreasureChest) tile).getSizeInventory(); k++) {
              ((GCCoreTileEntityTreasureChest) tile).setInventorySlotContents(k, null);
            }

            ChestGenHooks info = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);

            // Generate twice, since it's an extra special chest
            WeightedRandomChestContent.generateChestContents(
                this.rand,
                info.getItems(this.rand),
                (GCCoreTileEntityTreasureChest) tile,
                info.getCount(this.rand));
            WeightedRandomChestContent.generateChestContents(
                this.rand,
                info.getItems(this.rand),
                (GCCoreTileEntityTreasureChest) tile,
                info.getCount(this.rand));

            ((GCCoreTileEntityTreasureChest) tile)
                .setInventorySlotContents(
                    this.rand.nextInt(((GCCoreTileEntityTreasureChest) tile).getSizeInventory()),
                    this.getGuaranteedLoot(this.rand));

            break;
          }
        }
      }

      this.entityDropItem(new ItemStack(GCMarsItems.key.itemID, 1, 0), 0.5F);

      super.setDead();

      if (this.spawner != null) {
        this.spawner.isBossDefeated = true;
        this.spawner.boss = null;
        this.spawner.spawned = false;
      }
    }
  }