Fixed Bugs in DungeonHelper #31
@@ -31,7 +31,7 @@ public class DungeonHelper
|
|||||||
{
|
{
|
||||||
private static DungeonHelper instance = null;
|
private static DungeonHelper instance = null;
|
||||||
private static DDProperties properties = null;
|
private static DDProperties properties = null;
|
||||||
public static final Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+");
|
public static final Pattern NamePattern = Pattern.compile("[A-Za-z0-9_\\-]+");
|
||||||
|
|
||||||
private static final String SCHEMATIC_FILE_EXTENSION = ".schematic";
|
private static final String SCHEMATIC_FILE_EXTENSION = ".schematic";
|
||||||
private static final int DEFAULT_DUNGEON_WEIGHT = 100;
|
private static final int DEFAULT_DUNGEON_WEIGHT = 100;
|
||||||
@@ -91,14 +91,15 @@ public class DungeonHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Add all the basic dungeon types to dungeonTypeMapping
|
//Add all the basic dungeon types to dungeonTypeMapping
|
||||||
|
//Dungeon type names must be passed in lowercase to make matching easier.
|
||||||
dungeonTypeMapping = new HashMap<String, ArrayList<DungeonGenerator>>();
|
dungeonTypeMapping = new HashMap<String, ArrayList<DungeonGenerator>>();
|
||||||
dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE, simpleHalls);
|
dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE.toLowerCase(), simpleHalls);
|
||||||
dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE, complexHalls);
|
dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE.toLowerCase(), complexHalls);
|
||||||
dungeonTypeMapping.put(HUB_DUNGEON_TYPE, hubs);
|
dungeonTypeMapping.put(HUB_DUNGEON_TYPE.toLowerCase(), hubs);
|
||||||
dungeonTypeMapping.put(EXIT_DUNGEON_TYPE, exits);
|
dungeonTypeMapping.put(EXIT_DUNGEON_TYPE.toLowerCase(), exits);
|
||||||
dungeonTypeMapping.put(DEAD_END_DUNGEON_TYPE, deadEnds);
|
dungeonTypeMapping.put(DEAD_END_DUNGEON_TYPE.toLowerCase(), deadEnds);
|
||||||
dungeonTypeMapping.put(MAZE_DUNGEON_TYPE, mazes);
|
dungeonTypeMapping.put(MAZE_DUNGEON_TYPE.toLowerCase(), mazes);
|
||||||
dungeonTypeMapping.put(TRAP_DUNGEON_TYPE, pistonTraps);
|
dungeonTypeMapping.put(TRAP_DUNGEON_TYPE.toLowerCase(), pistonTraps);
|
||||||
|
|
||||||
//Load our reference to the DDProperties singleton
|
//Load our reference to the DDProperties singleton
|
||||||
if (properties == null)
|
if (properties == null)
|
||||||
@@ -162,13 +163,17 @@ public class DungeonHelper
|
|||||||
|
|
||||||
public boolean isCustomDungeon(int dimensionID)
|
public boolean isCustomDungeon(int dimensionID)
|
||||||
{
|
{
|
||||||
//TODO: Should we simply treat all pocket dimensions as valid custom dungeons? ~SenseiKiwi
|
|
||||||
return customDungeonStatus.containsKey(dimensionID);
|
return customDungeonStatus.containsKey(dimensionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateSchematicName(String name)
|
public boolean validateSchematicName(String name)
|
||||||
{
|
{
|
||||||
String[] dungeonData = name.split("_");
|
String[] dungeonData;
|
||||||
|
|
||||||
|
if (!name.endsWith(SCHEMATIC_FILE_EXTENSION))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_");
|
||||||
|
|
||||||
//Check for a valid number of parts
|
//Check for a valid number of parts
|
||||||
if (dungeonData.length < 3 || dungeonData.length > 4)
|
if (dungeonData.length < 3 || dungeonData.length > 4)
|
||||||
@@ -210,17 +215,17 @@ public class DungeonHelper
|
|||||||
String path = schematicFile.getAbsolutePath();
|
String path = schematicFile.getAbsolutePath();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (name.endsWith(SCHEMATIC_FILE_EXTENSION) && validateSchematicName(name))
|
if (validateSchematicName(name))
|
||||||
{
|
{
|
||||||
//Strip off the file extension while splitting the file name
|
//Strip off the file extension while splitting the file name
|
||||||
String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_");
|
String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_");
|
||||||
|
|
||||||
String dungeonType = dungeonData[0].toLowerCase();
|
String dungeonType = dungeonData[0].toLowerCase();
|
||||||
boolean open = dungeonData[2].equals("open");
|
boolean isOpen = dungeonData[2].equalsIgnoreCase("open");
|
||||||
int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT;
|
int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT;
|
||||||
|
|
||||||
//Add this custom dungeon to the list corresponding to its type
|
//Add this custom dungeon to the list corresponding to its type
|
||||||
DungeonGenerator generator = new DungeonGenerator(weight, path, open);
|
DungeonGenerator generator = new DungeonGenerator(weight, path, isOpen);
|
||||||
|
|
||||||
dungeonTypeMapping.get(dungeonType).add(generator);
|
dungeonTypeMapping.get(dungeonType).add(generator);
|
||||||
registeredDungeons.add(generator);
|
registeredDungeons.add(generator);
|
||||||
|
|||||||
129
StevenDimDoors/mod_pocketDim/world/PocketGenerator.java
Normal file
129
StevenDimDoors/mod_pocketDim/world/PocketGenerator.java
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
package StevenDimDoors.mod_pocketDim.world;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EnumCreatureType;
|
||||||
|
import net.minecraft.world.ChunkPosition;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.IChunkProvider;
|
||||||
|
import net.minecraft.world.gen.ChunkProviderGenerate;
|
||||||
|
import StevenDimDoors.mod_pocketDim.DimData;
|
||||||
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||||
|
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
||||||
|
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
||||||
|
import StevenDimDoors.mod_pocketDim.ticking.MobObelisk;
|
||||||
|
|
||||||
|
public class PocketGenerator extends ChunkProviderGenerate implements IChunkProvider
|
||||||
|
{
|
||||||
|
private World worldObj;
|
||||||
|
|
||||||
|
private static final int MAX_MONOLITH_SPAWN_Y = 245;
|
||||||
|
private static final int CHUNK_SIZE = 16;
|
||||||
|
|
||||||
|
public PocketGenerator(World par1World, long par2, boolean par4)
|
||||||
|
{
|
||||||
|
super(par1World, par2, par4);
|
||||||
|
this.worldObj = par1World;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateTerrain(int par1, int par2, byte[] par3ArrayOfByte)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean unloadQueuedChunks()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Chunk provideChunk(int chunkX, int chunkZ)
|
||||||
|
{
|
||||||
|
byte[] var3 = new byte[32768];
|
||||||
|
|
||||||
|
Chunk chunk = new Chunk(worldObj, var3, chunkX, chunkZ);
|
||||||
|
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Chunk loadChunk(int var1, int var2)
|
||||||
|
{
|
||||||
|
return super.loadChunk(var1, var2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void populate(IChunkProvider chunkProvider, int chunkX, int chunkZ)
|
||||||
|
{
|
||||||
|
//Check whether we want to populate this chunk with Monoliths.
|
||||||
|
DimData dimData = dimHelper.dimList.get(worldObj.provider.dimensionId);
|
||||||
|
|
||||||
|
if (dimData == null ||
|
||||||
|
dimData.dungeonGenerator == null ||
|
||||||
|
dimData.dungeonGenerator.isOpen)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//The following initialization code is based on code from ChunkProviderGenerate.
|
||||||
|
//It makes our generation depend on the world seed.
|
||||||
|
Random random = new Random(worldObj.getSeed());
|
||||||
|
long factorA = random.nextLong() / 2L * 2L + 1L;
|
||||||
|
long factorB = random.nextLong() / 2L * 2L + 1L;
|
||||||
|
random.setSeed((long)chunkX * factorA + (long)chunkZ * factorB ^ worldObj.getSeed());
|
||||||
|
|
||||||
|
int x, y, z;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
//Select a random column within the chunk
|
||||||
|
x = chunkX * CHUNK_SIZE + random.nextInt(CHUNK_SIZE);
|
||||||
|
z = chunkZ * CHUNK_SIZE + random.nextInt(CHUNK_SIZE);
|
||||||
|
y = 0;
|
||||||
|
|
||||||
|
while (worldObj.getBlockId(x, y, z) == 0 && y < 255)
|
||||||
|
{
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
y = yCoordHelper.getFirstUncovered(worldObj,x , y + 2, z);
|
||||||
|
|
||||||
|
if (worldObj.getBlockId(x, y - 1, z) != mod_pocketDim.blockDimWall.blockID)
|
||||||
|
{
|
||||||
|
y += random.nextInt(4) + 2;
|
||||||
|
}
|
||||||
|
if (y <= MAX_MONOLITH_SPAWN_Y)
|
||||||
|
{
|
||||||
|
Entity mob = new MobObelisk(worldObj);
|
||||||
|
mob.setLocationAndAngles(x, y, z, 1, 1);
|
||||||
|
worldObj.spawnEntityInWorld(mob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (yCoordHelper.getFirstUncovered(worldObj, x , y, z) > y || random.nextBoolean());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List getPossibleCreatures(EnumCreatureType var1, int var2, int var3, int var4)
|
||||||
|
{
|
||||||
|
DimData data = dimHelper.dimList.get(this.worldObj.provider.dimensionId);
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
if (data.dungeonGenerator != null)
|
||||||
|
{
|
||||||
|
if (data.isDimRandomRift && data.isPocket && !data.dungeonGenerator.isOpen)
|
||||||
|
{
|
||||||
|
return this.worldObj.getBiomeGenForCoords(var2, var3).getSpawnableList(var1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkPosition findClosestStructure(World var1, String var2, int var3, int var4, int var5)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
package StevenDimDoors.mod_pocketDim.world;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import StevenDimDoors.mod_pocketDim.DimData;
|
|
||||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
|
||||||
import StevenDimDoors.mod_pocketDim.helpers.dimHelper;
|
|
||||||
import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper;
|
|
||||||
import StevenDimDoors.mod_pocketDim.ticking.MobObelisk;
|
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.EnumCreatureType;
|
|
||||||
import net.minecraft.world.ChunkPosition;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.chunk.Chunk;
|
|
||||||
import net.minecraft.world.chunk.IChunkProvider;
|
|
||||||
import net.minecraft.world.gen.ChunkProviderGenerate;
|
|
||||||
|
|
||||||
public class pocketGenerator extends ChunkProviderGenerate implements IChunkProvider
|
|
||||||
{
|
|
||||||
private World worldObj;
|
|
||||||
private Random rand = new Random();
|
|
||||||
|
|
||||||
public pocketGenerator(World par1World, long par2, boolean par4)
|
|
||||||
{
|
|
||||||
|
|
||||||
super(par1World, par2, par4);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
this.worldObj=par1World;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void generateTerrain(int par1, int par2, byte[] par3ArrayOfByte)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean unloadQueuedChunks()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Chunk provideChunk(int par1, int par2)
|
|
||||||
{
|
|
||||||
|
|
||||||
byte[] var3 = new byte[32768];
|
|
||||||
|
|
||||||
Chunk var4 = new Chunk(this.worldObj, var3, par1, par2);
|
|
||||||
|
|
||||||
return var4;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Chunk loadChunk(int var1, int var2)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return super.loadChunk(var1, var2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void populate(IChunkProvider var1, int var2, int var3)
|
|
||||||
{
|
|
||||||
if(dimHelper.dimList.containsKey(worldObj.provider.dimensionId))
|
|
||||||
{
|
|
||||||
if(dimHelper.dimList.get(worldObj.provider.dimensionId).dungeonGenerator==null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(dimHelper.dimList.get(worldObj.provider.dimensionId).dungeonGenerator.isOpen)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int y =0;
|
|
||||||
int x = var2*16 + rand.nextInt(16);
|
|
||||||
int z = var3*16 + rand.nextInt(16);
|
|
||||||
int yTest;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
|
|
||||||
x = var2*16 + rand.nextInt(32)-8;
|
|
||||||
z = var3*16 + rand.nextInt(32)-8;
|
|
||||||
|
|
||||||
while(this.worldObj.getBlockId(x, y, z)==0&&y<255)
|
|
||||||
{
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
y = yCoordHelper.getFirstUncovered(this.worldObj,x , y+2, z);
|
|
||||||
|
|
||||||
if(this.worldObj.getBlockId(x, y-1, z)!=mod_pocketDim.blockDimWall.blockID)
|
|
||||||
{
|
|
||||||
y= y+rand.nextInt(4)+2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(y>245)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity mob = new MobObelisk(this.worldObj);
|
|
||||||
mob.setLocationAndAngles(x, y, z, 1, 1);
|
|
||||||
this.worldObj.spawnEntityInWorld(mob);
|
|
||||||
|
|
||||||
}
|
|
||||||
while( yCoordHelper.getFirstUncovered(this.worldObj,x , y, z)>y);
|
|
||||||
|
|
||||||
if(rand.nextBoolean())
|
|
||||||
{
|
|
||||||
this.populate(var1, var2, var3);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List getPossibleCreatures(EnumCreatureType var1, int var2, int var3,
|
|
||||||
int var4)
|
|
||||||
{
|
|
||||||
DimData data = dimHelper.dimList.get(this.worldObj.provider.dimensionId);
|
|
||||||
if(data!=null)
|
|
||||||
{
|
|
||||||
if(data.dungeonGenerator!=null)
|
|
||||||
{
|
|
||||||
if(data.isDimRandomRift&&data.isPocket&&!data.dungeonGenerator.isOpen)
|
|
||||||
{
|
|
||||||
ArrayList list = new ArrayList();
|
|
||||||
|
|
||||||
return this.worldObj.getBiomeGenForCoords(var2, var3).getSpawnableList(var1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChunkPosition findClosestStructure(World var1, String var2,
|
|
||||||
int var3, int var4, int var5) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -79,7 +79,7 @@ public class pocketProvider extends WorldProvider
|
|||||||
@Override
|
@Override
|
||||||
public IChunkProvider createChunkGenerator()
|
public IChunkProvider createChunkGenerator()
|
||||||
{
|
{
|
||||||
return new pocketGenerator(worldObj, dimensionId, false);
|
return new PocketGenerator(worldObj, dimensionId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user