Ejemplo n.º 1
0
  public boolean igniteWithResult() {
    if (this.setFrequency()) {
      super.ignite();
      return true;
    } else {
      if (this.isPlayerRocket()) {
        super.ignite();
        return true;
      }

      return false;
    }
  }
Ejemplo n.º 2
0
  @Override
  public void getNetworkedData(ArrayList<Object> list) {
    super.getNetworkedData(list);

    list.add(this.fuelTank.getFluidAmount());
    list.add(this.landing);
    list.add(this.destinationFrequency);
    list.add(this.targetVec != null);

    if (this.targetVec != null) {
      list.add(this.targetVec.getX());
      list.add(this.targetVec.getY());
      list.add(this.targetVec.getZ());
    }

    list.add(this.motionX * 8000.0D);
    list.add(this.motionY * 8000.0D);
    list.add(this.motionZ * 8000.0D);
    list.add(this.lastMotionY * 8000.0D);
    list.add(this.lastLastMotionY * 8000.0D);

    list.add(this.getWaitForPlayer());

    list.add(this.statusMessage != null ? this.statusMessage : "");
    list.add(this.statusMessageCooldown);
    list.add(this.lastStatusMessageCooldown);
    list.add(this.statusValid);

    if (!this.worldObj.isRemote) {
      list.add(this.riddenByEntity == null ? -1 : this.riddenByEntity.getEntityId());
    }
    list.add(this.statusColour != null ? this.statusColour : "");
  }
Ejemplo n.º 3
0
  @Override
  public void setDead() {
    super.setDead();

    if (this.rocketSoundUpdater != null) {
      this.rocketSoundUpdater.update();
    }
  }
Ejemplo n.º 4
0
  @Override
  protected void failRocket() {
    if (this.shouldCancelExplosion()) {
      for (int i = -3; i <= 3; i++) {
        BlockPos pos =
            new BlockPos(
                (int) Math.floor(this.posX),
                (int) Math.floor(this.posY + i),
                (int) Math.floor(this.posZ));
        if (this.landing
            && this.targetVec != null
            && this.worldObj.getTileEntity(pos) instanceof IFuelDock
            && this.posY - this.targetVec.getY() < 5) {
          for (int x = MathHelper.floor_double(this.posX) - 1;
              x <= MathHelper.floor_double(this.posX) + 1;
              x++) {
            for (int y = MathHelper.floor_double(this.posY - 3.0D);
                y <= MathHelper.floor_double(this.posY) + 1;
                y++) {
              for (int z = MathHelper.floor_double(this.posZ) - 1;
                  z <= MathHelper.floor_double(this.posZ) + 1;
                  z++) {
                BlockPos pos1 = new BlockPos(x, y, z);
                TileEntity tile = this.worldObj.getTileEntity(pos1);

                if (tile instanceof IFuelDock) {
                  this.landEntity(pos1);
                  return;
                }
              }
            }
          }
        }
      }
    }

    if (this.launchPhase == EnumLaunchPhase.LAUNCHED.ordinal()) {
      super.failRocket();
    }
  }
Ejemplo n.º 5
0
  @Override
  protected void writeEntityToNBT(NBTTagCompound nbt) {
    super.writeEntityToNBT(nbt);

    if (this.fuelTank.getFluid() != null) {
      nbt.setTag("fuelTank", this.fuelTank.writeToNBT(new NBTTagCompound()));
    }

    if (this.getSizeInventory() > 0) {
      final NBTTagList var2 = new NBTTagList();

      for (int var3 = 0; var3 < this.cargoItems.length; ++var3) {
        if (this.cargoItems[var3] != null) {
          final NBTTagCompound var4 = new NBTTagCompound();
          var4.setByte("Slot", (byte) var3);
          this.cargoItems[var3].writeToNBT(var4);
          var2.appendTag(var4);
        }
      }

      nbt.setTag("Items", var2);
    }

    nbt.setBoolean("TargetValid", this.targetVec != null);

    if (this.targetVec != null) {
      nbt.setDouble("targetTileX", this.targetVec.getX());
      nbt.setDouble("targetTileY", this.targetVec.getY());
      nbt.setDouble("targetTileZ", this.targetVec.getZ());
    }

    nbt.setBoolean("WaitingForPlayer", this.getWaitForPlayer());
    nbt.setBoolean("Landing", this.landing);
    nbt.setInteger(
        "AutoLaunchSetting",
        this.autoLaunchSetting != null ? this.autoLaunchSetting.getIndex() : -1);
    nbt.setInteger("TimeUntilAutoLaunch", this.autoLaunchCountdown);
    nbt.setInteger("DestinationFrequency", this.destinationFrequency);
  }
