changed cellular dungeon implementation to use "MetaBlocks"

This commit is contained in:
Boblet 2020-08-20 12:38:43 +02:00
parent c69e9d6625
commit 920599af25
7 changed files with 70 additions and 31 deletions

View File

@ -302,5 +302,20 @@ public class RecipesCommon {
return new OreDictStack(name, stacksize);
}
}
public static class MetaBlock {
public Block block;
public int meta;
public MetaBlock(Block block, int meta) {
this.block = block;
this.meta = meta;
}
public MetaBlock(Block block) {
this(block, 0);
}
}
}

View File

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import com.hbm.inventory.RecipesCommon.MetaBlock;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@ -25,11 +27,11 @@ public class CellularDungeon {
//the height of a room
public int height;
//list of random floor blocks with equal weight
public List<Block> floor = new ArrayList();
public List<MetaBlock> floor = new ArrayList();
//list of random ceiling blocks with equal weight
public List<Block> ceiling = new ArrayList();
public List<MetaBlock> ceiling = new ArrayList();
//list of random wall blocks with equal weight
public List<Block> wall = new ArrayList();
public List<MetaBlock> wall = new ArrayList();
//the rooms that the dungeon can use
public List<CellularDungeonRoom> rooms = new ArrayList();
int tries;
@ -45,7 +47,7 @@ public class CellularDungeon {
this.branches = branches;
}
public CellularDungeon(int width, int height, int dimX, int dimZ, int tries, int branches, Block floor, Block ceiling, Block wall) {
public CellularDungeon(int width, int height, int dimX, int dimZ, int tries, int branches, MetaBlock floor, MetaBlock ceiling, MetaBlock wall) {
this.dimX = dimX;
this.dimZ = dimZ;

View File

@ -1,5 +1,7 @@
package com.hbm.world.generator;
import com.hbm.inventory.RecipesCommon.MetaBlock;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@ -29,7 +31,7 @@ public class CellularDungeonRoom {
public void generateMain(World world, int x, int y, int z) {
DungeonToolbox.generateBox(world, x, y, z, parent.width, 1, parent.width, parent.floor);
DungeonToolbox.generateBox(world, x, y + 1, z, parent.width, parent.height - 1, parent.width, Blocks.air);
DungeonToolbox.generateBox(world, x, y + 1, z, parent.width, parent.height - 1, parent.width, new MetaBlock(Blocks.air));
DungeonToolbox.generateBox(world, x, y + parent.height - 1, z, parent.width, 1, parent.width, parent.ceiling);
}
@ -39,28 +41,28 @@ public class CellularDungeonRoom {
DungeonToolbox.generateBox(world, x, y + 1, z, parent.width, parent.height - 2, 1, parent.wall);
if(door)
DungeonToolbox.generateBox(world, x + parent.width / 2, y + 1, z, 1, 2, 1, Blocks.air);
DungeonToolbox.generateBox(world, x + parent.width / 2, y + 1, z, 1, 2, 1, new MetaBlock(Blocks.air));
}
if(wall == ForgeDirection.SOUTH) {
DungeonToolbox.generateBox(world, x, y + 1, z + parent.width - 1, parent.width, parent.height - 2, 1, parent.wall);
if(door)
DungeonToolbox.generateBox(world, x + parent.width / 2, y + 1, z + parent.width - 1, 1, 2, 1, Blocks.air);
DungeonToolbox.generateBox(world, x + parent.width / 2, y + 1, z + parent.width - 1, 1, 2, 1, new MetaBlock(Blocks.air));
}
if(wall == ForgeDirection.WEST) {
DungeonToolbox.generateBox(world, x, y + 1, z, 1, parent.height - 2, parent.width, parent.wall);
if(door)
DungeonToolbox.generateBox(world, x, y + 1, z + parent.width / 2, 1, 2, 1, Blocks.air);
DungeonToolbox.generateBox(world, x, y + 1, z + parent.width / 2, 1, 2, 1, new MetaBlock(Blocks.air));
}
if(wall == ForgeDirection.EAST) {
DungeonToolbox.generateBox(world, x + parent.width - 1, y + 1, z, 1, parent.height - 2, parent.width, parent.wall);
if(door)
DungeonToolbox.generateBox(world, x + parent.width - 1, y + 1, z + parent.width / 2, 1, 2, 1, Blocks.air);
DungeonToolbox.generateBox(world, x + parent.width - 1, y + 1, z + parent.width / 2, 1, 2, 1, new MetaBlock(Blocks.air));
}
}

View File

@ -3,13 +3,15 @@ package com.hbm.world.generator;
import java.util.List;
import java.util.Random;
import com.hbm.inventory.RecipesCommon.MetaBlock;
import net.minecraft.block.Block;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
public class DungeonToolbox {
public static void generateBoxTimed(World world, int x, int y, int z, int sx, int sy, int sz, List<Block> blocks) {
public static void generateBoxTimed(World world, int x, int y, int z, int sx, int sy, int sz, List<MetaBlock> blocks) {
if(blocks.isEmpty())
return;
@ -20,14 +22,14 @@ public class DungeonToolbox {
for(int k = z; k < z + sz; k++) {
Block b = getRandom(blocks, world.rand);
TimedGenerator.addOp(world, i, j, k, b, 0, 2);
MetaBlock b = getRandom(blocks, world.rand);
TimedGenerator.addOp(world, i, j, k, b.block, b.meta, 2);
}
}
}
}
public static void generateBox(World world, int x, int y, int z, int sx, int sy, int sz, List<Block> blocks) {
public static void generateBox(World world, int x, int y, int z, int sx, int sy, int sz, List<MetaBlock> blocks) {
if(blocks.isEmpty())
return;
@ -38,15 +40,19 @@ public class DungeonToolbox {
for(int k = z; k < z + sz; k++) {
Block b = getRandom(blocks, world.rand);
world.setBlock(i, j, k, b, 0, 2);
MetaBlock b = getRandom(blocks, world.rand);
world.setBlock(i, j, k, b.block, b.meta, 2);
}
}
}
}
public static void generateBox(World world, int x, int y, int z, int sx, int sy, int sz, Block block) {
generateBox(world, x, y, z, sx, sy, sz, new MetaBlock(block));
}
//i know it's copy paste, but it's a better strat than using a wrapper and generating single-entry lists for no good reason
public static void generateBox(World world, int x, int y, int z, int sx, int sy, int sz, Block block) {
public static void generateBox(World world, int x, int y, int z, int sx, int sy, int sz, MetaBlock block) {
for(int i = x; i < x + sx; i++) {
@ -54,13 +60,17 @@ public class DungeonToolbox {
for(int k = z; k < z + sz; k++) {
world.setBlock(i, j, k, block, 0, 2);
world.setBlock(i, j, k, block.block, block.meta, 2);
}
}
}
}
public static void generateBoxTimed(World world, int x, int y, int z, int sx, int sy, int sz, Block block) {
generateBoxTimed(world, x, y, z, sx, sy, sz, new MetaBlock(block));
}
public static void generateBoxTimed(World world, int x, int y, int z, int sx, int sy, int sz, MetaBlock block) {
for(int i = x; i < x + sx; i++) {
@ -68,14 +78,14 @@ public class DungeonToolbox {
for(int k = z; k < z + sz; k++) {
TimedGenerator.addOp(world, i, j, k, block, 0, 2);
TimedGenerator.addOp(world, i, j, k, block.block, block.meta, 2);
}
}
}
}
//now with vectors to provide handy rotations
public static void generateBox(World world, int x, int y, int z, Vec3 size, List<Block> blocks) {
public static void generateBox(World world, int x, int y, int z, Vec3 size, List<MetaBlock> blocks) {
generateBox(world, x, y, z, (int)size.xCoord, (int)size.yCoord, (int)size.zCoord, blocks);
}

View File

@ -1,18 +1,26 @@
package com.hbm.world.generator;
import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.RecipesCommon.MetaBlock;
public class JungleDungeon extends CellularDungeon {
public JungleDungeon(int width, int height, int dimX, int dimZ, int tries, int branches) {
super(width, height, dimX, dimZ, tries, branches);
this.floor.add(ModBlocks.brick_jungle);
this.floor.add(ModBlocks.brick_jungle_cracked);
this.wall.add(ModBlocks.brick_jungle);
this.wall.add(ModBlocks.brick_jungle_cracked);
this.ceiling.add(ModBlocks.brick_jungle);
this.ceiling.add(ModBlocks.brick_jungle_cracked);
this.floor.add(new MetaBlock(ModBlocks.brick_jungle));
this.floor.add(new MetaBlock(ModBlocks.brick_jungle_cracked));
for(int i = 0; i < 50; i++) {
this.wall.add(new MetaBlock(ModBlocks.brick_jungle));
this.wall.add(new MetaBlock(ModBlocks.brick_jungle_cracked));
}
for(int i = 0; i < 16; i++) {
this.wall.add(new MetaBlock(ModBlocks.brick_jungle_glyph, i));
}
this.ceiling.add(new MetaBlock(ModBlocks.brick_jungle));
this.ceiling.add(new MetaBlock(ModBlocks.brick_jungle_cracked));
}
}

View File

@ -1,18 +1,19 @@
package com.hbm.world.generator;
import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.RecipesCommon.MetaBlock;
public class TestDungeon extends CellularDungeon {
public TestDungeon(int width, int height, int dimX, int dimZ, int tries, int branches) {
super(width, height, dimX, dimZ, tries, branches);
this.floor.add(ModBlocks.meteor_polished);
this.wall.add(ModBlocks.meteor_brick);
this.wall.add(ModBlocks.meteor_brick);
this.wall.add(ModBlocks.meteor_brick_mossy);
this.wall.add(ModBlocks.meteor_brick_cracked);
this.ceiling.add(ModBlocks.block_meteor_broken);
this.floor.add(new MetaBlock(ModBlocks.meteor_polished));
this.wall.add(new MetaBlock(ModBlocks.meteor_brick));
this.wall.add(new MetaBlock(ModBlocks.meteor_brick));
this.wall.add(new MetaBlock(ModBlocks.meteor_brick_mossy));
this.wall.add(new MetaBlock(ModBlocks.meteor_brick_cracked));
this.ceiling.add(new MetaBlock(ModBlocks.block_meteor_broken));
}
}

View File

@ -8,6 +8,7 @@ import net.minecraft.world.World;
public class TimedGenerator {
//TODO: replace with timed operations, allows not only for direct block placements but also snazzy conditioned stuff
private static final HashMap<Integer, ArrayList<Object[]>> operations = new HashMap();
public static void automaton(World world, int amount) {