@Override
  public void processCommand(ICommandSender icommandsender, String[] astring) {
    GCEntityPlayerMP playerBase = null;

    if (astring.length < 2) {
      try {
        if (astring.length == 1) {
          playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(astring[0], true);
        } else {
          playerBase =
              PlayerUtil.getPlayerBaseServerFromPlayerUsername(
                  icommandsender.getCommandSenderName(), true);
        }

        if (playerBase != null) {
          playerBase.getPlayerStats().rocketStacks = new ItemStack[2];
          playerBase.getPlayerStats().rocketType = IRocketType.EnumRocketType.DEFAULT.ordinal();
          playerBase.getPlayerStats().rocketItem = GCItems.rocketTier1;
          playerBase.getPlayerStats().fuelLevel = 1000;

          HashMap<String, Integer> map =
              WorldUtil.getArrayOfPossibleDimensions(
                  WorldUtil.getPossibleDimensionsForSpaceshipTier(Integer.MAX_VALUE), playerBase);

          String temp = "";
          int count = 0;

          for (Entry<String, Integer> entry : map.entrySet()) {
            temp = temp.concat(entry.getKey() + (count < map.entrySet().size() - 1 ? "?" : ""));
            count++;
          }

          GalacticraftCore.packetPipeline.sendTo(
              new PacketSimple(
                  EnumSimplePacket.C_UPDATE_DIMENSION_LIST,
                  new Object[] {playerBase.getGameProfile().getName(), temp}),
              playerBase);
          playerBase.getPlayerStats().spaceshipTier = Integer.MAX_VALUE;
          playerBase.getPlayerStats().usingPlanetSelectionGui = true;
          playerBase.mountEntity(null);

          VersionUtil.notifyAdmins(
              icommandsender,
              this,
              "commands.dimensionteleport",
              new Object[] {
                String.valueOf(EnumColor.GREY + "[" + playerBase.getCommandSenderName()), "]"
              });
        } else {
          throw new Exception("Could not find player with name: " + astring[0]);
        }
      } catch (final Exception var6) {
        throw new CommandException(var6.getMessage(), new Object[0]);
      }
    } else {
      throw new WrongUsageException(
          "Not enough command arguments! Usage: " + this.getCommandUsage(icommandsender),
          new Object[0]);
    }
  }
