コード例 #1
0
  public void setAddress(int address) {
    if (this.worldObj != null && address != this.address) {
      ShortRangeTelepadHandler.removeShortRangeTeleporter(this);
    }

    this.address = address;

    if (this.address >= 0) {
      ShortRangeTelepadHandler.TelepadEntry entry =
          ShortRangeTelepadHandler.getLocationFromAddress(this.address);
      this.addressValid =
          entry == null
              || (this.worldObj != null
                  && (entry.dimensionID == this.worldObj.provider.getDimensionId()
                      && entry.position.x == this.getPos().getX()
                      && entry.position.y == this.getPos().getY()
                      && entry.position.z == this.getPos().getZ()));
    } else {
      this.addressValid = false;
    }

    if (worldObj != null && !worldObj.isRemote) {
      ShortRangeTelepadHandler.addShortRangeTelepad(this);
    }
  }
コード例 #2
0
  public boolean updateTarget() {
    if (this.targetAddress >= 0 && !this.worldObj.isRemote) {
      this.targetAddressResult = EnumTelepadSearchResult.NOT_FOUND;

      ShortRangeTelepadHandler.TelepadEntry addressResult =
          ShortRangeTelepadHandler.getLocationFromAddress(this.targetAddress);

      if (addressResult != null) {
        if (this.worldObj.provider.getDimensionId() == addressResult.dimensionID) {
          double distance =
              this.getDistanceSq(
                  addressResult.position.x + 0.5F,
                  addressResult.position.y + 0.5F,
                  addressResult.position.z + 0.5F);

          if (distance < Math.pow(TELEPORTER_RANGE * TELEPORTER_RANGE, 2)) {
            this.targetAddressResult = EnumTelepadSearchResult.VALID;
            return true;
          } else {
            this.targetAddressResult = EnumTelepadSearchResult.TOO_FAR;
            return false;
          }
        } else {
          this.targetAddressResult = EnumTelepadSearchResult.WRONG_DIM;
          return false;
        }
      } else {
        this.targetAddressResult = EnumTelepadSearchResult.NOT_FOUND;
        return false;
      }
    } else {
      this.targetAddressResult = EnumTelepadSearchResult.NOT_FOUND;
      return false;
    }
  }
コード例 #3
0
  @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);
  }
コード例 #4
0
  @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();
  }