Ejemplo n.º 6
0
  @Override
  protected void readEntityFromNBT(NBTTagCompound nbt) {
    super.readEntityFromNBT(nbt);

    if (nbt.hasKey("fuelTank")) {
      this.fuelTank.readFromNBT(nbt.getCompoundTag("fuelTank"));
    }

    if (this.getSizeInventory() > 0) {
      final NBTTagList var2 = nbt.getTagList("Items", 10);
      this.cargoItems = new ItemStack[this.getSizeInventory()];

      for (int var3 = 0; var3 < var2.tagCount(); ++var3) {
        final NBTTagCompound var4 = var2.getCompoundTagAt(var3);
        final int var5 = var4.getByte("Slot") & 255;

        if (var5 < this.cargoItems.length) {
          this.cargoItems[var5] = ItemStack.loadItemStackFromNBT(var4);
        }
      }
    }

    if (nbt.getBoolean("TargetValid") && nbt.hasKey("targetTileX")) {
      this.targetVec =
          new BlockPos(
              MathHelper.floor_double(nbt.getDouble("targetTileX")),
              MathHelper.floor_double(nbt.getDouble("targetTileY")),
              MathHelper.floor_double(nbt.getDouble("targetTileZ")));
    }

    this.setWaitForPlayer(nbt.getBoolean("WaitingForPlayer"));
    this.landing = nbt.getBoolean("Landing");
    int autoLaunchValue = nbt.getInteger("AutoLaunchSetting");
    this.autoLaunchSetting =
        autoLaunchValue == -1 ? null : EnumAutoLaunch.values()[autoLaunchValue];
    this.autoLaunchCountdown = nbt.getInteger("TimeUntilAutoLaunch");
    this.destinationFrequency = nbt.getInteger("DestinationFrequency");
  }
Ejemplo n.º 7
0
  @Override
  public void onLaunch() {
    if (!(this.worldObj.provider.getDimensionId()
            == GalacticraftCore.planetOverworld.getDimensionID()
        || this.worldObj.provider instanceof IGalacticraftWorldProvider)) {
      if (ConfigManagerCore.disableRocketLaunchAllNonGC) {
        this.cancelLaunch();
        return;
      }

      // No rocket flight in the Nether, the End etc
      for (int i = ConfigManagerCore.disableRocketLaunchDimensions.length - 1; i >= 0; i--) {
        if (ConfigManagerCore.disableRocketLaunchDimensions[i]
            == this.worldObj.provider.getDimensionId()) {
          this.cancelLaunch();
          return;
        }
      }
    }

    super.onLaunch();

    if (!this.worldObj.isRemote) {
      GCPlayerStats stats = null;

      if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayerMP) {
        stats = GCPlayerStats.get((EntityPlayerMP) this.riddenByEntity);

        if (!(this.worldObj.provider instanceof IOrbitDimension)) {
          stats.coordsTeleportedFromX = this.riddenByEntity.posX;
          stats.coordsTeleportedFromZ = this.riddenByEntity.posZ;
        }
      }

      int amountRemoved = 0;

      PADSEARCH:
      for (int x = MathHelper.floor_double(this.posX) - 1;
          x <= MathHelper.floor_double(this.posX) + 1;
          x++) {
        for (int y = MathHelper.floor_double(this.posY) - 3;
            y <= MathHelper.floor_double(this.posY) + 1;
            y++) {
          for (int z = MathHelper.floor_double(this.posZ) - 1;
              z <= MathHelper.floor_double(this.posZ) + 1;
              z++) {
            BlockPos pos = new BlockPos(x, y, z);
            final Block block = this.worldObj.getBlockState(pos).getBlock();

            if (block != null && block instanceof BlockLandingPadFull) {
              if (amountRemoved < 9) {
                EventLandingPadRemoval event = new EventLandingPadRemoval(this.worldObj, pos);
                MinecraftForge.EVENT_BUS.post(event);

                if (event.allow) {
                  this.worldObj.setBlockToAir(pos);
                  amountRemoved = 9;
                }
                break PADSEARCH;
              }
            }
          }
        }
      }

      // Set the player's launchpad item for return on landing - or null if launchpads not removed
      if (stats != null) {
        stats.launchpadStack = amountRemoved == 9 ? new ItemStack(GCBlocks.landingPad, 9, 0) : null;
      }

      this.playSound(
          "random.pop",
          0.2F,
          ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    }
  }