Пример #2
0
  @Override
  protected void jump() {
    this.motionY = 0.52D / WorldUtil.getGravityFactor(this);
    if (this.motionY < 0.26D) this.motionY = 0.26D;

    if (this.isPotionActive(Potion.jump)) {
      this.motionY += (this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F;
    }

    if (this.isSprinting()) {
      float f = this.rotationYaw * 0.017453292F;
      this.motionX -= MathHelper.sin(f) * 0.2F;
      this.motionZ += MathHelper.cos(f) * 0.2F;
    }

    this.isAirBorne = true;
    ForgeHooks.onLivingJump(this);
  }
Пример #3
0
  @Override
  public void handleServerSide(EntityPlayer player) {
    GCEntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayer(player, false);
    if (playerBase == null) {
      return;
    }

    switch (this.type) {
      case S_RESPAWN_PLAYER:
        playerBase.playerNetServerHandler.sendPacket(
            new S07PacketRespawn(
                player.dimension,
                player.worldObj.difficultySetting,
                player.worldObj.getWorldInfo().getTerrainType(),
                playerBase.theItemInWorldManager.getGameType()));
        break;
      case S_TELEPORT_ENTITY:
        try {
          final WorldProvider provider = WorldUtil.getProviderForName((String) this.data.get(0));
          final Integer dim = provider.dimensionId;
          GCLog.info(
              "Found matching world ("
                  + dim.toString()
                  + ") for name: "
                  + (String) this.data.get(0));

          if (playerBase.worldObj instanceof WorldServer) {
            final WorldServer world = (WorldServer) playerBase.worldObj;

            if (provider instanceof IOrbitDimension) {
              WorldUtil.transferEntityToDimension(playerBase, dim, world);
            } else {
              WorldUtil.transferEntityToDimension(playerBase, dim, world);
            }
          }

          playerBase.getPlayerStats().teleportCooldown = 300;
          GalacticraftCore.packetPipeline.sendTo(
              new PacketSimple(EnumSimplePacket.C_CLOSE_GUI, new Object[] {}), playerBase);
        } catch (final Exception e) {
          GCLog.severe(
              "Error occurred when attempting to transfer entity to dimension: "
                  + (String) this.data.get(0));
          e.printStackTrace();
        }
        break;
      case S_IGNITE_ROCKET:
        if (!player.worldObj.isRemote
            && !player.isDead
            && player.ridingEntity != null
            && !player.ridingEntity.isDead
            && player.ridingEntity instanceof EntityTieredRocket) {
          final EntityTieredRocket ship = (EntityTieredRocket) player.ridingEntity;

          if (!ship.landing) {
            if (ship.hasValidFuel()) {
              ItemStack stack2 = playerBase.getPlayerStats().extendedInventory.getStackInSlot(4);

              if (stack2 != null && stack2.getItem() instanceof ItemParaChute
                  || playerBase.getPlayerStats().launchAttempts > 0) {
                ship.igniteCheckingCooldown();
                playerBase.getPlayerStats().launchAttempts = 0;
              } else if (playerBase.getPlayerStats().chatCooldown == 0
                  && playerBase.getPlayerStats().launchAttempts == 0) {
                player.addChatMessage(
                    new ChatComponentText(GCCoreUtil.translate("gui.rocket.warning.noparachute")));
                playerBase.getPlayerStats().chatCooldown = 250;
                playerBase.getPlayerStats().launchAttempts = 1;
              }
            } else if (playerBase.getPlayerStats().chatCooldown == 0) {
              player.addChatMessage(
                  new ChatComponentText(GCCoreUtil.translate("gui.rocket.warning.nofuel")));
              playerBase.getPlayerStats().chatCooldown = 250;
            }
          }
        }
        break;
      case S_OPEN_SCHEMATIC_PAGE:
        if (player != null) {
          final ISchematicPage page =
              SchematicRegistry.getMatchingRecipeForID((Integer) this.data.get(0));

          player.openGui(
              GalacticraftCore.instance,
              page.getGuiID(),
              player.worldObj,
              (int) player.posX,
              (int) player.posY,
              (int) player.posZ);
        }
        break;
      case S_OPEN_FUEL_GUI:
        if (player.ridingEntity instanceof EntityBuggy) {
          GCCoreUtil.openBuggyInv(
              playerBase,
              (EntityBuggy) player.ridingEntity,
              ((EntityBuggy) player.ridingEntity).getType());
        } else if (player.ridingEntity instanceof EntitySpaceshipBase) {
          player.openGui(
              GalacticraftCore.instance,
              GuiIdsCore.ROCKET_INVENTORY,
              player.worldObj,
              (int) player.posX,
              (int) player.posY,
              (int) player.posZ);
        }
        break;
      case S_UPDATE_SHIP_YAW:
        if (player.ridingEntity instanceof EntitySpaceshipBase) {
          final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.ridingEntity;

          if (ship != null) {
            ship.rotationYaw = (Float) this.data.get(0);
          }
        }
        break;
      case S_UPDATE_SHIP_PITCH:
        if (player.ridingEntity instanceof EntitySpaceshipBase) {
          final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.ridingEntity;

          if (ship != null) {
            ship.rotationPitch = (Float) this.data.get(0);
          }
        }
        break;
      case S_SET_ENTITY_FIRE:
        Entity entity = player.worldObj.getEntityByID((Integer) this.data.get(0));

        if (entity instanceof EntityLiving) {
          ((EntityLiving) entity).setFire(3);
        }
        break;
      case S_OPEN_REFINERY_GUI:
        player.openGui(
            GalacticraftCore.instance,
            -1,
            player.worldObj,
            (Integer) this.data.get(0),
            (Integer) this.data.get(1),
            (Integer) this.data.get(2));
        break;
      case S_BIND_SPACE_STATION_ID:
        if ((playerBase.getPlayerStats().spaceStationDimensionID == -1
                || playerBase.getPlayerStats().spaceStationDimensionID == 0)
            && !ConfigManagerCore.disableSpaceStationCreation) {
          WorldUtil.bindSpaceStationToNewDimension(playerBase.worldObj, playerBase);

          WorldUtil.getSpaceStationRecipe((Integer) this.data.get(0)).matches(playerBase, true);
        }
        break;
      case S_UNLOCK_NEW_SCHEMATIC:
        final Container container = player.openContainer;

        if (container instanceof ContainerSchematic) {
          final ContainerSchematic schematicContainer = (ContainerSchematic) container;

          ItemStack stack = schematicContainer.craftMatrix.getStackInSlot(0);

          if (stack != null) {
            final ISchematicPage page = SchematicRegistry.getMatchingRecipeForItemStack(stack);

            if (page != null) {
              SchematicRegistry.unlockNewPage(playerBase, stack);

              if (--stack.stackSize <= 0) {
                stack = null;
              }

              schematicContainer.craftMatrix.setInventorySlotContents(0, stack);
              schematicContainer.craftMatrix.markDirty();

              GalacticraftCore.packetPipeline.sendTo(
                  new PacketSimple(
                      EnumSimplePacket.C_ADD_NEW_SCHEMATIC, new Object[] {page.getPageID()}),
                  playerBase);
            }
          }
        }
        break;
      case S_UPDATE_DISABLEABLE_BUTTON:
        final TileEntity tileAt =
            player.worldObj.getTileEntity(
                (Integer) this.data.get(0), (Integer) this.data.get(1), (Integer) this.data.get(2));

        if (tileAt instanceof IDisableableMachine) {
          final IDisableableMachine machine = (IDisableableMachine) tileAt;

          machine.setDisabled(
              (Integer) this.data.get(3), !machine.getDisabled((Integer) this.data.get(3)));
        }
        break;
      case S_ON_FAILED_CHEST_UNLOCK:
        if (playerBase.getPlayerStats().chatCooldown == 0) {
          player.addChatMessage(
              new ChatComponentText(
                  GCCoreUtil.translateWithFormat("gui.chest.warning.wrongkey", this.data.get(0))));
          playerBase.getPlayerStats().chatCooldown = 100;
        }
        break;
      case S_RENAME_SPACE_STATION:
        final SpaceStationWorldData ssdata =
            SpaceStationWorldData.getStationData(
                playerBase.worldObj, (Integer) this.data.get(1), playerBase);

        if (ssdata != null
            && ssdata.getOwner().equalsIgnoreCase(player.getGameProfile().getName())) {
          ssdata.setSpaceStationName((String) this.data.get(0));
          ssdata.setDirty(true);
        }
        break;
      case S_OPEN_EXTENDED_INVENTORY:
        player.openGui(
            GalacticraftCore.instance, GuiIdsCore.EXTENDED_INVENTORY, player.worldObj, 0, 0, 0);
        break;
      case S_ON_ADVANCED_GUI_CLICKED_INT:
        TileEntity tile1 =
            player.worldObj.getTileEntity(
                (Integer) this.data.get(1), (Integer) this.data.get(2), (Integer) this.data.get(3));

        switch ((Integer) this.data.get(0)) {
          case 0:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.redstoneActivation = (Integer) this.data.get(4) == 1;
            }
            break;
          case 1:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.playerDistanceActivation = (Integer) this.data.get(4) == 1;
            }
            break;
          case 2:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.playerDistanceSelection = (Integer) this.data.get(4);
            }
            break;
          case 3:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.playerNameMatches = (Integer) this.data.get(4) == 1;
            }
            break;
          case 4:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.invertSelection = (Integer) this.data.get(4) == 1;
            }
            break;
          case 5:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.lastHorizontalModeEnabled = launchController.horizontalModeEnabled;
              launchController.horizontalModeEnabled = (Integer) this.data.get(4) == 1;
            }
            break;
          case 6:
            if (tile1 instanceof IBubbleProvider) {
              IBubbleProvider distributor = (IBubbleProvider) tile1;
              distributor.setBubbleVisible((Integer) this.data.get(4) == 1);
            }
            break;
          default:
            break;
        }
        break;
      case S_ON_ADVANCED_GUI_CLICKED_STRING:
        TileEntity tile2 =
            player.worldObj.getTileEntity(
                (Integer) this.data.get(1), (Integer) this.data.get(2), (Integer) this.data.get(3));

        switch ((Integer) this.data.get(0)) {
          case 0:
            if (tile2 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile2;
              launchController.playerToOpenFor = (String) this.data.get(4);
            }
            break;
          default:
            break;
        }
        break;
      case S_UPDATE_SHIP_MOTION_Y:
        int entityID = (Integer) this.data.get(0);
        boolean up = (Boolean) this.data.get(1);

        Entity entity2 = player.worldObj.getEntityByID(entityID);

        if (entity2 instanceof EntityAutoRocket) {
          EntityAutoRocket autoRocket = (EntityAutoRocket) entity2;
          autoRocket.motionY += up ? 0.02F : -0.02F;
        }

        break;
      case S_START_NEW_SPACE_RACE:
        Integer teamID = (Integer) this.data.get(0);
        String teamName = (String) this.data.get(1);
        FlagData flagData = (FlagData) this.data.get(2);
        Vector3 teamColor = (Vector3) this.data.get(3);
        List<String> playerList = new ArrayList<String>();

        for (int i = 4; i < this.data.size(); i++) {
          playerList.add((String) this.data.get(i));
        }

        boolean previousData = SpaceRaceManager.getSpaceRaceFromID(teamID) != null;

        SpaceRace newRace = new SpaceRace(playerList, teamName, flagData, teamColor);

        if (teamID > 0) {
          newRace.setSpaceRaceID(teamID);
        }

        SpaceRaceManager.addSpaceRace(newRace);

        if (previousData) {
          SpaceRaceManager.sendSpaceRaceData(
              null, SpaceRaceManager.getSpaceRaceFromPlayer(playerBase.getGameProfile().getName()));
        }
        break;
      case S_REQUEST_FLAG_DATA:
        SpaceRaceManager.sendSpaceRaceData(
            playerBase, SpaceRaceManager.getSpaceRaceFromPlayer((String) this.data.get(0)));
        break;
      case S_INVITE_RACE_PLAYER:
        GCEntityPlayerMP playerInvited =
            PlayerUtil.getPlayerBaseServerFromPlayerUsername((String) this.data.get(0), true);
        if (playerInvited != null) {
          Integer teamInvitedTo = (Integer) this.data.get(1);
          SpaceRace race = SpaceRaceManager.getSpaceRaceFromID(teamInvitedTo);

          if (race != null) {
            playerInvited.getPlayerStats().spaceRaceInviteTeamID = teamInvitedTo;
            String dA = EnumColor.DARK_AQUA.code;
            String bG = EnumColor.BRIGHT_GREEN.code;
            String dB = EnumColor.PURPLE.code;
            String teamNameTotal = "";
            String[] teamNameSplit = race.getTeamName().split(" ");
            for (String teamNamePart : teamNameSplit) {
              teamNameTotal = teamNameTotal.concat(dB + teamNamePart + " ");
            }
            playerInvited.addChatMessage(
                new ChatComponentText(
                        "Received Space Race Team Invite from "
                            + bG
                            + player.getGameProfile().getName()
                            + dA
                            + ". To join "
                            + teamNameTotal
                            + dA
                            + "use command "
                            + EnumColor.AQUA
                            + "/joinrace")
                    .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_AQUA)));
          }
        }
        break;
      case S_REMOVE_RACE_PLAYER:
        Integer teamInvitedTo = (Integer) this.data.get(1);
        SpaceRace race = SpaceRaceManager.getSpaceRaceFromID(teamInvitedTo);

        if (race != null) {
          String playerToRemove = (String) this.data.get(0);

          if (!race.getPlayerNames().remove(playerToRemove)) {
            player.addChatMessage(
                new ChatComponentText("Could not find player with name: " + playerToRemove));
          } else {
            SpaceRaceManager.onPlayerRemoval(playerToRemove, race);
          }
        }
        break;
      case S_ADD_RACE_PLAYER:
        Integer teamToAddPlayer = (Integer) this.data.get(1);
        SpaceRace spaceRaceToAddPlayer = SpaceRaceManager.getSpaceRaceFromID(teamToAddPlayer);

        if (spaceRaceToAddPlayer != null) {
          String playerToAdd = (String) this.data.get(0);

          if (!spaceRaceToAddPlayer.getPlayerNames().contains(playerToAdd)) {
            SpaceRace oldRace = null;
            while ((oldRace = SpaceRaceManager.getSpaceRaceFromPlayer(playerToAdd)) != null) {
              SpaceRaceManager.removeSpaceRace(oldRace);
            }

            spaceRaceToAddPlayer.getPlayerNames().add(playerToAdd);
            SpaceRaceManager.sendSpaceRaceData(null, spaceRaceToAddPlayer);

            for (String member : spaceRaceToAddPlayer.getPlayerNames()) {
              EntityPlayerMP memberObj =
                  MinecraftServer.getServer()
                      .getConfigurationManager()
                      .getPlayerForUsername(member);

              if (memberObj != null) {
                memberObj.addChatMessage(
                    new ChatComponentText(
                            EnumColor.BRIGHT_GREEN
                                + playerToAdd
                                + EnumColor.DARK_AQUA
                                + " has joined the Space Race!")
                        .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_AQUA)));
              }
            }
          } else {
            player.addChatMessage(
                new ChatComponentText("You are already a part of this space race!")
                    .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_RED)));
          }
        }
        break;
      default:
        break;
    }
  }
