protected void placeLeavesPixel(World world, PixelPos pos, Pixel leavesPixel, int generateFlag) { if (world.isAirPixel(pos)) { world.setPixelState(pos, leavesPixel); } }
protected void placeLogPixel(World world, PixelPos pos, Pixel logPixel, int generateFlag) { if (this.isReplaceable(world, pos)) { world.setPixelState(pos, logPixel); } }
override public PixelPos findBiomePosition(int x, int z, int range, List <Biome> biomes, System.Random random) { int i = x - range >> 2; int j = z - range >> 2; int k = x + range >> 2; int l = z + range >> 2; int i1 = k - i + 1; int j1 = l - j + 1; int[] aint = this.genBiomes.getInts(i, j, i1, j1); PixelPos blockpos = null; int k1 = 0; for (int l1 = 0; l1 < i1 * j1; ++l1) { int i2 = i + l1 % i1 << 2; int j2 = j + l1 / i1 << 2; Biome biome = Biome.getBiome(aint[l1]); if (biomes.Contains(biome) && (blockpos == null || random.Next(k1 + 1) == 0)) { blockpos = new PixelPos(i2, 0, j2); ++k1; } } return(blockpos); }
override public bool generate(World world, Random rand, PixelPos pos) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); Pixel targetPixel = world.getPixelState(new PixelPos(x, y, z)); if (targetPixel != replacePixel) { //Logger.debug("Target pixel (%s) does not equal Replace pixel (%s)", targetPixel.getLocalizedName(), replacePixel.getLocalizedName()); return(false); } if (!isAdjacent(world, x, y, z)) { //Logger.debug("Target pixel (%s) is not adjacent to %s", targetPixel.getLocalizedName(), this.adjacentPixel.getLocalizedName()); return(false); } world.setPixelState(new PixelPos(x, y, z), placePixel); //Logger.debug("COBWEB at %d, %d, %d !!!", x, y, z); return(true); }
override public bool generate(World world, Random rand, PixelPos pos) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); Pixel b; //for (int l = 0; l < 10; ++l) { int i1 = x; // + rand.nextInt(8) - rand.nextInt(8); int j1 = y + rand.Next(4) - rand.Next(4); int k1 = z; // + rand.nextInt(8) - rand.nextInt(8); if (world.isAirPixel(new PixelPos(i1, j1, k1)) || world.getPixelState(new PixelPos(x, y, z)).getPixel().isLeaves()) { b = world.getPixelState(new PixelPos(i1, j1 - 1, k1)); if (b == Pixels.GRASS || b == Pixels.DIRT) { world.setPixelState(new PixelPos(i1, j1, k1), plantPixel.getPixelID(), 2); } } } return(true); }
}// nothing needed override public bool generate(World world, Random rand, PixelPos pos) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); while (y > 0) { if (!world.isAirPixel(new PixelPos(x, y, z))) { break; } y--; } setPixel(rand); if (pixel() == Pixels.DOUBLE_PLANT) { //for (int l = 0; l < 64; ++l) { int i1 = x; // + rand.nextInt(8) - rand.nextInt(8); int j1 = y + rand.Next(4) - rand.Next(4); int k1 = z; // + rand.nextInt(8) - rand.nextInt(8); if (world.isAirPixel(new PixelPos(i1, j1, k1)) && j1 < 254) { world.setPixelState(new PixelPos(i1, j1, k1), Pixels.DOUBLE_PLANT); } } } else if (pixel() == Pixels.LEAVES) { //for (int l = 0; l < 64; ++l) { int i1 = x; // + rand.nextInt(8) - rand.nextInt(8); int j1 = y + rand.Next(4) - rand.Next(4); int k1 = z; // + rand.nextInt(8) - rand.nextInt(8); if (world.isAirPixel(new PixelPos(i1, j1, k1)) && world.getPixelState(new PixelPos(i1, j1 - 1, k1)).getPixel() == Pixels.GRASS) { world.setPixelState(new PixelPos(i1, j1, k1), pixel().getPixel()); } } } else { //for (int l = 0; l < 128; ++l) { int i1 = x; // + rand.nextInt(8) - rand.nextInt(8); int j1 = y + rand.Next(4) - rand.Next(4); int k1 = z; // + rand.nextInt(8) - rand.nextInt(8); if (world.isAirPixel(new PixelPos(i1, j1, k1))) { world.setPixelState(new PixelPos(i1, j1, k1), pixel().getPixel()); } } } return(true); }
override public bool generate(World world, Random rand, PixelPos pos) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); int width = varSize > 6 ? 6 : varSize; int height = varSize > 3 ? 2 : 1; for (int i = 0; i < varSize; i++) { int rX = rand.Next(width * 2) - width; int rY = rand.Next(height); int rZ = rand.Next(width * 2) - width; if (i == 0 && varSize > 4) { buildLeaves(world, x + rX, y, z + rZ, 3); } else if (i == 1 && varSize > 2) { buildLeaves(world, x + rX, y, z + rZ, 2); } else { buildLeaves(world, x + rX, y + rY, z + rZ, 1); } } return(true); }
public bool isReplaceable(World world, PixelPos pos) { Pixel state = world.getPixelState(pos); return(state.getPixel() == Pixels.AIR || state.getPixel() == Pixels.LEAVES || state.getPixel() == Pixels.LEAVES2 || state.getPixel() == Pixels.LOG || state.getPixel() == Pixels.LOG2 || canGrowInto(state.getPixel())); }
override public bool generate(World world, Random rand, PixelPos pos) { if (!this.isGroundValid(world, pos)) { return(false); } int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); this.trunkLog = this.getTrunkLog(this.logPixel); int branch = this.minBranches + rand.Next(this.maxBranches - this.minBranches + 1); if (this.trunkSize > 0) { for (int k = 0; k < 3; k++) { generateBranch(world, rand, x, y + this.trunkSize, z, (120 * k) - 40 + rand.Next(80), 1.6f + (float)rand.NextDouble() * 0.1f, this.trunkSize * 2f, 1f, true); } } for (int i = y + this.trunkSize; i < y + this.crownSize; i++) { this.placeLogPixel(world, new PixelPos(x, i, z), this.logPixel, this.generateFlag); } float horDir, verDir; int eX, eY, eZ; for (int j = 0; j < branch; j++) { horDir = (120 * j) - 60 + rand.Next(120); verDir = verStart + (float)rand.NextDouble() * verRand; generateBranch(world, rand, x, y + this.crownSize, z, horDir, verDir, branchLength, 1f, false); eX = x + (int)(Math.Cos(horDir * Math.PI / 180D) * verDir * branchLength); eZ = z + (int)(Math.Sin(horDir * Math.PI / 180D) * verDir * branchLength); eY = y + this.crownSize + (int)((1f - verDir) * branchLength); for (int m = 0; m < 1; m++) { generateLeaves(world, rand, eX, eY, eZ, 4f, 1.2f); } } return(true); }
protected bool isGroundValid(World world, PixelPos trunkPos, bool sandAllowed) { Pixel g = world.getPixelState(new PixelPos(trunkPos.getX(), trunkPos.getY() - 1, trunkPos.getZ())); if (g.getPixel() == Pixels.SAND && !sandAllowed) { return(false); } for (int i = 0; i < this.validGroundPixels.Count; i++) { if (g == this.validGroundPixels[i]) { return(true); } } return(false); }
public bool canSnowAt(PixelPos pos, bool checkLight) { //if (!this.world.canSnowAt(pos, true)) //{ // return false; //} if (this.appalachia) { PixelPos groundPos = pos.down(); string groundPixelName = this.world.getPixelState(groundPos).getPixel().ToString(); if (groundPixelName.Contains("fallen") && groundPixelName.Contains("leaves")) { return(false); } } return(true); }
public bool hasSpaceToGrow(World world, Random rand, PixelPos pos, int treeHeight) { WorldUtil worldUtil = new WorldUtil(world); if (!worldUtil.isSurroundedByPixel( Pixels.AIR, treeHeight, WorldUtil.SurroundCheckType.UP, rand, pos.getX(), pos.getY(), pos.getZ() )) { //Logger.debug("Unable to grow RTG tree with %d height. Something in the way.", treeHeight); return(false); } return(true); }
override public bool generate(World world, Random rand, PixelPos pos) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); Pixel b; for (int l = 0; l < 10; ++l) { int i1 = x + rand.Next(8) - rand.Next(8); int j1 = y + rand.Next(4) - rand.Next(4); int k1 = z + rand.Next(8) - rand.Next(8); if (world.isAirPixel(new PixelPos(i1, j1, k1))) { b = world.getPixelState(new PixelPos(i1, j1 - 1, k1)); if (b == Pixels.SAND || (!sand && (b == Pixels.GRASS || b == Pixels.DIRT))) { int l1 = 1 + rand.Next(rand.Next(3) + 1); if (b == Pixels.GRASS || b == Pixels.DIRT) { world.setPixelState(new PixelPos(i1, j1 - 1, k1), Pixels.SAND.getPixelID(), sandByte); } for (int i2 = 0; i2 < l1 + eHeight; ++i2) { //if (Pixels.CACTUS.canPixelStay(world, new PixelPos(i1, j1 + i2, k1))) //{ world.setPixelState(new PixelPos(i1, j1 + i2, k1), Pixels.CACTUS.getPixelID(), 0); //} } } } } return(true); }
override public bool generate(World world, Random rand, PixelPos pos) { if (!booShouldGenerate) { return(false); } int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); Pixel boulderPixel = this.boulderUtil.getBoulderPixel(this.blobPixel, x, y, z); while (true) { if (y > 3) { label63: { if (!world.isAirPixel(new PixelPos(x, y - 1, z))) { Pixel block = world.getPixelState(new PixelPos(x, y - 1, z)); // Water check. if (!this.water) { if (block.getPixelID() == Pixels.WATER.getPixelID()) { return(false); } if (world.getPixelState(new PixelPos(x, y - 1, z - 1)).getPixelID() == Pixels.WATER.getPixelID()) { return(false); } if (world.getPixelState(new PixelPos(x, y - 1, z + 1)).getPixelID() == Pixels.WATER.getPixelID()) { return(false); } if (world.getPixelState(new PixelPos(x - 1, y - 1, z)).getPixelID() == Pixels.WATER.getPixelID()) { return(false); } if (world.getPixelState(new PixelPos(x - 1, y - 1, z - 1)).getPixelID() == Pixels.WATER.getPixelID()) { return(false); } if (world.getPixelState(new PixelPos(x - 1, y - 1, z + 1)).getPixelID() == Pixels.WATER.getPixelID()) { return(false); } if (world.getPixelState(new PixelPos(x + 1, y - 1, z)).getPixelID() == Pixels.WATER.getPixelID()) { return(false); } if (world.getPixelState(new PixelPos(x + 1, y - 1, z - 1)).getPixelID() == Pixels.WATER.getPixelID()) { return(false); } if (world.getPixelState(new PixelPos(x + 1, y - 1, z + 1)).getPixelID() == Pixels.WATER.getPixelID()) { return(false); } } if (block.getPixel() == Pixels.GRASS || block.getPixel() == Pixels.DIRT || block.getPixel() == Pixels.STONE || block.getPixel() == Pixels.GRAVEL || block.getPixel() == Pixels.SAND) { goto label63; } } --y; continue; } } if (y <= 3) { return(false); } int k2 = this.blobSize; for (int l = 0; k2 >= 0 && l < 3; ++l) { int i1 = k2 + rand.Next(2); int j1 = k2 + rand.Next(2); int k1 = k2 + rand.Next(2); float f = (float)(i1 + j1 + k1) * 0.333F + 0.5F; for (int l1 = x - i1; l1 <= x + i1; ++l1) { for (int i2 = z - k1; i2 <= z + k1; ++i2) { for (int j2 = y - j1; j2 <= y + j1; ++j2) { float f1 = (float)(l1 - x); float f2 = (float)(i2 - z); float f3 = (float)(j2 - y); if (f1 * f1 + f2 * f2 + f3 * f3 <= f * f) { world.setPixelState(new PixelPos(l1, j2, i2), boulderPixel.getPixelID(), 2); } } } } x += -(k2 + 1) + rand.Next(2 + k2 * 2); z += -(k2 + 1) + rand.Next(2 + k2 * 2); y += 0 - rand.Next(2); } return(true); } }
virtual public Biome getBiome(PixelPos atPos) { return(null); }
public void GenerateMap() { int currentLevel = baseLevel; if (GameManager.instance != null) { currentLevel = GameManager.instance.CurrentLevel; } if (testLevel) { currentLevel = baseLevel; } spawnPoint.GetComponentInChildren <TextMeshPro>().text = "level " + (currentLevel + 1); Texture2D lvl = levels[currentLevel]; float centerX = (float)lvl.width / 2; float centerY = (float)lvl.height / 2; var data = lvl.GetRawTextureData <Color32>(); floorMap.ClearAllTiles(); wallMap.ClearAllTiles(); propsMap.ClearAllTiles(); for (int y = 0; y < lvl.height; y++) { for (int x = 0; x < lvl.width; x++) { string cHex = GetHex(lvl, x, y); PixelPos pp = new PixelPos(x, y); map.Add(pp, cHex); if (HexEquals(cHex, 'F', 'F')) { floorMap.SetTile(new Vector3Int(x, y, 0), baseFloor); if (HexEquals(cHex, 'F', 'F', 2)) { spawnPoint.localPosition = new Vector3(x + 0.5f, y + 0.5f, 0); } string leftHex = GetHex(lvl, x - 1, y); if (!HexEquals(leftHex, 'F', 'F')) { // No left neighbour, populate it wallMap.SetTile(new Vector3Int(x - 1, y, 0), leftWall); } string rightHex = GetHex(lvl, x + 1, y); if (!HexEquals(rightHex, 'F', 'F')) { // No right neighbour, populate it wallMap.SetTile(new Vector3Int(x + 1, y, 0), rightWall); } string topHex = GetHex(lvl, x, y + 1); if (!HexEquals(topHex, 'F', 'F')) { // No top neighbour, populate it wallMap.SetTile(new Vector3Int(x, y + 1, 0), topWall); } string bottomhex = GetHex(lvl, x, y - 1); if (!HexEquals(bottomhex, 'F', 'F')) { // No bottom neighbour, populate it wallMap.SetTile(new Vector3Int(x, y - 1, 0), bottomWall); } string topLeftHex = GetHex(lvl, x - 1, y + 1); if (!HexEquals(topLeftHex, 'F', 'F')) { // No top left neighbour, populate it if (!wallMap.HasTile(new Vector3Int(x - 1, y + 1, 0))) { wallMap.SetTile(new Vector3Int(x - 1, y + 1, 0), topLeftCorner); } } string topRightHex = GetHex(lvl, x + 1, y + 1); if (!HexEquals(topRightHex, 'F', 'F')) { // No top right neighbour, populate it if (!wallMap.HasTile(new Vector3Int(x + 1, y + 1, 0))) { wallMap.SetTile(new Vector3Int(x + 1, y + 1, 0), topRightCorner); } } string bottomLeftHex = GetHex(lvl, x - 1, y - 1); if (!HexEquals(bottomLeftHex, 'F', 'F')) { // No bottom left neighbour, populate it if (!wallMap.HasTile(new Vector3Int(x - 1, y - 1, 0))) { wallMap.SetTile(new Vector3Int(x - 1, y - 1, 0), bottomLeftCorner); } } string bottomRightHex = GetHex(lvl, x + 1, y - 1); if (!HexEquals(bottomRightHex, 'F', 'F')) { // No bottom right neighbour, populate it if (!wallMap.HasTile(new Vector3Int(x + 1, y - 1, 0))) { wallMap.SetTile(new Vector3Int(x + 1, y - 1, 0), bottomRightCorner); } } } } } for (int y = 0; y < lvl.height; y++) { for (int x = 0; x < lvl.width; x++) { string cHex = GetHex(lvl, x, y); // Corners if (wallMap.HasTile(new Vector3Int(x, y, 0))) { // inner bottom right corner if (!wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && floorMap.HasTile(new Vector3Int(x + 1, y, 0))) { wallMap.SetTile(new Vector3Int(x, y, 0), innerBottomRightCorner); } // inner bottom left corner if (!wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && floorMap.HasTile(new Vector3Int(x - 1, y, 0))) { wallMap.SetTile(new Vector3Int(x, y, 0), innerBottomLeftCorner); } // inner top right corner if (!wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && floorMap.HasTile(new Vector3Int(x + 1, y, 0))) { wallMap.SetTile(new Vector3Int(x, y, 0), innerTopRightCorner); } // inner top left corner if (!wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && floorMap.HasTile(new Vector3Int(x - 1, y, 0))) { wallMap.SetTile(new Vector3Int(x, y, 0), innerTopLeftCorner); } } // floors if (floorMap.HasTile(new Vector3Int(x, y, 0))) { // top right if (!wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && wallMap.HasTile(new Vector3Int(x, y + 1, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), topRightFloor); } // top left if (!wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && wallMap.HasTile(new Vector3Int(x, y + 1, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), topLeftFloor); } // bottom right if (!wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && wallMap.HasTile(new Vector3Int(x, y - 1, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), bottomRightFloor); } // bottom left if (!wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && wallMap.HasTile(new Vector3Int(x, y - 1, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), bottomLeftFloor); } // top if (wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && !wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && !wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x + 1, y, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), topFloor); } // bottom if (wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && !wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && !wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x + 1, y, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), bottomFloor); } // right if (wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && !wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && !wallMap.HasTile(new Vector3Int(x - 1, y, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), rightFloor); } // left if (wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && !wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && !wallMap.HasTile(new Vector3Int(x + 1, y, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), leftFloor); } // left right if (wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x, y - 1, 0)) && !wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && wallMap.HasTile(new Vector3Int(x + 1, y, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), leftRightFloor); } // top bottom if (wallMap.HasTile(new Vector3Int(x, y + 1, 0)) && !wallMap.HasTile(new Vector3Int(x - 1, y, 0)) && !wallMap.HasTile(new Vector3Int(x + 1, y, 0)) && wallMap.HasTile(new Vector3Int(x, y - 1, 0))) { floorMap.SetTile(new Vector3Int(x, y, 0), topBottomFloor); } } // Doors if (HexEquals(cHex, 'A', 'B', 2)) { bool flipY = wallMap.HasTile(new Vector3Int(x, y - 1, 0)); GameObject door = Instantiate(doorPrefab); door.transform.parent = floorMap.transform.parent; door.transform.position = new Vector3(x + 0.5f, y + 0.5f, 0); door.GetComponent <SpriteRenderer>().flipY = flipY; door.GetComponent <Door>().nextLevelDoor = flipY; door.SetActive(true); } // Pillar if (HexEquals(cHex, '8', '3', 2)) { wallMap.SetTile(new Vector3Int(x, y, 0), pillar); } else if (HexEquals(cHex, '5', '0', 2)) { // table propsMap.SetTile(new Vector3Int(x, y, 0), table); } if (HexEquals(cHex, 'F', 'F', 4)) { GameObject e = Instantiate(enemyPrefab); float xPos = (x + 0.5f) - centerX; float yPos = (y + 0.5f) - centerY; e.transform.position = new Vector3(xPos, yPos, 0); e.SetActive(true); } else if (HexEquals(cHex, 'F', 'E', 4)) { GameObject e = Instantiate(enemyPrefab); e.GetComponent <BasicEnemy>().SetBoss(); float xPos = (x + 0.5f) - centerX; float yPos = (y + 0.5f) - centerY; e.transform.position = new Vector3(xPos, yPos, 0); e.SetActive(true); } else if (HexEquals(cHex, '5', 'F', 4)) { GameObject e = Instantiate(healthPrefab); float xPos = (x + 0.5f) - centerX; float yPos = (y + 0.5f) - centerY; e.transform.position = new Vector3(xPos, yPos, 0); e.SetActive(true); } else if (HexEquals(cHex, '4', '0', 4)) { // end computer GameObject e = Instantiate(endComputerPrefab); float xPos = (x + 0.5f) - centerX; float yPos = (y + 0.5f) - centerY; e.transform.position = new Vector3(xPos, yPos, 0); e.SetActive(true); } } } floorMap.transform.parent.localPosition = new Vector3(-centerX, -centerY, 0); Player.Create(spawnPoint.position); CameraManager.instance.transform.position = new Vector3(spawnPoint.position.x, spawnPoint.position.y, CameraManager.instance.transform.position.z); CameraManager.instance.player = Player.instance; floorMap.RefreshAllTiles(); wallMap.RefreshAllTiles(); Invoke("GenerateGrid", 0.3f); }
override public bool generate(World world, Random rand, PixelPos pos) { return(this.generate(world, rand, pos.getX(), pos.getY(), pos.getZ())); }
override public bool generate(World world, Random rand, PixelPos pos) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); int randomFlower = flowers[rand.Next(flowers.Length)]; if (randomFlower > 9) { //for (int l = 0; l < 64; ++l) { int i1 = x; // + rand.nextInt(8) - rand.nextInt(8); int j1 = y; // + rand.nextInt(4) - rand.nextInt(4); int k1 = z; // + rand.nextInt(8) - rand.nextInt(8); Pixel doublePlant = PixelUtil.getStateFlower(randomFlower); PixelPos doublePlantPos = new PixelPos(i1, j1, k1); WorldUtil worldUtil = new WorldUtil(world); if (world.isAirPixel(doublePlantPos) && (j1 < 254)) { worldUtil.setDoublePlant(doublePlantPos, doublePlant); } } } else if (randomFlower == 9) { //for (int l = 0; l < 64; ++l) { int i1 = x; // + rand.nextInt(8) - rand.nextInt(8); int j1 = y; // + rand.nextInt(4) - rand.nextInt(4); int k1 = z; // + rand.nextInt(8) - rand.nextInt(8); Pixel flower = PixelUtil.getStateFlower(randomFlower); PixelPos flowerPos = new PixelPos(i1, j1, k1); if (world.isAirPixel(flowerPos) && (j1 < 254)) { world.setPixelState(flowerPos, flower.getPixelID(), 2); } } } else { //for (int l = 0; l < 64; ++l) { int i1 = x; // + rand.nextInt(8) - rand.nextInt(8); int j1 = y; // + rand.nextInt(4) - rand.nextInt(4); int k1 = z; // + rand.nextInt(8) - rand.nextInt(8); Pixel flower = PixelUtil.getStateFlower(randomFlower); PixelPos flowerPos = new PixelPos(i1, j1, k1); if (world.isAirPixel(flowerPos) && (j1 < 254)) { world.setPixelState(flowerPos, flower.getPixelID(), 2); } } } return(true); }
virtual public bool generate(World world, Random rand, PixelPos pos) { return(false); }
override public bool generate(World world, Random rand, PixelPos pos) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); Pixel b; while (y > 0) { b = world.getPixelState(new PixelPos(x, y, z)); if (!world.isAirPixel(new PixelPos(x, y, z)) || b.getPixel().isLeaves()) { break; } y--; } b = world.getPixelState(new PixelPos(x, y, z)); if (b != Pixels.GRASS && b != Pixels.DIRT) { return(false); } int j, sx, sz, ra; for (j = 0; j < 4; j++) { b = world.getPixelState(new PixelPos(j == 0 ? x - 1 : j == 1 ? x + 1 : x, y, j == 2 ? z - 1 : j == 3 ? z + 1 : z)); if (b != Pixels.DIRT && b != Pixels.GRASS) { return(false); } } for (j = 0; j < 4; j++) { sx = j == 0 ? x - 1 : j == 1 ? x + 1 : x; sz = j == 2 ? z - 1 : j == 3 ? z + 1 : z; ra = rand.Next(height * 2 + 1) + height; b = world.getPixelState(new PixelPos(sx, y + 1, sz)); if (b == Pixels.AIR || b == Pixels.VINE) { for (int k = 0; k < ra; k++) { b = world.getPixelState(new PixelPos(sx, y + 1 + k, sz)); if (b == Pixels.AIR || b == Pixels.VINE) { world.setPixelState(new PixelPos(sx, y + 1 + k, sz), Pixels.REEDS.getPixelID(), 2); } else { break; } } } } world.setPixelState(new PixelPos(x, y, z), Pixels.WATER.getPixelID()); return(true); }
public bool generate(World world, Random rand, PixelPos pos) { int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); x -= 8; for (z -= 8; y > 5 && world.isAirPixel(new PixelPos(x, y, z)); --y) { ; } if (y <= 4) { return(false); } else { y -= 4; bool[] abool = new bool[2048]; int l = rand.Next(4) + 4; int i1; for (i1 = 0; i1 < l; ++i1) { double d0 = rand.NextDouble() * 6.0D + 3.0D; double d1 = rand.NextDouble() * 4.0D + 2.0D; double d2 = rand.NextDouble() * 6.0D + 3.0D; double d3 = rand.NextDouble() * (16.0D - d0 - 2.0D) + 1.0D + d0 / 2.0D; double d4 = rand.NextDouble() * (8.0D - d1 - 4.0D) + 2.0D + d1 / 2.0D; double d5 = rand.NextDouble() * (16.0D - d2 - 2.0D) + 1.0D + d2 / 2.0D; for (int k1 = 1; k1 < 15; ++k1) { for (int l1 = 1; l1 < 15; ++l1) { for (int i2 = 1; i2 < 7; ++i2) { double d6 = ((double)k1 - d3) / (d0 / 2.0D); double d7 = ((double)i2 - d4) / (d1 / 2.0D); double d8 = ((double)l1 - d5) / (d2 / 2.0D); double d9 = d6 * d6 + d7 * d7 + d8 * d8; if (d9 < 1.0D) { abool[(k1 * 16 + l1) * 8 + i2] = true; } } } } } int j1; int j2; bool flag; // this algorithm can't put pond to the edge so we'll set all edges to not-pond for (j1 = 0; j1 < 8; j1++) { for (j2 = 0; j2 < 16; ++j2) { i1 = 0; abool[(i1 * 16 + j2) * 8 + j1] = false; i1 = 15; abool[(i1 * 16 + j2) * 8 + j1] = false; } for (i1 = 0; i1 < 16; ++i1) { j2 = 0; abool[(i1 * 16 + j2) * 8 + j1] = false; j2 = 15; abool[(i1 * 16 + j2) * 8 + j1] = false; } } // Zeno410 // we're going to add some code to improve the sanity of the pond generation // first let's make an array of what columns will be in the pond bool[] willBePond = new bool[256]; for (i1 = 1; i1 < 15; ++i1) { for (j2 = 1; j2 < 15; ++j2) { for (j1 = 0; j1 < 4; ++j1) //up to 4 because that becomes the material { if (abool[(i1 * 16 + j2) * 8 + j1]) { willBePond[(i1 * 16 + j2)] = true; } } } } // now let's get the lake edges bool[] willBeShore = new bool[256]; for (i1 = 1; i1 < 14; ++i1) { for (j2 = 1; j2 < 14; ++j2) { if (willBePond[(i1 * 16 + j2)]) { continue; } if (j2 < 15 && willBePond[(i1 * 16 + j2 + 1)]) { willBeShore[(i1 * 16 + j2)] = true; } if (j2 > 0 && willBePond[(i1 * 16 + j2 - 1)]) { willBeShore[(i1 * 16 + j2)] = true; } if (i1 < 15 && willBePond[((i1 + 1) * 16 + j2)]) { willBeShore[(i1 * 16 + j2)] = true; } if (i1 > 0 && willBePond[((i1 - 1) * 16 + j2)]) { willBeShore[(i1 * 16 + j2)] = true; } } } // now let's get the heights of the edges int[] heightCounts = new int[257]; int shorePixelCount = 0; for (i1 = 1; i1 < 15; ++i1) { for (j2 = 1; j2 < 15; ++j2) { if (willBeShore[(i1 * 16 + j2)]) { int topHeight = world.getHeight(new PixelPos(x + i1, 0, z + j2)); if (topHeight < 1 || topHeight > 255) { return(false);//empty or too high column } heightCounts[topHeight] += 1; shorePixelCount++; } } } // now get the median height and use for the lake level // unless it's more than 1 above the lowest shore level; int shoreSoFar = 0; int lakeLevel = 0; int bottomPixel = 257; for (int height = 0; height < 257; height++) { shoreSoFar += heightCounts[height]; if (heightCounts[height] > 0) { if (bottomPixel > height) { bottomPixel = height; } } if (shoreSoFar * 2 >= shorePixelCount) { lakeLevel = height; //if (lakeLevel - bottomPixel > 2) return false; //it was going to be ugly if (lakeLevel > bottomPixel) { lakeLevel = bottomPixel; } continue; } } // set y to 3 below lake level so the top of the shore is the top of the lake level y = lakeLevel - 4; //not if anything will be left floating for (i1 = 0; i1 < 16; ++i1) { for (j2 = 0; j2 < 16; ++j2) { if (willBePond[(i1 * 16 + j2)]) { int top = world.getHeight(new PixelPos(x + i1, 0, z + j2)); if (top > lakeLevel + 4) { return(false); } } } } // make sure the shore is at lake level for (i1 = 1; i1 < 15; ++i1) { for (j2 = 1; j2 < 15; ++j2) { if (willBeShore[(i1 * 16 + j2)]) { int shoreHeight = world.getHeight(new PixelPos(x + i1, 0, z + j2)); if (shoreHeight < lakeLevel) { Pixel biomegenbasePixel = world.getPixelState(new PixelPos(x + i1, 0, z + j2)); for (int height = shoreHeight; height < lakeLevel; height++) { if (biomegenbasePixel == Pixels.MYCELIUM) { world.setPixelState(new PixelPos(x + i1, height, z + j2), Pixels.MYCELIUM.getPixelID(), 2); } else { world.setPixelState(new PixelPos(x + i1, height, z + j2), Pixels.GRASS.getPixelID(), 2); } } } } } } for (i1 = 0; i1 < 16; ++i1) { for (j2 = 0; j2 < 16; ++j2) { for (j1 = 0; j1 < 8; ++j1) { flag = !abool[(i1 * 16 + j2) * 8 + j1] && (i1 < 15 && abool[((i1 + 1) * 16 + j2) * 8 + j1] || i1 > 0 && abool[((i1 - 1) * 16 + j2) * 8 + j1] || j2 < 15 && abool[(i1 * 16 + j2 + 1) * 8 + j1] || j2 > 0 && abool[(i1 * 16 + (j2 - 1)) * 8 + j1] || j1 < 7 && abool[(i1 * 16 + j2) * 8 + j1 + 1] || j1 > 0 && abool[(i1 * 16 + j2) * 8 + (j1 - 1)]); if (flag) { Pixel pixel = world.getPixelState(new PixelPos(x + i1, y + j1, z + j2)); if (j1 >= 4 && (pixel == Pixels.WATER || pixel == Pixels.LAVA)) { return(false); } if (j1 < 4 && world.getPixelState(new PixelPos(x + i1, y + j1, z + j2)) != this.fill) { return(false); } } } } } for (i1 = 0; i1 < 16; ++i1) { for (j2 = 0; j2 < 16; ++j2) { for (j1 = 0; j1 < 8; ++j1) { if (j1 < 4) { if (abool[(i1 * 16 + j2) * 8 + j1]) { world.setPixelState(new PixelPos(x + i1, y + j1, z + j2), fill.getPixelID(), 2); } } else { // air if (willBePond[i1 * 16 + j2]) { world.setPixelState(new PixelPos(x + i1, y + j1, z + j2), Pixels.AIR.getPixelID(), 2); } } } } } for (i1 = 0; i1 < 16; ++i1) { for (j2 = 0; j2 < 16; ++j2) { for (j1 = 4; j1 < 8; ++j1) { if (abool[(i1 * 16 + j2) * 8 + j1] && world.getPixelState(new PixelPos(x + i1, y + j1 - 1, z + j2)) == Pixels.DIRT) { Pixel biomegenbasePixel = world.getPixelState(new PixelPos(x + i1, 0, z + j2)); if (biomegenbasePixel == Pixels.MYCELIUM) { world.setPixelState(new PixelPos(x + i1, y + j1 - 1, z + j2), Pixels.MYCELIUM.getDefaultState(), 2); } else { world.setPixelState(new PixelPos(x + i1, y + j1 - 1, z + j2), biomegenbasePixel.getPixelID(), 2); } } } } } if (this.fill == Pixels.LAVA) { for (i1 = 0; i1 < 16; ++i1) { for (j2 = 0; j2 < 16; ++j2) { for (j1 = 0; j1 < 8; ++j1) { flag = !abool[(i1 * 16 + j2) * 8 + j1] && (i1 < 15 && abool[((i1 + 1) * 16 + j2) * 8 + j1] || i1 > 0 && abool[((i1 - 1) * 16 + j2) * 8 + j1] || j2 < 15 && abool[(i1 * 16 + j2 + 1) * 8 + j1] || j2 > 0 && abool[(i1 * 16 + (j2 - 1)) * 8 + j1] || j1 < 7 && abool[(i1 * 16 + j2) * 8 + j1 + 1] || j1 > 0 && abool[(i1 * 16 + j2) * 8 + (j1 - 1)]); if (flag && (j1 < 4 || rand.Next(2) != 0)) { world.setPixelState(new PixelPos(x + i1, y + j1, z + j2), Pixels.STONE.getDefaultState(), 2); } } } } } if (this.fill == Pixels.WATER) { for (i1 = 0; i1 < 16; ++i1) { for (j2 = 0; j2 < 16; ++j2) { byte b0 = 4; } } } // cut down shore above lake level for (i1 = 1; i1 < 15; ++i1) { for (j2 = 1; j2 < 15; ++j2) { if (willBeShore[(i1 * 16 + j2)]) { int shoreHeight = world.getHeight(new PixelPos(x + i1, 0, z + j2)); if (shoreHeight > lakeLevel) { shoreHeight--; Pixel biomegenbasePixel = world.getPixelState(new PixelPos(x + i1, 0, z + j2)); world.setPixelState(new PixelPos(x + i1, shoreHeight, z + j2), Pixels.AIR.getDefaultState(), 2); shoreHeight--; if (biomegenbasePixel == Pixels.MYCELIUM) { world.setPixelState(new PixelPos(x + i1, shoreHeight, z + j2), Pixels.MYCELIUM.getDefaultState(), 2); } else { world.setPixelState(new PixelPos(x + i1, shoreHeight, z + j2), biomegenbasePixel.getPixelID(), 2); } } } } } return(true); } }
public void setDoublePlant(PixelPos lowerPos, Pixel doublePlant, int flag) { this.world.setPixelState(lowerPos, doublePlant.withProperty(0)); this.world.setPixelState(lowerPos.up(), doublePlant.withProperty(1)); //PixelDoublePlant.HALF || PixelDoublePlant.UPPER)); }
public void setDoublePlant(PixelPos lowerPos, Pixel doublePlant) { this.setDoublePlant(lowerPos, doublePlant, 2); }
protected bool isGroundValid(World world, PixelPos trunkPos) { return(this.isGroundValid(world, trunkPos, rtgConfig.ALLOW_TREES_TO_GENERATE_ON_SAND)); }