Ejemplo n.º 8
0
  @Override
  public void decodePacketdata(ByteBuf buffer) {
    super.decodePacketdata(buffer);
    this.fuelTank.setFluid(new FluidStack(GCFluids.fluidFuel, buffer.readInt()));
    this.landing = buffer.readBoolean();
    this.destinationFrequency = buffer.readInt();

    if (buffer.readBoolean()) {
      this.targetVec = new BlockPos(buffer.readInt(), buffer.readInt(), buffer.readInt());
    }

    this.motionX = buffer.readDouble() / 8000.0D;
    this.motionY = buffer.readDouble() / 8000.0D;
    this.motionZ = buffer.readDouble() / 8000.0D;
    this.lastMotionY = buffer.readDouble() / 8000.0D;
    this.lastLastMotionY = buffer.readDouble() / 8000.0D;

    if (this.cargoItems == null) {
      this.cargoItems = new ItemStack[this.getSizeInventory()];
    }

    this.setWaitForPlayer(buffer.readBoolean());

    this.statusMessage = ByteBufUtils.readUTF8String(buffer);
    this.statusMessage = this.statusMessage.equals("") ? null : this.statusMessage;
    this.statusMessageCooldown = buffer.readInt();
    this.lastStatusMessageCooldown = buffer.readInt();
    this.statusValid = buffer.readBoolean();

    // Update client with correct rider if needed
    if (this.worldObj.isRemote) {
      int shouldBeMountedId = buffer.readInt();
      if (this.riddenByEntity == null) {
        if (shouldBeMountedId > -1) {
          Entity e = FMLClientHandler.instance().getWorldClient().getEntityByID(shouldBeMountedId);
          if (e != null) {
            if (e.dimension != this.dimension) {
              if (e instanceof EntityPlayer) {
                e =
                    WorldUtil.forceRespawnClient(
                        this.dimension,
                        e.worldObj.getDifficulty().getDifficultyId(),
                        e.worldObj.getWorldInfo().getTerrainType().getWorldTypeName(),
                        ((EntityPlayerMP) e).theItemInWorldManager.getGameType().getID());
                e.mountEntity(this);
              }
            } else e.mountEntity(this);
          }
        }
      } else if (this.riddenByEntity.getEntityId() != shouldBeMountedId) {
        if (shouldBeMountedId == -1) {
          this.riddenByEntity.mountEntity(null);
        } else {
          Entity e = FMLClientHandler.instance().getWorldClient().getEntityByID(shouldBeMountedId);
          if (e != null) {
            if (e.dimension != this.dimension) {
              if (e instanceof EntityPlayer) {
                e =
                    WorldUtil.forceRespawnClient(
                        this.dimension,
                        e.worldObj.getDifficulty().getDifficultyId(),
                        e.worldObj.getWorldInfo().getTerrainType().getWorldTypeName(),
                        ((EntityPlayerMP) e).theItemInWorldManager.getGameType().getID());
                e.mountEntity(this);
              }
            } else e.mountEntity(this);
          }
        }
      }
    }
    this.statusColour = ByteBufUtils.readUTF8String(buffer);
    if (this.statusColour.equals("")) this.statusColour = null;
  }
