public static void updateSSOwnership( EntityPlayerMP player, String playerName, GCPlayerStats stats, int stationID, SpaceStationWorldData stationData) { if (stationData == null) { stationData = SpaceStationWorldData.getMPSpaceStationData(null, stationID, null); } if (stationData.owner.equals(playerName)) { // This player is the owner of the station - ensure stats data matches if (!(stats.spaceStationDimensionData.values().contains(stationID))) { GCLog.debug( "Player owns station: " + stationData.getSpaceStationName() + " with home planet " + stationData.getHomePlanet()); stats.spaceStationDimensionData.put(stationData.getHomePlanet(), stationID); } } else { // This player is the owner of the station - remove from stats data Integer savedOwned = stats.spaceStationDimensionData.get(stationData.getHomePlanet()); if (savedOwned != null && savedOwned == stationID) { GCLog.debug( "Player does not own station: " + stationData.getSpaceStationName() + " with home planet " + stationData.getHomePlanet()); stats.spaceStationDimensionData.remove(savedOwned); } } }
@Override public void readFromNBT(NBTTagCompound nbttagcompound) { this.owner = nbttagcompound.getString("owner").replace(".", ""); this.spaceStationName = nbttagcompound.getString("spaceStationName"); if (nbttagcompound.hasKey("dataCompound")) { this.dataCompound = nbttagcompound.getCompoundTag("dataCompound"); } else { this.dataCompound = new NBTTagCompound(); } if (nbttagcompound.hasKey("homePlanet")) { this.homePlanet = nbttagcompound.getInteger("homePlanet"); } else { GCLog.info( "Home planet data not found in space station save file for \"" + this.spaceStationName + "\". Using default overworld."); this.homePlanet = 0; // Overworld dimension ID } if (nbttagcompound.hasKey("dimensionIdStatic")) { this.dimensionIdStatic = nbttagcompound.getInteger("dimensionIdStatic"); } else { GCLog.info( "Static dimension ID not found in space station save file for \"" + this.spaceStationName + "\". Using default overworld."); this.dimensionIdStatic = ConfigManagerCore.idDimensionOverworldOrbitStatic; } if (nbttagcompound.hasKey("dimensionIdDynamic")) { this.dimensionIdDynamic = nbttagcompound.getInteger("dimensionIdDynamic"); } else { GCLog.info( "Dynamic dimension ID not found in space station save file for \"" + this.spaceStationName + "\". Using default overworld."); this.dimensionIdDynamic = ConfigManagerCore.idDimensionOverworldOrbit; } this.allowAllPlayers = nbttagcompound.getBoolean("allowedAll"); final NBTTagList var2 = nbttagcompound.getTagList("allowedPlayers", 10); this.allowedPlayers.clear(); for (int var3 = 0; var3 < var2.tagCount(); ++var3) { final NBTTagCompound var4 = var2.getCompoundTagAt(var3); final String var5 = var4.getString("allowedPlayer"); if (!this.allowedPlayers.contains(var5)) { this.allowedPlayers.add(var5); } } }
public PacketSimple(EnumSimplePacket packetType, List<Object> data) { if (packetType.getDecodeClasses().length != data.size()) { GCLog.info("Simple Packet Core found data length different than packet type"); new RuntimeException().printStackTrace(); } this.type = packetType; this.data = data; }
@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; } }
@SideOnly(Side.CLIENT) @Override public void handleClientSide(EntityPlayer player) { GCEntityClientPlayerMP playerBaseClient = null; if (player instanceof GCEntityClientPlayerMP) { playerBaseClient = (GCEntityClientPlayerMP) player; } else { return; } switch (this.type) { case C_AIR_REMAINING: if (String.valueOf(this.data.get(2)) .equals( String.valueOf( FMLClientHandler.instance() .getClient() .thePlayer .getGameProfile() .getName()))) { TickHandlerClient.airRemaining = (Integer) this.data.get(0); TickHandlerClient.airRemaining2 = (Integer) this.data.get(1); } break; case C_UPDATE_DIMENSION_LIST: if (String.valueOf(this.data.get(0)) .equals(FMLClientHandler.instance().getClient().thePlayer.getGameProfile().getName())) { final String[] destinations = ((String) this.data.get(1)).split("\\."); if (FMLClientHandler.instance().getClient().theWorld != null && !(FMLClientHandler.instance().getClient().currentScreen instanceof GuiCelestialSelection || FMLClientHandler.instance().getClient().currentScreen instanceof GuiGalaxyMap)) { FMLClientHandler.instance().getClient().displayGuiScreen(new GuiCelestialSelection()); } } break; case C_SPAWN_SPARK_PARTICLES: int x, y, z; x = (Integer) this.data.get(0); y = (Integer) this.data.get(1); z = (Integer) this.data.get(2); Minecraft mc = Minecraft.getMinecraft(); for (int i = 0; i < 4; i++) { if (mc != null && mc.renderViewEntity != null && mc.effectRenderer != null && mc.theWorld != null) { final EntityFX fx = new EntityFXSparks( mc.theWorld, x - 0.15 + 0.5, y + 1.2, z + 0.15 + 0.5, mc.theWorld.rand.nextDouble() / 20 - mc.theWorld.rand.nextDouble() / 20, mc.theWorld.rand.nextDouble() / 20 - mc.theWorld.rand.nextDouble() / 20); if (fx != null) { mc.effectRenderer.addEffect(fx); } } } break; case C_UPDATE_GEAR_SLOT: int subtype = (Integer) this.data.get(2); EntityPlayer gearDataPlayer = null; MinecraftServer server = MinecraftServer.getServer(); if (server != null) { gearDataPlayer = server.getConfigurationManager().getPlayerForUsername((String) this.data.get(0)); } else { gearDataPlayer = player.worldObj.getPlayerEntityByName((String) this.data.get(0)); } if (gearDataPlayer != null) { PlayerGearData gearData = ClientProxyCore.playerItemData.get(gearDataPlayer.getPersistentID()); if (gearData == null) { gearData = new PlayerGearData(player); } EnumModelPacket type = EnumModelPacket.values()[(Integer) this.data.get(1)]; switch (type) { case ADDMASK: gearData.setMask(0); break; case REMOVEMASK: gearData.setMask(-1); break; case ADDGEAR: gearData.setGear(0); break; case REMOVEGEAR: gearData.setGear(-1); break; case ADDLEFTGREENTANK: gearData.setLeftTank(0); break; case ADDLEFTORANGETANK: gearData.setLeftTank(1); break; case ADDLEFTREDTANK: gearData.setLeftTank(2); break; case ADDRIGHTGREENTANK: gearData.setRightTank(0); break; case ADDRIGHTORANGETANK: gearData.setRightTank(1); break; case ADDRIGHTREDTANK: gearData.setRightTank(2); break; case REMOVE_LEFT_TANK: gearData.setLeftTank(-1); break; case REMOVE_RIGHT_TANK: gearData.setRightTank(-1); break; case ADD_PARACHUTE: String name = ""; if (subtype != -1) { name = ItemParaChute.names[subtype]; gearData.setParachute( new ResourceLocation( GalacticraftCore.ASSET_DOMAIN, "textures/model/parachute/" + name + ".png")); } break; case REMOVE_PARACHUTE: gearData.setParachute(null); break; case ADD_FREQUENCY_MODULE: gearData.setFrequencyModule(0); break; case REMOVE_FREQUENCY_MODULE: gearData.setFrequencyModule(-1); break; case ADD_THERMAL_HELMET: gearData.setThermalPadding(0, 0); break; case ADD_THERMAL_CHESTPLATE: gearData.setThermalPadding(1, 0); break; case ADD_THERMAL_LEGGINGS: gearData.setThermalPadding(2, 0); break; case ADD_THERMAL_BOOTS: gearData.setThermalPadding(3, 0); break; case REMOVE_THERMAL_HELMET: gearData.setThermalPadding(0, -1); break; case REMOVE_THERMAL_CHESTPLATE: gearData.setThermalPadding(1, -1); break; case REMOVE_THERMAL_LEGGINGS: gearData.setThermalPadding(2, -1); break; case REMOVE_THERMAL_BOOTS: gearData.setThermalPadding(3, -1); break; default: break; } ClientProxyCore.playerItemData.put(playerBaseClient.getPersistentID(), gearData); } break; case C_CLOSE_GUI: FMLClientHandler.instance().getClient().displayGuiScreen(null); break; case C_RESET_THIRD_PERSON: FMLClientHandler.instance().getClient().gameSettings.thirdPersonView = playerBaseClient.getThirdPersonView(); break; case C_UPDATE_SPACESTATION_LIST: try { if (WorldUtil.registeredSpaceStations != null) { for (Integer registeredID : WorldUtil.registeredSpaceStations) { DimensionManager.unregisterDimension(registeredID); } } WorldUtil.registeredSpaceStations = new ArrayList<Integer>(); if (this.data.size() > 0) { if (this.data.get(0) instanceof Integer) { for (Object o : this.data) { Integer dimID = (Integer) o; if (!WorldUtil.registeredSpaceStations.contains(dimID)) { WorldUtil.registeredSpaceStations.add(dimID); if (!DimensionManager.isDimensionRegistered(dimID)) { DimensionManager.registerDimension( dimID, ConfigManagerCore.idDimensionOverworldOrbit); } else { GCLog.severe( "Dimension already registered on client: unable to register space station dimension " + dimID); } } } } else if (this.data.get(0) instanceof Integer[]) { for (Object o : (Integer[]) this.data.get(0)) { Integer dimID = (Integer) o; if (!WorldUtil.registeredSpaceStations.contains(dimID)) { WorldUtil.registeredSpaceStations.add(dimID); if (!DimensionManager.isDimensionRegistered(dimID)) { DimensionManager.registerDimension( dimID, ConfigManagerCore.idDimensionOverworldOrbit); } else { GCLog.severe( "Dimension already registered on client: unable to register space station dimension " + dimID); } } } } } break; } catch (final Exception e) { e.printStackTrace(); } case C_UPDATE_SPACESTATION_DATA: SpaceStationWorldData var4 = SpaceStationWorldData.getMPSpaceStationData( player.worldObj, (Integer) this.data.get(0), player); var4.readFromNBT((NBTTagCompound) this.data.get(1)); break; case C_UPDATE_SPACESTATION_CLIENT_ID: ClientProxyCore.clientSpaceStationID = (Integer) this.data.get(0); break; case C_UPDATE_PLANETS_LIST: try { if (WorldUtil.registeredPlanets != null) { for (Integer registeredID : WorldUtil.registeredPlanets) { DimensionManager.unregisterDimension(registeredID); } } WorldUtil.registeredPlanets = new ArrayList<Integer>(); if (this.data.size() > 0) { if (this.data.get(0) instanceof Integer) { for (Object o : this.data) { Integer dimID = (Integer) o; if (!WorldUtil.registeredPlanets.contains(dimID)) { WorldUtil.registeredPlanets.add(dimID); DimensionManager.registerDimension(dimID, dimID); } } } else if (this.data.get(0) instanceof Integer[]) { for (Object o : (Integer[]) this.data.get(0)) { Integer dimID = (Integer) o; if (!WorldUtil.registeredPlanets.contains(dimID)) { WorldUtil.registeredPlanets.add(dimID); DimensionManager.registerDimension(dimID, dimID); } } } } break; } catch (final Exception e) { e.printStackTrace(); } case C_ADD_NEW_SCHEMATIC: final ISchematicPage page = SchematicRegistry.getMatchingRecipeForID((Integer) this.data.get(0)); if (!playerBaseClient.unlockedSchematics.contains(page)) { playerBaseClient.unlockedSchematics.add(page); } break; case C_UPDATE_SCHEMATIC_LIST: for (Object o : this.data) { Integer schematicID = (Integer) o; if (schematicID != -2) { Collections.sort(playerBaseClient.unlockedSchematics); if (!playerBaseClient.unlockedSchematics.contains( SchematicRegistry.getMatchingRecipeForID(Integer.valueOf(schematicID)))) { playerBaseClient.unlockedSchematics.add( SchematicRegistry.getMatchingRecipeForID(Integer.valueOf(schematicID))); } } } break; case C_PLAY_SOUND_BOSS_DEATH: player.playSound(GalacticraftCore.ASSET_PREFIX + "entity.bossdeath", 10.0F, 0.8F); break; case C_PLAY_SOUND_EXPLODE: player.playSound("random.explode", 10.0F, 0.7F); break; case C_PLAY_SOUND_BOSS_LAUGH: player.playSound(GalacticraftCore.ASSET_PREFIX + "entity.bosslaugh", 10.0F, 0.2F); break; case C_PLAY_SOUND_BOW: player.playSound("random.bow", 10.0F, 0.2F); break; case C_UPDATE_OXYGEN_VALIDITY: playerBaseClient.oxygenSetupValid = (Boolean) this.data.get(0); break; case C_OPEN_PARACHEST_GUI: switch ((Integer) this.data.get(1)) { case 0: if (player.ridingEntity instanceof EntityBuggy) { FMLClientHandler.instance() .getClient() .displayGuiScreen( new GuiBuggy( player.inventory, (EntityBuggy) player.ridingEntity, ((EntityBuggy) player.ridingEntity).getType())); player.openContainer.windowId = (Integer) this.data.get(0); } break; case 1: int entityID = (Integer) this.data.get(2); Entity entity = player.worldObj.getEntityByID(entityID); if (entity != null && entity instanceof IInventorySettable) { FMLClientHandler.instance() .getClient() .displayGuiScreen( new GuiParaChest(player.inventory, (IInventorySettable) entity)); } player.openContainer.windowId = (Integer) this.data.get(0); break; } break; case C_UPDATE_WIRE_BOUNDS: TileEntity tile = player.worldObj.getTileEntity( (Integer) this.data.get(0), (Integer) this.data.get(1), (Integer) this.data.get(2)); if (tile instanceof TileEntityConductor) { ((TileEntityConductor) tile).adjacentConnections = null; player .worldObj .getBlock(tile.xCoord, tile.yCoord, tile.zCoord) .setBlockBoundsBasedOnState(player.worldObj, tile.xCoord, tile.yCoord, tile.zCoord); } break; case C_OPEN_SPACE_RACE_GUI: if (Minecraft.getMinecraft().currentScreen == null) { TickHandlerClient.spaceRaceGuiScheduled = false; player.openGui( GalacticraftCore.instance, GuiIdsCore.SPACE_RACE_START, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); } else { TickHandlerClient.spaceRaceGuiScheduled = true; } break; case C_UPDATE_SPACE_RACE_DATA: 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++) { String playerName = (String) this.data.get(i); ClientProxyCore.flagRequestsSent.remove(playerName); playerList.add(playerName); } SpaceRace race = new SpaceRace(playerList, teamName, flagData, teamColor); race.setSpaceRaceID(teamID); SpaceRaceManager.addSpaceRace(race); break; case C_OPEN_JOIN_RACE_GUI: playerBaseClient.spaceRaceInviteTeamID = (Integer) this.data.get(0); player.openGui( GalacticraftCore.instance, GuiIdsCore.SPACE_RACE_JOIN, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ); break; case C_UPDATE_FOOTPRINT_LIST: ClientProxyCore.footprintRenderer.footprints.clear(); for (int i = 0; i < this.data.size(); i++) { Footprint print = (Footprint) this.data.get(i); ClientProxyCore.footprintRenderer.addFootprint(print); } break; case C_UPDATE_STATION_SPIN: if (playerBaseClient.worldObj.provider instanceof WorldProviderOrbit) { ((WorldProviderOrbit) playerBaseClient.worldObj.provider) .setSpinRate((Float) this.data.get(0), (Boolean) this.data.get(1)); } break; case C_UPDATE_STATION_DATA: if (playerBaseClient.worldObj.provider instanceof WorldProviderOrbit) { ((WorldProviderOrbit) playerBaseClient.worldObj.provider) .setSpinCentre((Double) this.data.get(0), (Double) this.data.get(1)); } break; case C_UPDATE_STATION_BOX: if (playerBaseClient.worldObj.provider instanceof WorldProviderOrbit) { ((WorldProviderOrbit) playerBaseClient.worldObj.provider) .setSpinBox( (Integer) this.data.get(0), (Integer) this.data.get(1), (Integer) this.data.get(2), (Integer) this.data.get(3), (Integer) this.data.get(4), (Integer) this.data.get(5)); } break; case C_UPDATE_THERMAL_LEVEL: playerBaseClient.thermalLevel = (Integer) this.data.get(0); break; case C_DISPLAY_ROCKET_CONTROLS: player.addChatMessage( new ChatComponentText( Keyboard.getKeyName(KeyHandlerClient.spaceKey.getKeyCode()) + " - " + GCCoreUtil.translate("gui.rocket.launch.name"))); player.addChatMessage( new ChatComponentText( Keyboard.getKeyName(KeyHandlerClient.leftKey.getKeyCode()) + " / " + Keyboard.getKeyName(KeyHandlerClient.rightKey.getKeyCode()) + " - " + GCCoreUtil.translate("gui.rocket.turn.name"))); player.addChatMessage( new ChatComponentText( Keyboard.getKeyName(KeyHandlerClient.accelerateKey.getKeyCode()) + " / " + Keyboard.getKeyName(KeyHandlerClient.decelerateKey.getKeyCode()) + " - " + GCCoreUtil.translate("gui.rocket.updown.name"))); player.addChatMessage( new ChatComponentText( Keyboard.getKeyName(KeyHandlerClient.openFuelGui.getKeyCode()) + " - " + GCCoreUtil.translate("gui.rocket.inv.name"))); break; default: break; } }
@SubscribeEvent public void onServerTick(ServerTickEvent event) { MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); // Prevent issues when clients switch to LAN servers if (server == null) return; if (event.phase == Phase.START) { if (MapUtil.calculatingMap.get()) MapUtil.BiomeMapNextTick(); else if (!MapUtil.doneOverworldTexture) MapUtil.makeOverworldTexture(); if (TickHandlerServer.spaceRaceData == null) { World world = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(0); TickHandlerServer.spaceRaceData = (WorldDataSpaceRaces) world.mapStorage.loadData( WorldDataSpaceRaces.class, WorldDataSpaceRaces.saveDataID); if (TickHandlerServer.spaceRaceData == null) { TickHandlerServer.spaceRaceData = new WorldDataSpaceRaces(WorldDataSpaceRaces.saveDataID); world.mapStorage.setData(WorldDataSpaceRaces.saveDataID, TickHandlerServer.spaceRaceData); } } SpaceRaceManager.tick(); if (TickHandlerServer.tickCount % 100 == 0) { WorldServer[] worlds = server.worldServers; for (int i = 0; i < worlds.length; i++) { WorldServer world = worlds[i]; ChunkProviderServer chunkProviderServer = world.theChunkProviderServer; Map<Long, List<Footprint>> footprintMap = TickHandlerServer.serverFootprintMap.get(world.provider.dimensionId); if (footprintMap != null) { boolean mapChanged = false; if (chunkProviderServer != null) { Iterator iterator = chunkProviderServer.loadedChunks.iterator(); while (iterator.hasNext()) { Chunk chunk = (Chunk) iterator.next(); long chunkKey = ChunkCoordIntPair.chunkXZ2Int(chunk.xPosition, chunk.zPosition); List<Footprint> footprints = footprintMap.get(chunkKey); if (footprints != null) { List<Footprint> toRemove = new ArrayList<Footprint>(); for (int j = 0; j < footprints.size(); j++) { footprints.get(j).age += 100; if (footprints.get(j).age >= Footprint.MAX_AGE) { toRemove.add(footprints.get(j)); } } if (!toRemove.isEmpty()) { footprints.removeAll(toRemove); } footprintMap.put(chunkKey, footprints); mapChanged = true; GalacticraftCore.packetPipeline.sendToDimension( new PacketSimple( EnumSimplePacket.C_UPDATE_FOOTPRINT_LIST, new Object[] { chunkKey, footprints.toArray(new Footprint[footprints.size()]) }), worlds[i].provider.dimensionId); } } } if (mapChanged) { TickHandlerServer.serverFootprintMap.put(world.provider.dimensionId, footprintMap); } } } } if (!footprintBlockChanges.isEmpty()) { for (BlockVec3Dim targetPoint : footprintBlockChanges) { WorldServer[] worlds = FMLCommonHandler.instance().getMinecraftServerInstance().worldServers; for (int i = 0; i < worlds.length; i++) { WorldServer world = worlds[i]; if (world.provider.dimensionId == targetPoint.dim) { long chunkKey = ChunkCoordIntPair.chunkXZ2Int((int) targetPoint.x >> 4, (int) targetPoint.z >> 4); GalacticraftCore.packetPipeline.sendToAllAround( new PacketSimple( EnumSimplePacket.C_FOOTPRINTS_REMOVED, new Object[] { chunkKey, new BlockVec3(targetPoint.x, targetPoint.y, targetPoint.z) }), new NetworkRegistry.TargetPoint( targetPoint.dim, targetPoint.x, targetPoint.y, targetPoint.z, 50)); // Map<Long, List<Footprint>> footprintMap = // TickHandlerServer.serverFootprintMap.get(world.provider.dimensionId); // // if (footprintMap != null && !footprintMap.isEmpty()) // { // List<Footprint> footprints = // footprintMap.get(chunkKey); // if (footprints != null) // GalacticraftCore.packetPipeline.sendToAllAround(new // PacketSimple(EnumSimplePacket.C_UPDATE_FOOTPRINT_LIST, new Object[] { chunkKey, // footprints.toArray(new Footprint[footprints.size()]) }), new // NetworkRegistry.TargetPoint(targetPoint.dim, targetPoint.x, targetPoint.y, // targetPoint.z, 50)); // } } } } footprintBlockChanges.clear(); } if (tickCount % 20 == 0) { if (!playersRequestingMapData.isEmpty()) { ArrayList<EntityPlayerMP> copy = new ArrayList<EntityPlayerMP>(playersRequestingMapData); for (EntityPlayerMP playerMP : copy) { GCPlayerStats stats = GCPlayerStats.get(playerMP); ChunkCoordIntPair chunkCoordIntPair = new ChunkCoordIntPair( (int) Math.floor(stats.coordsTeleportedFromX) >> 4, (int) Math.floor(stats.coordsTeleportedFromZ) >> 4); BufferedImage image = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB); for (int x0 = -12; x0 <= 12; x0++) { for (int z0 = -12; z0 <= 12; z0++) { Chunk chunk = MinecraftServer.getServer() .worldServerForDimension(0) .getChunkFromChunkCoords( chunkCoordIntPair.chunkXPos + x0, chunkCoordIntPair.chunkZPos + z0); if (chunk != null) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { int l4 = chunk.getHeightValue(x, z) + 1; Block block = Blocks.air; int i5 = 0; if (l4 > 1) { do { --l4; block = chunk.getBlock(x, l4, z); i5 = chunk.getBlockMetadata(x, l4, z); } while (block.getMapColor(i5) == MapColor.airColor && l4 > 0); } int col = block.getMapColor(i5).colorValue; image.setRGB(x + (x0 + 12) * 16, z + (z0 + 12) * 16, col); } } } } } try { File baseFolder = new File( MinecraftServer.getServer().worldServerForDimension(0).getChunkSaveLocation(), "galacticraft/overworldMap"); if (!baseFolder.exists()) { if (!baseFolder.mkdirs()) { GCLog.severe( "Base folder(s) could not be created: " + baseFolder.getAbsolutePath()); } } File outputFile = new File( baseFolder, "" + chunkCoordIntPair.chunkXPos + "_" + chunkCoordIntPair.chunkZPos + ".jpg"); if (!outputFile.exists() || (outputFile.canWrite() && outputFile.canRead())) { ImageIO.write(image, "jpg", outputFile); } } catch (IOException e) { e.printStackTrace(); } } playersRequestingMapData.removeAll(copy); } } TickHandlerServer.tickCount++; if (TickHandlerServer.tickCount >= Long.MAX_VALUE) { TickHandlerServer.tickCount = 0; } EnergyNetwork.tickCount++; } else if (event.phase == Phase.END) { int maxPasses = 10; while (!TickHandlerServer.networkTicks.isEmpty()) { LinkedList<EnergyNetwork> pass = new LinkedList(); pass.addAll(TickHandlerServer.networkTicks); TickHandlerServer.networkTicks.clear(); for (EnergyNetwork grid : pass) { grid.tickEnd(); } if (--maxPasses <= 0) { break; } } maxPasses = 10; while (!TickHandlerServer.oxygenTransmitterUpdates.isEmpty()) { LinkedList<TileEntityOxygenTransmitter> pass = new LinkedList(); pass.addAll(TickHandlerServer.oxygenTransmitterUpdates); TickHandlerServer.oxygenTransmitterUpdates.clear(); for (TileEntityOxygenTransmitter newTile : pass) { if (!newTile.isInvalid()) newTile.refresh(); } if (--maxPasses <= 0) { break; } } maxPasses = 10; while (!TickHandlerServer.hydrogenTransmitterUpdates.isEmpty()) { LinkedList<TileEntityHydrogenPipe> pass = new LinkedList(); pass.addAll(TickHandlerServer.hydrogenTransmitterUpdates); TickHandlerServer.hydrogenTransmitterUpdates.clear(); for (TileEntityHydrogenPipe newTile : pass) { if (!newTile.isInvalid()) newTile.refresh(); } if (--maxPasses <= 0) { break; } } maxPasses = 10; while (!TickHandlerServer.energyTransmitterUpdates.isEmpty()) { LinkedList<TileBaseConductor> pass = new LinkedList(); pass.addAll(TickHandlerServer.energyTransmitterUpdates); TickHandlerServer.energyTransmitterUpdates.clear(); for (TileBaseConductor newTile : pass) { if (!newTile.isInvalid()) newTile.refresh(); } if (--maxPasses <= 0) { break; } } } }
/** * Complete the energy transfer. Called internally on server tick end. * * @return Amount of energy SENT to all acceptors */ private float doProduce() { float sent = 0.0F; if (!this.availableAcceptors.isEmpty()) { float energyNeeded = this.totalRequested; float energyAvailable = this.totalEnergy; float reducor = 1.0F; float energyStorageReducor = 1.0F; if (energyNeeded > energyAvailable) { // If not enough energy, try reducing what goes into energy storage (if any) energyNeeded -= this.totalStorageExcess; // If there's still not enough, put the minimum into energy storage (if any) and, anyhow, // reduce everything proportionately if (energyNeeded > energyAvailable) { energyStorageReducor = 0F; reducor = energyAvailable / energyNeeded; } else { // Energyavailable exceeds the total needed but only if storage does not fill all in one // go - this is a common situation energyStorageReducor = (energyAvailable - energyNeeded) / this.totalStorageExcess; } } float currentSending; float sentToAcceptor; int tierProduced = Math.min(this.producersTierGC, this.networkTierGC); TileEntity debugTE = null; try { for (TileEntity tileEntity : this.availableAcceptors) { debugTE = tileEntity; // Exit the loop if there is no energy left at all (should normally not happen, should be // some even for the last acceptor) if (sent >= energyAvailable) { break; } // The base case is to give each acceptor what it is requesting currentSending = this.energyRequests.get(tileEntity); // If it's an energy store, we may need to damp it down if energyStorageReducor is less // than 1 if (currentSending > EnergyNetwork.ENERGY_STORAGE_LEVEL) { currentSending = EnergyNetwork.ENERGY_STORAGE_LEVEL + (currentSending - EnergyNetwork.ENERGY_STORAGE_LEVEL) * energyStorageReducor; } // Reduce everything proportionately if there is not enough energy for all needs currentSending *= reducor; if (currentSending > energyAvailable - sent) { currentSending = energyAvailable - sent; } ForgeDirection sideFrom = this.availableconnectedDirections.get(tileEntity); if (tileEntity instanceof IElectrical) { sentToAcceptor = ((IElectrical) tileEntity) .receiveElectricity(sideFrom, currentSending, tierProduced, true); } else if (isRF2Loaded && tileEntity instanceof IEnergyReceiver) { final int currentSendinginRF = (currentSending >= Integer.MAX_VALUE / EnergyConfigHandler.TO_RF_RATIO) ? Integer.MAX_VALUE : (int) (currentSending * EnergyConfigHandler.TO_RF_RATIO); sentToAcceptor = ((IEnergyReceiver) tileEntity).receiveEnergy(sideFrom, currentSendinginRF, false) / EnergyConfigHandler.TO_RF_RATIO; } else if (isMekLoaded && tileEntity instanceof IStrictEnergyAcceptor) { sentToAcceptor = (float) ((IStrictEnergyAcceptor) tileEntity) .transferEnergyToAcceptor( sideFrom, currentSending * EnergyConfigHandler.TO_MEKANISM_RATIO) / EnergyConfigHandler.TO_MEKANISM_RATIO; } else if (isRF1Loaded && tileEntity instanceof IEnergyHandler) { final int currentSendinginRF = (currentSending >= Integer.MAX_VALUE / EnergyConfigHandler.TO_RF_RATIO) ? Integer.MAX_VALUE : (int) (currentSending * EnergyConfigHandler.TO_RF_RATIO); sentToAcceptor = ((IEnergyHandler) tileEntity).receiveEnergy(sideFrom, currentSendinginRF, false) / EnergyConfigHandler.TO_RF_RATIO; } else if (isIC2Loaded && tileEntity instanceof IEnergySink) { double energySendingIC2 = currentSending * EnergyConfigHandler.TO_IC2_RATIO; if (energySendingIC2 >= 1D) { double result = 0; try { if (EnergyUtil.voltageParameterIC2) { result = (Double) EnergyUtil.injectEnergyIC2.invoke( tileEntity, sideFrom, energySendingIC2, 120D); } else { result = (Double) EnergyUtil.injectEnergyIC2.invoke(tileEntity, sideFrom, energySendingIC2); } } catch (Exception ex) { if (ConfigManagerCore.enableDebug) { ex.printStackTrace(); } } sentToAcceptor = currentSending - (float) result / EnergyConfigHandler.TO_IC2_RATIO; if (sentToAcceptor < 0F) { sentToAcceptor = 0F; } } else { sentToAcceptor = 0F; } } else if (isBCLoaded && EnergyConfigHandler.getBuildcraftVersion() == 6 && MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, sideFrom) != null) // New BC API { sentToAcceptor = (float) MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, sideFrom) .addEnergy(currentSending * EnergyConfigHandler.TO_BC_RATIO) / EnergyConfigHandler.TO_BC_RATIO; } else if (isBCLoaded && tileEntity instanceof IPowerReceptor) // Legacy BC API { PowerReceiver receiver = ((IPowerReceptor) tileEntity).getPowerReceiver(sideFrom); if (receiver != null) { double toSendBC = Math.min( currentSending * EnergyConfigHandler.TO_BC_RATIO, receiver.powerRequest()); sentToAcceptor = (float) receiver.receiveEnergy( buildcraft.api.power.PowerHandler.Type.PIPE, toSendBC, sideFrom) / EnergyConfigHandler.TO_BC_RATIO; } else { sentToAcceptor = 0F; } } else { sentToAcceptor = 0F; } if (sentToAcceptor / currentSending > 1.002F && sentToAcceptor > 0.01F) { if (!this.spamstop) { FMLLog.info( "Energy network: acceptor took too much energy, offered " + currentSending + ", took " + sentToAcceptor + ". " + tileEntity.toString()); this.spamstop = true; } sentToAcceptor = currentSending; } sent += sentToAcceptor; } } catch (Exception e) { GCLog.severe("DEBUG Energy network loop issue, please report this"); if (debugTE != null) GCLog.severe( "Problem was likely caused by tile in dim " + debugTE.getWorldObj().provider.dimensionId + " at " + debugTE.xCoord + "," + debugTE.yCoord + "," + debugTE.zCoord + " Type:" + debugTE.getClass().getSimpleName()); } } if (EnergyNetwork.tickCount % 200 == 0) { this.spamstop = false; } float returnvalue = sent; if (returnvalue > this.totalEnergy) { returnvalue = this.totalEnergy; } if (returnvalue < 0F) { returnvalue = 0F; } return returnvalue; }
public boolean setFrequency() { if (!GalacticraftCore.isPlanetsLoaded) { return false; } 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); TileEntity tile = this.worldObj.getTileEntity(pos); if (tile instanceof IFuelDock) { IFuelDock dock = (IFuelDock) tile; try { TileEntity launchController = null; Class<?> controllerClass = Class.forName( "micdoodle8.mods.galacticraft.planets.mars.tile.TileEntityLaunchController"); for (ILandingPadAttachable connectedTile : dock.getConnectedTiles()) { try { controllerClass.cast(connectedTile); } catch (ClassCastException e) { continue; } launchController = (TileEntity) connectedTile; if (launchController != null) { TileEntity tile2 = launchController.getWorld().getTileEntity(launchController.getPos()); try { controllerClass.cast(tile2); } catch (ClassCastException e) { launchController = null; continue; } launchController = tile2; } if (launchController != null) { break; } } if (launchController != null) { Boolean b = (Boolean) controllerClass.getMethod("validFrequency").invoke(launchController); if (b != null && b) { int controllerFrequency = controllerClass.getField("destFrequency").getInt(launchController); boolean foundPad = this.setTarget(false, controllerFrequency); if (foundPad) { this.destinationFrequency = controllerFrequency; GCLog.debug( "Rocket under launch control: going to target frequency " + controllerFrequency); return true; } } } } catch (ClassCastException e) { } catch (Exception e) { e.printStackTrace(); } } } } } this.destinationFrequency = -1; return false; }