Пример #4
0
  @SubscribeEvent
  public void onWorldTick(WorldTickEvent event) {
    if (event.phase == Phase.START) {
      final WorldServer world = (WorldServer) event.world;

      CopyOnWriteArrayList<ScheduledBlockChange> changeList =
          TickHandlerServer.scheduledBlockChanges.get(world.provider.dimensionId);

      if (changeList != null && !changeList.isEmpty()) {
        int blockCount = 0;
        int blockCountMax = Math.max(this.MAX_BLOCKS_PER_TICK, changeList.size() / 4);
        List<ScheduledBlockChange> newList =
            new ArrayList<ScheduledBlockChange>(Math.max(0, changeList.size() - blockCountMax));

        for (ScheduledBlockChange change : changeList) {
          if (++blockCount > blockCountMax) {
            newList.add(change);
          } else {
            if (change != null) {
              BlockVec3 changePosition = change.getChangePosition();
              Block block = world.getBlock(changePosition.x, changePosition.y, changePosition.z);
              // Only replace blocks of type BlockAir or fire - this is to prevent accidents where
              // other mods have moved blocks
              if (changePosition != null && (block instanceof BlockAir || block == Blocks.fire)) {
                world.setBlock(
                    changePosition.x,
                    changePosition.y,
                    changePosition.z,
                    change.getChangeID(),
                    change.getChangeMeta(),
                    change.getChangeUpdateFlag());
              }
            }
          }
        }

        changeList.clear();
        TickHandlerServer.scheduledBlockChanges.remove(world.provider.dimensionId);
        if (newList.size() > 0)
          TickHandlerServer.scheduledBlockChanges.put(
              world.provider.dimensionId, new CopyOnWriteArrayList<ScheduledBlockChange>(newList));
      }

      CopyOnWriteArrayList<BlockVec3> torchList =
          TickHandlerServer.scheduledTorchUpdates.get(world.provider.dimensionId);

      if (torchList != null && !torchList.isEmpty()) {
        for (BlockVec3 torch : torchList) {
          if (torch != null) {
            Block b = world.getBlock(torch.x, torch.y, torch.z);
            if (b instanceof BlockUnlitTorch) {
              world.scheduleBlockUpdateWithPriority(
                  torch.x, torch.y, torch.z, b, 2 + world.rand.nextInt(30), 0);
            }
          }
        }

        torchList.clear();
        TickHandlerServer.scheduledTorchUpdates.remove(world.provider.dimensionId);
      }

      if (world.provider instanceof IOrbitDimension) {
        final Object[] entityList = world.loadedEntityList.toArray();

        for (final Object o : entityList) {
          if (o instanceof Entity) {
            final Entity e = (Entity) o;

            if (e.worldObj.provider instanceof IOrbitDimension) {
              final IOrbitDimension dimension = (IOrbitDimension) e.worldObj.provider;

              if (e.posY <= dimension.getYCoordToTeleportToPlanet()) {
                final Integer dim =
                    WorldUtil.getProviderForName(dimension.getPlanetToOrbit()).dimensionId;

                WorldUtil.transferEntityToDimension(e, dim, world, false, null);
              }
            }
          }
        }
      }
    } else if (event.phase == Phase.END) {
      final WorldServer world = (WorldServer) event.world;

      List<BlockVec3> edgesList = TickHandlerServer.edgeChecks.get(world.provider.dimensionId);
      final HashSet<BlockVec3> checkedThisTick = new HashSet();

      if (edgesList != null && !edgesList.isEmpty()) {
        List<BlockVec3> edgesListCopy = new ArrayList();
        edgesListCopy.addAll(edgesList);
        for (BlockVec3 edgeBlock : edgesListCopy) {
          if (edgeBlock != null && !checkedThisTick.contains(edgeBlock)) {
            if (TickHandlerServer.scheduledForChange(world.provider.dimensionId, edgeBlock)) {
              continue;
            }

            ThreadFindSeal done =
                new ThreadFindSeal(world, edgeBlock, 2000, new ArrayList<TileEntityOxygenSealer>());
            checkedThisTick.addAll(done.checked);
          }
        }

        TickHandlerServer.edgeChecks.remove(world.provider.dimensionId);
      }
    }
  }