Ejemplo n.º 9
0
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (!this.worldObj.isRemote) {
      if (this.statusMessageCooldown > 0) {
        this.statusMessageCooldown--;
      }

      if (this.statusMessageCooldown == 0
          && this.lastStatusMessageCooldown > 0
          && this.statusValid) {
        this.autoLaunch();
      }

      if (this.autoLaunchCountdown > 0
          && (!(this instanceof EntityTieredRocket) || this.riddenByEntity != null)) {
        this.autoLaunchCountdown--;

        if (this.autoLaunchCountdown <= 0) {
          this.autoLaunch();
        }
      }

      if (this.autoLaunchSetting == EnumAutoLaunch.ROCKET_IS_FUELED
          && this.fuelTank.getFluidAmount() == this.fuelTank.getCapacity()
          && (!(this instanceof EntityTieredRocket) || this.riddenByEntity != null)) {
        this.autoLaunch();
      }

      if (this.autoLaunchSetting == EnumAutoLaunch.INSTANT) {
        if (this.autoLaunchCountdown == 0
            && (!(this instanceof EntityTieredRocket) || this.riddenByEntity != null)) {
          this.autoLaunch();
        }
      }

      if (this.autoLaunchSetting == EnumAutoLaunch.REDSTONE_SIGNAL) {
        if (this.ticks % 25 == 0) {
          if (this.getLandingPad() != null && this.getLandingPad().getConnectedTiles() != null) {
            for (ILandingPadAttachable tile : this.getLandingPad().getConnectedTiles()) {
              if (this.worldObj.getTileEntity(((TileEntity) tile).getPos()) != null) {
                try {
                  Class<?> controllerClass =
                      Class.forName(
                          "micdoodle8.mods.galacticraft.planets.mars.tile.TileEntityLaunchController");

                  try {
                    controllerClass.cast(this.worldObj.getTileEntity(((TileEntity) tile).getPos()));
                  } catch (ClassCastException e) {
                    continue;
                  }

                  if (this.worldObj.isBlockIndirectlyGettingPowered(((TileEntity) tile).getPos())
                      > 0) {
                    this.autoLaunch();
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            }
          }
        }
      }

      if (this.launchPhase == EnumLaunchPhase.LAUNCHED.ordinal() && this.hasValidFuel()) {
        if (this.landing
            && this.targetVec != null
            && this.worldObj.getTileEntity(this.targetVec) instanceof IFuelDock) {
          this.motionY =
              Math.max(
                  -2.0F,
                  (this.posY - this.getOnPadYOffset() - 0.4D - this.targetVec.getY()) / -70.0D);

          if (this.getEntityBoundingBox().minY - this.targetVec.getY() < 0.5F) {
            for (int x = MathHelper.floor_double(this.posX) - 1;
                x <= MathHelper.floor_double(this.posX) + 1;
                x++) {
              for (int y =
                      MathHelper.floor_double(
                              this.getEntityBoundingBox().minY - this.getOnPadYOffset() - 0.45D)
                          - 1;
                  y <= MathHelper.floor_double(this.getEntityBoundingBox().maxY) + 1;
                  y++) {
                for (int z = MathHelper.floor_double(this.posZ) - 1;
                    z <= MathHelper.floor_double(this.posZ) + 1;
                    z++) {
                  TileEntity tile = this.worldObj.getTileEntity(new BlockPos(x, y, z));

                  if (tile instanceof IFuelDock) {
                    this.failRocket();
                  }
                }
              }
            }
          }
        }
      }

      if (this.getLandingPad() != null && this.getLandingPad().getConnectedTiles() != null) {
        for (ILandingPadAttachable tile : this.getLandingPad().getConnectedTiles()) {
          if (this.worldObj.getTileEntity(((TileEntity) tile).getPos()) != null
              && this.worldObj.getTileEntity(((TileEntity) tile).getPos())
                  instanceof TileEntityFuelLoader) {
            if (tile instanceof TileEntityFuelLoader
                && ((TileEntityFuelLoader) tile).getEnergyStoredGC() > 0) {
              if (this.launchPhase == EnumLaunchPhase.LAUNCHED.ordinal()) {
                this.setPad(null);
              }
            }
          }
        }
      }

      this.lastStatusMessageCooldown = this.statusMessageCooldown;
    }

    if (this.launchPhase == EnumLaunchPhase.IGNITED.ordinal() || this.getLaunched()) {
      if (this.rocketSoundUpdater != null) {
        this.rocketSoundUpdater.update();
        this.rocketSoundToStop = true;
      }
    } else {
      // Not ignited - either because not yet launched, or because it has landed
      if (this.rocketSoundToStop) this.stopRocketSound();
    }
  }