// Need for create world config from network packet public WorldConfig(DataInputStream stream, LocalWorld world) throws IOException { // General information this.WorldName = readStringFromStream(stream); this.WorldFog = stream.readInt(); this.WorldNightFog = stream.readInt(); this.WorldFogR = ((WorldFog & 0xFF0000) >> 16) / 255F; this.WorldFogG = ((WorldFog & 0xFF00) >> 8) / 255F; this.WorldFogB = (WorldFog & 0xFF) / 255F; this.WorldNightFogR = ((WorldNightFog & 0xFF0000) >> 16) / 255F; this.WorldNightFogG = ((WorldNightFog & 0xFF00) >> 8) / 255F; this.WorldNightFogB = (WorldNightFog & 0xFF) / 255F; // Custom biomes + ids int count = stream.readInt(); while (count-- > 0) { String name = readStringFromStream(stream); int id = stream.readInt(); world.AddBiome(name, id); this.CustomBiomes.add(name); this.CustomBiomeIds.put(name, id); } // BiomeConfigs this.biomeConfigs = new BiomeConfig[world.getMaxBiomesCount()]; count = stream.readInt(); while (count-- > 0) { int id = stream.readInt(); BiomeConfig config = new BiomeConfig(stream, this, world.getBiomeById(id)); this.biomeConfigs[id] = config; } }
@Override public void spawn(LocalWorld world, Random rand, boolean villageInChunk, int x, int z) { int y = rand.nextInt(maxAltitude - minAltitude) + minAltitude; for (int i = 0; i < 10; i++) { int cactusX = x + rand.nextInt(8) - rand.nextInt(8); int cactusBaseY = y + rand.nextInt(4) - rand.nextInt(4); int cactusZ = z + rand.nextInt(8) - rand.nextInt(8); // Check position if (!world.isEmpty(cactusX, cactusBaseY, cactusZ)) continue; // Check foundation LocalMaterialData foundationMaterial = world.getMaterial(cactusX, cactusBaseY - 1, cactusZ); if (!sourceBlocks.contains(foundationMaterial)) continue; // Check neighbors if (!world.isEmpty(cactusX - 1, cactusBaseY, cactusZ)) continue; if (!world.isEmpty(cactusX + 1, cactusBaseY, cactusZ)) continue; if (!world.isEmpty(cactusX, cactusBaseY, cactusZ + 1)) continue; if (!world.isEmpty(cactusX, cactusBaseY, cactusZ + 1)) continue; // Spawn cactus int cactusHeight = 1 + rand.nextInt(rand.nextInt(3) + 1); for (int dY = 0; dY < cactusHeight; dY++) { world.setBlock(cactusX, cactusBaseY + dY, cactusZ, material); } } }
@Override public void onPlayerLogin(EntityPlayer player) { // Server-side - called whenever a player logs in // I couldn't find a way to detect if the client has TerrainControl, // so for now the configs are sent anyway. // Get the config LocalWorld worldTC = WorldHelper.toLocalWorld(player.worldObj); if (worldTC == null) { // World not loaded return; } WorldConfig config = worldTC.getSettings(); // Serialize it ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutputStream stream = new DataOutputStream(outputStream); try { stream.writeInt(TCDefaultValues.ProtocolVersion.intValue()); config.Serialize(stream); } catch (IOException e) { e.printStackTrace(); } // Make the packet Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = TCDefaultValues.ChannelName.stringValue(); packet.data = outputStream.toByteArray(); packet.length = outputStream.size(); // Send the packet ((EntityPlayerMP) player).playerNetServerHandler.sendPacketToPlayer(packet); System.out.println("TerrainControl: sent config"); }
@Override public boolean onCommand(CommandSender sender, List<String> args) { Location location = this.getLocation(sender); int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); LocalWorld world = this.getWorld(sender, ""); if (world == null) { sender.sendMessage(ERROR_COLOR + "Plugin is not enabled for this world."); return true; } LocalBiome biome = world.getCalculatedBiome(x, z); BiomeIds biomeIds = biome.getIds(); sender.sendMessage( MESSAGE_COLOR + "According to the biome generator, you are in the " + VALUE_COLOR + biome.getName() + MESSAGE_COLOR + " biome, with id " + VALUE_COLOR + biomeIds.getGenerationId()); if (args.contains("-f")) { sender.sendMessage( MESSAGE_COLOR + "The base temperature of this biome is " + VALUE_COLOR + biome.getBiomeConfig().biomeTemperature + MESSAGE_COLOR + ", \nat your height it is " + VALUE_COLOR + biome.getTemperatureAt(x, y, z)); } if (args.contains("-s")) { LocalBiome savedBiome = world.getBiome(x, z); BiomeIds savedIds = savedBiome.getIds(); sender.sendMessage( MESSAGE_COLOR + "According to the world save files, you are in the " + VALUE_COLOR + savedBiome.getName() + MESSAGE_COLOR + " biome, with id " + VALUE_COLOR + savedIds.getSavedId()); } return true; }
@Override public LocalWorld getWorld(String name) { LocalWorld world = worldType.worldTC; if (world == null) { return null; } if (world.getName().equals(name)) { return world; } return null; }
// canSpawnStructureAtCoords @Override protected boolean a(int chunkX, int chunkZ) { Random rand = b; World worldMC = c; if (rand.nextInt(80) < Math.max(Math.abs(chunkX), Math.abs(chunkZ))) { LocalWorld world = WorldHelper.toLocalWorld(worldMC); LocalBiome biome = world.getBiome(chunkX * 16 + 8, chunkZ * 16 + 8); if (rand.nextDouble() * 100.0 < biome.getBiomeConfig().mineshaftsRarity) { return true; } } return false; }
public LayeredBiomeGenerator(LocalWorld world) { super(world); Layer[] layers = initLayers(); if (world.getConfigs().getWorldConfig().improvedRivers) defaultOutputType = OutputType.WITHOUT_RIVERS; this.unZoomedLayer = layers[0]; this.biomeLayer = layers[1]; }
@SubscribeEvent public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { // Server-side - called whenever a player logs in // I couldn't find a way to detect if the client has TerrainControl, // so for now the configs are sent anyway. // Get the config if (!(event.player instanceof EntityPlayerMP)) { return; } EntityPlayerMP player = (EntityPlayerMP) event.player; LocalWorld worldTC = worldLoader.getWorld(player.getEntityWorld()); if (worldTC == null) { // World not loaded return; } ConfigProvider configs = worldTC.getConfigs(); // Serialize it ByteBuf nettyBuffer = Unpooled.buffer(); PacketBuffer mojangBuffer = new PacketBuffer(nettyBuffer); DataOutput stream = new ByteBufOutputStream(nettyBuffer); try { stream.writeInt(PluginStandardValues.ProtocolVersion); ConfigToNetworkSender.send(configs, stream); } catch (IOException e) { TerrainControl.printStackTrace(LogMarker.FATAL, e); } // Make the packet SPacketCustomPayload packet = new SPacketCustomPayload(PluginStandardValues.ChannelName, mojangBuffer); // Send the packet player.connection.sendPacket(packet); }
@Override protected void spawnInChunk( LocalWorld world, Random random, boolean villageInChunk, ChunkCoordinate chunkCoord) { // Find all structures that reach this chunk, and spawn them int searchRadius = world.getConfigs().getWorldConfig().maximumCustomStructureRadius; int currentChunkX = chunkCoord.getChunkX(); int currentChunkZ = chunkCoord.getChunkZ(); for (int searchChunkX = currentChunkX - searchRadius; searchChunkX < currentChunkX + searchRadius; searchChunkX++) { for (int searchChunkZ = currentChunkZ - searchRadius; searchChunkZ < currentChunkZ + searchRadius; searchChunkZ++) { CustomObjectStructure structureStart = world.getStructureCache().getStructureStart(searchChunkX, searchChunkZ); if (structureStart != null) { structureStart.spawnForChunk(chunkCoord); } } } }
CustomObjectStructure(LocalWorld world, CustomObjectCoordinate start) { CustomObject object = start.getObject(); this.world = world; this.start = start; this.height = object.getStructurePartSpawnHeight(); this.maxBranchDepth = object.getMaxBranchDepth(); random = RandomHelper.getRandomForCoords(start.getX(), start.getY(), start.getZ(), world.getSeed()); // Calculate all branches and add them to a list objectsToSpawn = new LinkedHashMap<ChunkCoordinate, Set<CustomObjectCoordinate>>(); addToSpawnList(start); // Add the object itself addBranches(start, 1); }
/** * Returns the vein that starts in the chunk. * * <p> * * @param chunkX The x of the chunk. * @param chunkZ The z of the chunk. * @return The vein that starts in the chunk, or null if there is no starting vein. */ public Vein getVeinStartInChunk(LocalWorld world, int chunkX, int chunkZ) { // Create a random generator that is constant for this chunk and vein Random random = RandomHelper.getRandomForCoords( chunkX, chunkZ, material.hashCode() * (minRadius + maxRadius + 100) + world.getSeed()); if (random.nextDouble() * 100.0 < veinRarity) { int veinX = chunkX * 16 + random.nextInt(16) + 8; int veinY = MathHelper.getRandomNumberInRange(random, minAltitude, maxAltitude); int veinZ = chunkZ * 16 + random.nextInt(16) + 8; int veinSize = MathHelper.getRandomNumberInRange(random, minRadius, maxRadius); return new Vein(veinX, veinY, veinZ, veinSize); } return null; }
@Override public void spawn(LocalWorld world, Random rand, boolean villageInChunk, int x, int z) { int y = rand.nextInt(maxAltitude - minAltitude) + minAltitude; if (!sourceBlocks.contains(world.getMaterial(x, y + 1, z))) return; if (!sourceBlocks.contains(world.getMaterial(x, y - 1, z))) return; if (!world.isEmpty(x, y, z) && (!sourceBlocks.contains(world.getMaterial(x, y, z)))) return; int i = 0; int j = 0; LocalMaterialData tempBlock = world.getMaterial(x - 1, y, z); i = (sourceBlocks.contains(tempBlock)) ? i + 1 : i; j = (tempBlock.isMaterial(DefaultMaterial.AIR)) ? j + 1 : j; tempBlock = world.getMaterial(x + 1, y, z); i = (sourceBlocks.contains(tempBlock)) ? i + 1 : i; j = (tempBlock.isMaterial(DefaultMaterial.AIR)) ? j + 1 : j; tempBlock = world.getMaterial(x, y, z - 1); i = (sourceBlocks.contains(tempBlock)) ? i + 1 : i; j = (tempBlock.isMaterial(DefaultMaterial.AIR)) ? j + 1 : j; tempBlock = world.getMaterial(x, y, z + 1); i = (sourceBlocks.contains(tempBlock)) ? i + 1 : i; j = (tempBlock.isMaterial(DefaultMaterial.AIR)) ? j + 1 : j; if ((i == 3) && (j == 1)) { world.setBlock(x, y, z, material); } }
/** * Spawns this block at the position. The saved x, y and z in this block are ignored. * * <p> * * @param world The world to spawn in. * @param random The random number generator. * @param x The absolute x to spawn. The x-position in this object is ignored. * @param y The absolute y to spawn. The y-position in this object is ignored. * @param z The absolute z to spawn. The z-position in this object is ignored. */ public void spawn(LocalWorld world, Random random, int x, int y, int z) { world.setBlock(x, y, z, material); if (hasMetaData) { world.attachMetadata(x, y, z, metaDataTag); } }
@Override public void spawn(LocalWorld world, Random random, boolean villageInChunk, int x, int z) { int y = RandomHelper.numberInRange(random, minAltitude, maxAltitude); world.placeDungeon(random, x, y, z); }
// Need for create world config from network packet public WorldConfig(DataInputStream stream, LocalWorld world) throws IOException { // Protocol version int protocolVersion = stream.readInt(); if (protocolVersion != TCDefaultValues.ProtocolVersion.intValue()) throw new IOException("Wrong TC protocol version"); this.WorldName = ReadStringFromStream(stream); this.GenerationDepth = stream.readInt(); this.BiomeRarityScale = stream.readInt(); this.LandRarity = stream.readInt(); this.LandSize = stream.readInt(); this.LandFuzzy = stream.readInt(); this.IceRarity = stream.readInt(); this.IceSize = stream.readInt(); this.FrozenOcean = stream.readBoolean(); this.FrozenRivers = stream.readBoolean(); this.RiverRarity = stream.readInt(); this.RiverSize = stream.readInt(); this.RiversEnabled = stream.readBoolean(); this.oldBiomeSize = stream.readDouble(); this.minTemperature = stream.readFloat(); this.maxTemperature = stream.readFloat(); this.minMoisture = stream.readFloat(); this.maxMoisture = stream.readFloat(); this.WorldFog = stream.readInt(); this.WorldNightFog = stream.readInt(); this.WorldFogR = ((WorldFog & 0xFF0000) >> 16) / 255F; this.WorldFogG = ((WorldFog & 0xFF00) >> 8) / 255F; this.WorldFogB = (WorldFog & 0xFF) / 255F; this.WorldNightFogR = ((WorldNightFog & 0xFF0000) >> 16) / 255F; this.WorldNightFogG = ((WorldNightFog & 0xFF00) >> 8) / 255F; this.WorldNightFogB = (WorldNightFog & 0xFF) / 255F; int count = stream.readInt(); while (count-- > 0) { String name = ReadStringFromStream(stream); int id = stream.readInt(); world.AddBiome(name, id); this.CustomBiomes.add(name); this.CustomBiomeIds.put(name, id); } this.biomeConfigs = new BiomeConfig[world.getMaxBiomesCount()]; count = stream.readInt(); while (count-- > 0) { int id = stream.readInt(); BiomeConfig config = new BiomeConfig(stream, this, world.getBiomeById(id)); this.biomeConfigs[id] = config; } count = stream.readInt(); String name; while (count-- > 0) { name = ReadStringFromStream(stream); this.NormalBiomes.add(name); } count = stream.readInt(); while (count-- > 0) { name = ReadStringFromStream(stream); this.IceBiomes.add(name); } count = stream.readInt(); while (count-- > 0) { name = ReadStringFromStream(stream); this.IsleBiomes.add(name); } count = stream.readInt(); while (count-- > 0) { name = ReadStringFromStream(stream); this.BorderBiomes.add(name); } for (BiomeConfig biomeConfig : this.biomeConfigs) if (biomeConfig != null && biomeConfig.Biome.isCustom()) biomeConfig.Biome.setCustom(biomeConfig); }
public WorldConfig(File settingsDir, LocalWorld world, boolean checkOnly) { this.SettingsDir = settingsDir; this.WorldName = world.getName(); File settingsFile = new File(this.SettingsDir, TCDefaultValues.WorldSettingsName.stringValue()); this.ReadSettingsFile(settingsFile); this.RenameOldSettings(); this.ReadConfigSettings(); this.CorrectSettings(); ReadWorldCustomObjects(); // Check biome ids for (String biomeName : CustomBiomes) if (CustomBiomeIds.get(biomeName) == -1) CustomBiomeIds.put(biomeName, world.getFreeBiomeId()); // Need add check to clashes if (this.SettingsMode != ConfigMode.WriteDisable) this.WriteSettingsFile(settingsFile, (this.SettingsMode == ConfigMode.WriteAll)); world.setHeightBits(this.worldHeightBits); File BiomeFolder = new File(SettingsDir, TCDefaultValues.WorldBiomeConfigDirectoryName.stringValue()); if (!BiomeFolder.exists()) { if (!BiomeFolder.mkdir()) { System.out.println( "TerrainControl: error create biome configs directory, working with defaults"); return; } } ArrayList<LocalBiome> localBiomes = new ArrayList<LocalBiome>(world.getDefaultBiomes()); // Add custom biomes to world for (String biomeName : this.CustomBiomes) { if (checkOnly) localBiomes.add(world.getNullBiome(biomeName)); else localBiomes.add(world.AddBiome(biomeName, this.CustomBiomeIds.get(biomeName))); } // Build biome replace matrix for (int i = 0; i < this.ReplaceMatrixBiomes.length; i++) this.ReplaceMatrixBiomes[i] = (byte) i; this.biomeConfigs = new BiomeConfig[world.getMaxBiomesCount()]; String LoadedBiomeNames = ""; for (LocalBiome localBiome : localBiomes) { BiomeConfig config = new BiomeConfig(BiomeFolder, localBiome, this); if (checkOnly) continue; if (!config.ReplaceBiomeName.equals("")) { this.HaveBiomeReplace = true; this.ReplaceMatrixBiomes[config.Biome.getId()] = (byte) world.getBiomeIdByName(config.ReplaceBiomeName); } if (this.NormalBiomes.contains(config.Name)) this.normalBiomesRarity += config.BiomeRarity; if (this.IceBiomes.contains(config.Name)) this.iceBiomesRarity += config.BiomeRarity; this.biomeConfigs[localBiome.getId()] = config; if (!this.BiomeConfigsHaveReplacement) this.BiomeConfigsHaveReplacement = config.ReplaceCount > 0; if (this.biomes.size() != 0) LoadedBiomeNames += ", "; LoadedBiomeNames += localBiome.getName(); this.biomes.add(config); if (this.ModeBiome == BiomeMode.FromImage) { if (this.biomeColorMap == null) this.biomeColorMap = new HashMap<Integer, Integer>(); try { int color = Integer.decode(config.BiomeColor); if (color <= 0xFFFFFF) this.biomeColorMap.put(color, config.Biome.getId()); } catch (NumberFormatException ex) { System.out.println("TerrainControl: wrong color in " + config.Biome.getName()); } } } System.out.println("TerrainControl: Loaded biomes - " + LoadedBiomeNames); }