Пример #5
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;
  }
  @SubscribeEvent
  public void onWorldTick(WorldTickEvent event) {
    if (event.phase == Phase.START) {
      final WorldServer world = (WorldServer) event.world;

      CopyOnWriteArrayList<ScheduledBlockChange> changeList =
          TickHandlerServer.scheduledBlockChanges.get(world.provider.dimensionId);

      if (changeList != null && !changeList.isEmpty()) {
        for (ScheduledBlockChange change : changeList) {
          if (change != null) {
            BlockVec3 changePosition = change.getChangePosition();
            if (changePosition != null) {
              world.setBlock(
                  changePosition.x,
                  changePosition.y,
                  changePosition.z,
                  change.getChangeID(),
                  change.getChangeMeta(),
                  2);
            }
          }
        }

        changeList.clear();
        TickHandlerServer.scheduledBlockChanges.remove(world.provider.dimensionId);
      }

      CopyOnWriteArrayList<BlockVec3> torchList =
          TickHandlerServer.scheduledTorchUpdates.get(world.provider.dimensionId);

      if (torchList != null && !torchList.isEmpty()) {
        for (BlockVec3 torch : torchList) {
          if (torch != null) {
            if (world.getBlock(torch.x, torch.y, torch.z) == GCBlocks.unlitTorch) {
              world.scheduleBlockUpdateWithPriority(
                  torch.x, torch.y, torch.z, GCBlocks.unlitTorch, 2 + world.rand.nextInt(30), 0);
            } else if (world.getBlock(torch.x, torch.y, torch.z) == GCBlocks.unlitTorchLit) {
              world.scheduleBlockUpdateWithPriority(
                  torch.x, torch.y, torch.z, GCBlocks.unlitTorchLit, 2 + world.rand.nextInt(30), 0);
            }
          }
        }

        torchList.clear();
        TickHandlerServer.scheduledTorchUpdates.remove(world.provider.dimensionId);
      }

      if (world.provider instanceof IOrbitDimension) {
        final Object[] entityList = world.loadedEntityList.toArray();

        for (final Object o : entityList) {
          if (o instanceof Entity) {
            final Entity e = (Entity) o;

            if (e.worldObj.provider instanceof IOrbitDimension) {
              final IOrbitDimension dimension = (IOrbitDimension) e.worldObj.provider;

              if (e.posY <= dimension.getYCoordToTeleportToPlanet()) {
                final Integer dim =
                    WorldUtil.getProviderForName(dimension.getPlanetToOrbit()).dimensionId;

                WorldUtil.transferEntityToDimension(e, dim, world, false, null);
              }
            }
          }
        }
      }
    } else if (event.phase == Phase.END) {
      final WorldServer world = (WorldServer) event.world;

      List<BlockVec3> edgesList = TickHandlerServer.edgeChecks.get(world.provider.dimensionId);
      final HashSet<BlockVec3> checkedThisTick = new HashSet();

      if (edgesList != null && !edgesList.isEmpty()) {
        List<BlockVec3> edgesListCopy = new ArrayList();
        edgesListCopy.addAll(edgesList);
        for (BlockVec3 edgeBlock : edgesListCopy) {
          if (edgeBlock != null && !checkedThisTick.contains(edgeBlock)) {
            if (TickHandlerServer.scheduledForChange(world.provider.dimensionId, edgeBlock)) {
              continue;
            }

            ThreadFindSeal done =
                new ThreadFindSeal(world, edgeBlock, 2000, new ArrayList<TileEntityOxygenSealer>());
            checkedThisTick.addAll(done.checked);
          }
        }

        TickHandlerServer.edgeChecks.remove(world.provider.dimensionId);
      }
    }
  }
Пример #7
0
  @Override
  @SuppressWarnings("unchecked")
  public void onUpdate() {
    super.onUpdate();

    if (this.ticksExisted > 400) {
      if (this.isHot) {
        this.isHot = false;
        this.setHot(this.isHot);
      }
    } else if (!this.worldObj.isRemote) {
      this.setHot(this.isHot);
    }

    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.prevRotationYaw =
          this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
      this.prevRotationPitch =
          this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI);
    }

    BlockPos pos = new BlockPos(this.xTile, this.yTile, this.zTile);
    Block block = this.worldObj.getBlockState(pos).getBlock();

    if (!block.isAir(this.worldObj, pos)) {
      block.setBlockBoundsBasedOnState(this.worldObj, pos);
      AxisAlignedBB axisalignedbb =
          block.getCollisionBoundingBox(this.worldObj, pos, this.worldObj.getBlockState(pos));

      if (axisalignedbb != null
          && axisalignedbb.isVecInside(new Vec3(this.posX, this.posY, this.posZ))) {
        this.inGround = true;
      }
    }

    if (this.inGround) {
      Block j = this.worldObj.getBlockState(pos).getBlock();
      int k = j.getMetaFromState(this.worldObj.getBlockState(pos));

      if (j == this.inTile && k == this.inData) {
        ++this.ticksInGround;

        if (this.ticksInGround == 1200) {
          this.setDead();
        }
      } else {
        this.inGround = false;
        this.motionX *= this.rand.nextFloat() * 0.2F;
        this.motionY *= this.rand.nextFloat() * 0.2F;
        this.motionZ *= this.rand.nextFloat() * 0.2F;
        this.ticksInGround = 0;
        this.ticksInAir = 0;
      }
    } else {
      ++this.ticksInAir;
      Vec3 vec3 = new Vec3(this.posX, this.posY, this.posZ);
      Vec3 vec31 =
          new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
      MovingObjectPosition movingobjectposition =
          this.worldObj.rayTraceBlocks(vec3, vec31, false, true, false);
      vec3 = new Vec3(this.posX, this.posY, this.posZ);
      vec31 =
          new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

      if (movingobjectposition != null) {
        vec31 =
            new Vec3(
                movingobjectposition.hitVec.xCoord,
                movingobjectposition.hitVec.yCoord,
                movingobjectposition.hitVec.zCoord);
      }

      this.rotationPitch += 1F;

      Entity entity = null;
      List<Entity> list =
          this.worldObj.getEntitiesWithinAABBExcludingEntity(
              this,
              this.getEntityBoundingBox()
                  .addCoord(this.motionX, this.motionY, this.motionZ)
                  .expand(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;
      int l;
      float f1;

      for (l = 0; l < list.size(); ++l) {
        Entity entity1 = list.get(l);

        if (entity1.canBeCollidedWith()
            && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 = entity1.getEntityBoundingBox().expand(f1, f1, f1);
          MovingObjectPosition movingobjectposition1 =
              axisalignedbb1.calculateIntercept(vec3, vec31);

          if (movingobjectposition1 != null) {
            double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

            if (d1 < d0 || d0 == 0.0D) {
              entity = entity1;
              d0 = d1;
            }
          }
        }
      }

      if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
      }

      if (movingobjectposition != null
          && movingobjectposition.entityHit != null
          && movingobjectposition.entityHit instanceof EntityPlayer) {
        EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;

        if (entityplayer.capabilities.disableDamage
            || this.shootingEntity instanceof EntityPlayer
                && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
          movingobjectposition = null;
        }
      }

      float f2;
      float f3;
      double damage = ConfigManagerCore.hardMode ? 3.2D : 1.6D;

      if (movingobjectposition != null) {
        if (movingobjectposition.entityHit != null) {
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          int i1 = MathHelper.ceiling_double_int(f2 * damage);

          DamageSource damagesource = null;

          if (this.shootingEntity == null) {
            damagesource =
                new EntityDamageSourceIndirect("meteorChunk", this, this).setProjectile();
          } else {
            damagesource =
                new EntityDamageSourceIndirect("meteorChunk", this, this.shootingEntity)
                    .setProjectile();
          }

          if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman)) {
            movingobjectposition.entityHit.setFire(2);
          }

          if (movingobjectposition.entityHit.attackEntityFrom(damagesource, i1)) {
            if (movingobjectposition.entityHit instanceof EntityLivingBase) {
              EntityLivingBase entitylivingbase = (EntityLivingBase) movingobjectposition.entityHit;

              if (!this.worldObj.isRemote) {
                entitylivingbase.setArrowCountInEntity(
                    entitylivingbase.getArrowCountInEntity() + 1);
              }

              if (this.knockbackStrength > 0) {
                f3 =
                    MathHelper.sqrt_double(
                        this.motionX * this.motionX + this.motionZ * this.motionZ);

                if (f3 > 0.0F) {
                  movingobjectposition.entityHit.addVelocity(
                      this.motionX * this.knockbackStrength * 0.6000000238418579D / f3,
                      0.1D,
                      this.motionZ * this.knockbackStrength * 0.6000000238418579D / f3);
                }
              }

              if (this.shootingEntity != null) {
                EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
                EnchantmentHelper.applyArthropodEnchantments(
                    (EntityLivingBase) this.shootingEntity, entitylivingbase);
              }

              if (this.shootingEntity != null
                  && movingobjectposition.entityHit != this.shootingEntity
                  && movingobjectposition.entityHit instanceof EntityPlayer
                  && this.shootingEntity instanceof EntityPlayerMP) {
                ((EntityPlayerMP) this.shootingEntity)
                    .playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
              }
            }

            if (!(movingobjectposition.entityHit instanceof EntityEnderman)) {
              this.setDead();
            }
          } else {
            this.motionX *= -0.10000000149011612D;
            this.motionY *= -0.10000000149011612D;
            this.motionZ *= -0.10000000149011612D;
            this.rotationYaw += 180.0F;
            this.prevRotationYaw += 180.0F;
            this.ticksInAir = 0;
          }
        } else {
          this.xTile = movingobjectposition.getBlockPos().getX();
          this.yTile = movingobjectposition.getBlockPos().getY();
          this.zTile = movingobjectposition.getBlockPos().getZ();
          IBlockState state = this.worldObj.getBlockState(movingobjectposition.getBlockPos());
          this.inTile = state.getBlock();
          this.inData = this.inTile.getMetaFromState(state);
          this.motionX = (float) (movingobjectposition.hitVec.xCoord - this.posX);
          this.motionY = (float) (movingobjectposition.hitVec.yCoord - this.posY);
          this.motionZ = (float) (movingobjectposition.hitVec.zCoord - this.posZ);
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          this.posX -= this.motionX / f2 * 0.05000000074505806D;
          this.posY -= this.motionY / f2 * 0.05000000074505806D;
          this.posZ -= this.motionZ / f2 * 0.05000000074505806D;
          this.inGround = true;

          if (!this.inTile.isAir(this.worldObj, movingobjectposition.getBlockPos())) {
            this.inTile.onEntityCollidedWithBlock(
                this.worldObj, movingobjectposition.getBlockPos(), this);
          }
        }
      }

      this.posX += this.motionX;
      this.posY += this.motionY;
      this.posZ += this.motionZ;
      f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);

      if (!this.onGround) {
        this.rotationPitch += 10;
        this.rotationYaw += 2;
      }

      float f4 = 0.99F;
      f1 = 0.05F;

      if (this.isInWater()) {
        for (int j1 = 0; j1 < 4; ++j1) {
          f3 = 0.25F;
          this.worldObj.spawnParticle(
              EnumParticleTypes.WATER_BUBBLE,
              this.posX - this.motionX * f3,
              this.posY - this.motionY * f3,
              this.posZ - this.motionZ * f3,
              this.motionX,
              this.motionY,
              this.motionZ);
        }

        f4 = 0.8F;
      }

      this.motionX *= f4;
      this.motionY *= f4;
      this.motionZ *= f4;
      this.motionY -= WorldUtil.getGravityForEntity(this);
      this.setPosition(this.posX, this.posY, this.posZ);
      this.doBlockCollisions();
    }
  }
Пример #8
0
  private void updateFeet(EntityPlayerSP player, double motionX, double motionZ) {
    GCPlayerStatsClient stats = GCPlayerStatsClient.get(player);
    double motionSqrd = motionX * motionX + motionZ * motionZ;

    // If the player is on the moon, not airbourne and not riding anything
    if (motionSqrd > 0.001
        && player.worldObj != null
        && player.worldObj.provider instanceof WorldProviderMoon
        && player.ridingEntity == null
        && !player.capabilities.isFlying) {
      int iPosX = (int) Math.floor(player.posX);
      int iPosY = (int) Math.floor(player.posY - 1);
      int iPosZ = (int) Math.floor(player.posZ);
      BlockPos pos1 = new BlockPos(iPosX, iPosY, iPosZ);
      IBlockState state = player.worldObj.getBlockState(pos1);

      // If the block below is the moon block
      if (state.getBlock() == GCBlocks.blockMoon) {
        // And is the correct metadata (moon turf)
        if (state.getBlock().getMetaFromState(state) == 5) {
          // If it has been long enough since the last step
          if (stats.distanceSinceLastStep > 0.35) {
            Vector3 pos = new Vector3(player);
            // Set the footprint position to the block below and add random number to stop
            // z-fighting
            pos.y = MathHelper.floor_double(player.posY) + player.getRNG().nextFloat() / 100.0F;

            // Adjust footprint to left or right depending on step count
            switch (stats.lastStep) {
              case 0:
                pos.translate(
                    new Vector3(
                        Math.sin(Math.toRadians(-player.rotationYaw + 90)) * 0.25,
                        0,
                        Math.cos(Math.toRadians(-player.rotationYaw + 90)) * 0.25));
                break;
              case 1:
                pos.translate(
                    new Vector3(
                        Math.sin(Math.toRadians(-player.rotationYaw - 90)) * 0.25,
                        0,
                        Math.cos(Math.toRadians(-player.rotationYaw - 90)) * 0.25));
                break;
            }

            pos =
                WorldUtil.getFootprintPosition(
                    player.worldObj, player.rotationYaw - 180, pos, new BlockVec3(player));

            long chunkKey = ChunkCoordIntPair.chunkXZ2Int(pos.intX() >> 4, pos.intZ() >> 4);
            ClientProxyCore.footprintRenderer.addFootprint(
                chunkKey,
                player.worldObj.provider.getDimensionId(),
                pos,
                player.rotationYaw,
                player.getName());

            // Increment and cap step counter at 1
            stats.lastStep++;
            stats.lastStep %= 2;
            stats.distanceSinceLastStep = 0;
          } else {
            stats.distanceSinceLastStep += motionSqrd;
          }
        }
      }
    }
  }