2013-06-10 23:03:52 +02:00
|
|
|
package StevenDimDoors.mod_pocketDim.helpers;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
2013-06-15 17:21:49 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Hashtable;
|
2013-06-10 23:03:52 +02:00
|
|
|
import java.util.Random;
|
2013-06-15 16:25:50 +02:00
|
|
|
import java.util.regex.Pattern;
|
2013-06-10 23:03:52 +02:00
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
2013-06-12 06:42:24 +02:00
|
|
|
import net.minecraft.block.BlockContainer;
|
2013-06-10 23:03:52 +02:00
|
|
|
import net.minecraft.world.World;
|
2013-06-14 01:01:54 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.DDProperties;
|
2013-06-11 20:42:11 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
|
2013-06-10 23:03:52 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.LinkData;
|
|
|
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.jnbt.ByteArrayTag;
|
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.jnbt.CompoundTag;
|
2013-06-12 23:59:34 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.jnbt.ListTag;
|
2013-06-10 23:03:52 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.jnbt.NBTOutputStream;
|
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.jnbt.ShortTag;
|
2013-06-12 06:42:24 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.helpers.jnbt.Tag;
|
2013-06-10 23:03:52 +02:00
|
|
|
|
|
|
|
public class DungeonHelper
|
|
|
|
{
|
2013-06-16 07:00:05 +02:00
|
|
|
private static DungeonHelper instance = null;
|
2013-06-14 01:01:54 +02:00
|
|
|
private static DDProperties properties = null;
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 17:21:49 +02:00
|
|
|
public static final Pattern NamePattern = Pattern.compile("[A-Za-z0-9_]+");
|
|
|
|
|
2013-06-15 16:25:50 +02:00
|
|
|
private static final String SCHEMATIC_FILE_EXTENSION = ".schematic";
|
|
|
|
private static final int DEFAULT_DUNGEON_WEIGHT = 100;
|
2013-06-15 17:30:05 +02:00
|
|
|
private static final int MAX_DUNGEON_WEIGHT = 10000; //Used to prevent overflows and math breaking down
|
2013-06-15 17:21:49 +02:00
|
|
|
|
|
|
|
private static final String HUB_DUNGEON_TYPE = "Hub";
|
|
|
|
private static final String TRAP_DUNGEON_TYPE = "Trap";
|
|
|
|
private static final String SIMPLE_HALL_DUNGEON_TYPE = "SimpleHall";
|
|
|
|
private static final String COMPLEX_HALL_DUNGEON_TYPE = "ComplexHall";
|
|
|
|
private static final String EXIT_DUNGEON_TYPE = "Exit";
|
|
|
|
private static final String DEAD_END_DUNGEON_TYPE = "DeadEnd";
|
|
|
|
private static final String MAZE_DUNGEON_TYPE = "Maze";
|
|
|
|
|
|
|
|
//The list of dungeon types will be kept as an array for now. If we allow new
|
|
|
|
//dungeon types in the future, then this can be changed to an ArrayList.
|
|
|
|
private static final String[] DUNGEON_TYPES = new String[] {
|
|
|
|
HUB_DUNGEON_TYPE,
|
|
|
|
TRAP_DUNGEON_TYPE,
|
|
|
|
SIMPLE_HALL_DUNGEON_TYPE,
|
|
|
|
COMPLEX_HALL_DUNGEON_TYPE,
|
|
|
|
EXIT_DUNGEON_TYPE,
|
|
|
|
DEAD_END_DUNGEON_TYPE,
|
|
|
|
MAZE_DUNGEON_TYPE
|
|
|
|
};
|
|
|
|
|
|
|
|
private Random rand = new Random();
|
2013-06-15 16:25:50 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
public HashMap<Integer, LinkData> customDungeonStatus = new HashMap<Integer, LinkData>();
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
public ArrayList<DungeonGenerator> customDungeons = new ArrayList<DungeonGenerator>();
|
|
|
|
public ArrayList<DungeonGenerator> registeredDungeons = new ArrayList<DungeonGenerator>();
|
2013-06-15 14:46:28 +02:00
|
|
|
|
|
|
|
private ArrayList<DungeonGenerator> weightedDungeonGenList = new ArrayList<DungeonGenerator>();
|
|
|
|
private ArrayList<DungeonGenerator> simpleHalls = new ArrayList<DungeonGenerator>();
|
|
|
|
private ArrayList<DungeonGenerator> complexHalls = new ArrayList<DungeonGenerator>();
|
|
|
|
private ArrayList<DungeonGenerator> deadEnds = new ArrayList<DungeonGenerator>();
|
|
|
|
private ArrayList<DungeonGenerator> hubs = new ArrayList<DungeonGenerator>();
|
|
|
|
private ArrayList<DungeonGenerator> mazes = new ArrayList<DungeonGenerator>();
|
|
|
|
private ArrayList<DungeonGenerator> pistonTraps = new ArrayList<DungeonGenerator>();
|
|
|
|
private ArrayList<DungeonGenerator> exits = new ArrayList<DungeonGenerator>();
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
public ArrayList<Integer> metadataFlipList = new ArrayList<Integer>();
|
|
|
|
public ArrayList<Integer> metadataNextList = new ArrayList<Integer>();
|
|
|
|
|
|
|
|
public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true);
|
2013-06-15 17:21:49 +02:00
|
|
|
private HashSet<String> dungeonTypeChecker;
|
|
|
|
private Hashtable<String, ArrayList<DungeonGenerator>> dungeonTypeMapping;
|
|
|
|
|
2013-06-16 07:00:05 +02:00
|
|
|
private DungeonHelper()
|
2013-06-15 14:46:28 +02:00
|
|
|
{
|
2013-06-15 17:21:49 +02:00
|
|
|
//Load the dungeon type checker with the list of all types in lowercase.
|
|
|
|
//Capitalization matters for matching in a hash set.
|
|
|
|
dungeonTypeChecker = new HashSet<String>();
|
|
|
|
for (String dungeonType : DUNGEON_TYPES)
|
|
|
|
{
|
|
|
|
dungeonTypeChecker.add(dungeonType.toLowerCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
//Add all the basic dungeon types to dungeonTypeMapping
|
|
|
|
dungeonTypeMapping.put(SIMPLE_HALL_DUNGEON_TYPE, simpleHalls);
|
|
|
|
dungeonTypeMapping.put(COMPLEX_HALL_DUNGEON_TYPE, complexHalls);
|
|
|
|
dungeonTypeMapping.put(HUB_DUNGEON_TYPE, hubs);
|
|
|
|
dungeonTypeMapping.put(EXIT_DUNGEON_TYPE, exits);
|
|
|
|
dungeonTypeMapping.put(DEAD_END_DUNGEON_TYPE, deadEnds);
|
|
|
|
dungeonTypeMapping.put(MAZE_DUNGEON_TYPE, mazes);
|
|
|
|
dungeonTypeMapping.put(TRAP_DUNGEON_TYPE, pistonTraps);
|
|
|
|
|
|
|
|
//Load our reference to the DDProperties singleton
|
2013-06-15 14:46:28 +02:00
|
|
|
if (properties == null)
|
|
|
|
properties = DDProperties.instance();
|
|
|
|
}
|
|
|
|
|
2013-06-16 07:00:05 +02:00
|
|
|
public static DungeonHelper create()
|
|
|
|
{
|
|
|
|
if (instance == null)
|
|
|
|
instance = new DungeonHelper();
|
|
|
|
else
|
|
|
|
throw new IllegalStateException("Cannot create DungeonHelper twice");
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static DungeonHelper instance()
|
|
|
|
{
|
|
|
|
if (instance == null)
|
|
|
|
{
|
|
|
|
//This is to prevent some frustrating bugs that could arise when classes
|
|
|
|
//are loaded in the wrong order. Trust me, I had to squash a few...
|
|
|
|
throw new IllegalStateException("Instance of DungeonHelper requested before creation");
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2013-06-15 16:25:50 +02:00
|
|
|
public boolean validateSchematicName(String name)
|
|
|
|
{
|
|
|
|
String[] dungeonData = name.split("_");
|
|
|
|
|
|
|
|
//Check for a valid number of parts
|
|
|
|
if (dungeonData.length < 3 || dungeonData.length > 4)
|
|
|
|
return false;
|
|
|
|
|
2013-06-15 17:21:49 +02:00
|
|
|
//Check if the dungeon type is valid
|
|
|
|
if (!dungeonTypeChecker.contains(dungeonData[0].toLowerCase()))
|
2013-06-15 16:25:50 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
//Check if the name is valid
|
|
|
|
if (!NamePattern.matcher(dungeonData[1]).matches())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//Check if the open/closed flag is present
|
|
|
|
if (!dungeonData[2].equalsIgnoreCase("open") && !dungeonData[2].equalsIgnoreCase("closed"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//If the weight is present, check that it is valid
|
|
|
|
if (dungeonData.length == 4)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int weight = Integer.parseInt(dungeonData[3]);
|
2013-06-15 17:30:05 +02:00
|
|
|
if (weight < 0 || weight > MAX_DUNGEON_WEIGHT)
|
2013-06-15 16:25:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch (NumberFormatException e)
|
|
|
|
{
|
|
|
|
//Not a number
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
public void registerCustomDungeon(File schematicFile)
|
|
|
|
{
|
2013-06-15 16:25:50 +02:00
|
|
|
String name = schematicFile.getName();
|
2013-06-15 17:21:49 +02:00
|
|
|
String path = schematicFile.getAbsolutePath();
|
2013-06-10 23:03:52 +02:00
|
|
|
try
|
|
|
|
{
|
2013-06-15 16:25:50 +02:00
|
|
|
if (name.endsWith(SCHEMATIC_FILE_EXTENSION) && validateSchematicName(name))
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
2013-06-15 16:25:50 +02:00
|
|
|
//Strip off the file extension while splitting the file name
|
|
|
|
String[] dungeonData = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()).split("_");
|
|
|
|
|
2013-06-15 17:21:49 +02:00
|
|
|
String dungeonType = dungeonData[0].toLowerCase();
|
2013-06-15 16:25:50 +02:00
|
|
|
boolean open = dungeonData[2].equals("open");
|
|
|
|
int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT;
|
2013-06-15 17:21:49 +02:00
|
|
|
|
|
|
|
//Add this custom dungeon to the list corresponding to its type
|
|
|
|
DungeonGenerator generator = new DungeonGenerator(weight, path, open);
|
2013-06-15 16:25:50 +02:00
|
|
|
|
2013-06-15 17:21:49 +02:00
|
|
|
dungeonTypeMapping.get(dungeonType).add(generator);
|
|
|
|
weightedDungeonGenList.add(generator);
|
|
|
|
registeredDungeons.add(generator);
|
2013-06-15 17:30:05 +02:00
|
|
|
customDungeons.add(generator);
|
2013-06-15 16:25:50 +02:00
|
|
|
System.out.println("Imported " + name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println("Could not parse dungeon filename, not adding dungeon to generation lists");
|
2013-06-15 17:21:49 +02:00
|
|
|
customDungeons.add(new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, path, true));
|
2013-06-15 16:25:50 +02:00
|
|
|
System.out.println("Imported " + name);
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
2013-06-15 16:25:50 +02:00
|
|
|
System.out.println("Failed to import " + name);
|
2013-06-15 14:07:33 +02:00
|
|
|
}
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
public void importCustomDungeons(String dir)
|
|
|
|
{
|
|
|
|
File file = new File(dir);
|
2013-06-15 16:25:50 +02:00
|
|
|
File[] schematicNames = file.listFiles();
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-15 16:25:50 +02:00
|
|
|
if (schematicNames!=null)
|
2013-06-15 14:07:33 +02:00
|
|
|
{
|
|
|
|
for(File schematicFile: schematicNames)
|
|
|
|
{
|
|
|
|
this.registerCustomDungeon(schematicFile);
|
|
|
|
}
|
|
|
|
}
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void registerFlipBlocks()
|
|
|
|
{
|
|
|
|
this.metadataFlipList.add(Block.dispenser.blockID);
|
|
|
|
this.metadataFlipList.add(Block.stairsStoneBrick.blockID);
|
|
|
|
this.metadataFlipList.add(Block.lever.blockID);
|
|
|
|
this.metadataFlipList.add(Block.stoneButton.blockID);
|
|
|
|
this.metadataFlipList.add(Block.redstoneRepeaterIdle.blockID);
|
|
|
|
this.metadataFlipList.add(Block.redstoneRepeaterActive.blockID);
|
|
|
|
this.metadataFlipList.add(Block.tripWireSource.blockID);
|
|
|
|
this.metadataFlipList.add(Block.torchWood.blockID);
|
|
|
|
this.metadataFlipList.add(Block.torchRedstoneIdle.blockID);
|
|
|
|
this.metadataFlipList.add(Block.torchRedstoneActive.blockID);
|
|
|
|
this.metadataFlipList.add(Block.doorIron.blockID);
|
|
|
|
this.metadataFlipList.add(Block.doorWood.blockID);
|
|
|
|
this.metadataFlipList.add(Block.pistonBase.blockID);
|
|
|
|
this.metadataFlipList.add(Block.pistonStickyBase.blockID);
|
2013-06-15 10:19:08 +02:00
|
|
|
this.metadataFlipList.add(Block.pistonExtension.blockID);
|
2013-06-11 21:43:27 +02:00
|
|
|
this.metadataFlipList.add(Block.redstoneComparatorIdle.blockID);
|
|
|
|
this.metadataFlipList.add(Block.redstoneComparatorActive.blockID);
|
|
|
|
this.metadataFlipList.add(Block.signPost.blockID);
|
|
|
|
this.metadataFlipList.add(Block.signWall.blockID);
|
|
|
|
this.metadataFlipList.add(Block.skull.blockID);
|
|
|
|
this.metadataFlipList.add(Block.ladder.blockID);
|
2013-06-12 06:42:24 +02:00
|
|
|
this.metadataFlipList.add(Block.vine.blockID);
|
|
|
|
this.metadataFlipList.add(Block.anvil.blockID);
|
|
|
|
this.metadataFlipList.add(Block.chest.blockID);
|
|
|
|
this.metadataFlipList.add(Block.chestTrapped.blockID);
|
|
|
|
this.metadataFlipList.add(Block.hopperBlock.blockID);
|
2013-06-10 23:03:52 +02:00
|
|
|
this.metadataFlipList.add(Block.stairsNetherBrick.blockID);
|
|
|
|
this.metadataFlipList.add(Block.stairsCobblestone.blockID);
|
|
|
|
this.metadataFlipList.add(Block.stairsNetherBrick.blockID);
|
|
|
|
this.metadataFlipList.add(Block.stairsNetherQuartz.blockID);
|
|
|
|
this.metadataFlipList.add(Block.stairsSandStone.blockID);
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
this.metadataNextList.add(Block.redstoneRepeaterIdle.blockID);
|
|
|
|
this.metadataNextList.add(Block.redstoneRepeaterActive.blockID);
|
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
public void registerBaseDungeons()
|
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
this.hubs.add(new DungeonGenerator(0, "/schematics/4WayBasicHall.schematic", false));
|
|
|
|
this.hubs.add(new DungeonGenerator(0, "/schematics/4WayBasicHall.schematic", false));
|
|
|
|
this.hubs.add(new DungeonGenerator(0, "/schematics/doorTotemRuins.schematic", true));
|
|
|
|
this.hubs.add(new DungeonGenerator(0, "/schematics/hallwayTrapRooms1.schematic", false));
|
|
|
|
this.hubs.add(new DungeonGenerator(0, "/schematics/longDoorHallway.schematic", false));
|
|
|
|
this.hubs.add(new DungeonGenerator(0, "/schematics/smallRotundaWithExit.schematic", false));
|
|
|
|
this.hubs.add(new DungeonGenerator(0, "/schematics/fortRuins.schematic", true));
|
|
|
|
this.hubs.add(new DungeonGenerator(0, "/schematics/4WayHallExit.schematic", false));
|
|
|
|
this.hubs.add(new DungeonGenerator(0, "/schematics/4WayHallExit.schematic", false));
|
|
|
|
|
|
|
|
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/collapsedSingleTunnel1.schematic", false));
|
|
|
|
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/singleStraightHall1.schematic", false));
|
|
|
|
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/smallBranchWithExit.schematic", false));
|
|
|
|
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/smallSimpleLeft.schematic", false));
|
|
|
|
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/smallSimpleRight.schematic", false));
|
|
|
|
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/simpleStairsUp.schematic", false));
|
|
|
|
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/simpleStairsDown.schematic", false));
|
|
|
|
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/simpleSmallT1.schematic", false));
|
|
|
|
|
|
|
|
this.complexHalls.add(new DungeonGenerator(0, "/schematics/tntPuzzleTrap.schematic", false));
|
|
|
|
this.complexHalls.add(new DungeonGenerator(0, "/schematics/brokenPillarsO.schematic", true));
|
|
|
|
this.complexHalls.add(new DungeonGenerator(0, "/schematics/buggyTopEntry1.schematic", true));
|
|
|
|
this.complexHalls.add(new DungeonGenerator(0, "/schematics/exitRuinsWithHiddenDoor.schematic", true));
|
|
|
|
this.complexHalls.add(new DungeonGenerator(0, "/schematics/hallwayHiddenTreasure.schematic", false));
|
|
|
|
this.complexHalls.add(new DungeonGenerator(0, "/schematics/mediumPillarStairs.schematic", true));
|
|
|
|
this.complexHalls.add(new DungeonGenerator(0, "/schematics/ruinsO.schematic", true));
|
|
|
|
this.complexHalls.add(new DungeonGenerator(0, "/schematics/pitStairs.schematic", true));
|
|
|
|
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/azersDungeonO.schematic", false));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/diamondTowerTemple1.schematic", true));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/fallingTrapO.schematic", false));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/hiddenStaircaseO.schematic", true));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/lavaTrapO.schematic", true));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/randomTree.schematic", true));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/smallHiddenTowerO.schematic", true));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/smallSilverfishRoom.schematic", false));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/tntTrapO.schematic", false));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/smallDesert.schematic", true));
|
|
|
|
this.deadEnds.add(new DungeonGenerator(0, "/schematics/smallPond.schematic", true));
|
|
|
|
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/fakeTNTTrap.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/hallwayPitFallTrap.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/hallwayPitFallTrap.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/pistonFallRuins.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/pistonFloorHall.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/pistonFloorHall.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/pistonSmasherHall.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/simpleDropHall.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/wallFallcomboPistonHall.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/wallFallcomboPistonHall.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/fallingTNThall.schematic", false));
|
|
|
|
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/lavaPyramid.schematic", true));
|
|
|
|
|
|
|
|
this.mazes.add(new DungeonGenerator(0, "/schematics/smallMaze1.schematic", false));
|
|
|
|
this.mazes.add(new DungeonGenerator(0, "/schematics/smallMultilevelMaze.schematic", false));
|
|
|
|
|
|
|
|
this.exits.add(new DungeonGenerator(0, "/schematics/exitCube.schematic", true));
|
|
|
|
this.exits.add(new DungeonGenerator(0, "/schematics/lockingExitHall.schematic", false));
|
|
|
|
this.exits.add(new DungeonGenerator(0, "/schematics/smallExitPrison.schematic", true));
|
|
|
|
this.exits.add(new DungeonGenerator(0, "/schematics/lockingExitHall.schematic", false));
|
|
|
|
|
|
|
|
this.weightedDungeonGenList.addAll(this.simpleHalls);
|
|
|
|
this.weightedDungeonGenList.addAll(this.exits);
|
|
|
|
this.weightedDungeonGenList.addAll(this.pistonTraps);
|
|
|
|
this.weightedDungeonGenList.addAll(this.mazes);
|
|
|
|
this.weightedDungeonGenList.addAll(this.deadEnds);
|
|
|
|
this.weightedDungeonGenList.addAll(this.complexHalls);
|
|
|
|
this.weightedDungeonGenList.addAll(this.hubs);
|
|
|
|
|
|
|
|
for(DungeonGenerator data : this.weightedDungeonGenList)
|
|
|
|
{
|
|
|
|
if(!this.registeredDungeons.contains(data))
|
|
|
|
{
|
|
|
|
this.registeredDungeons.add(data);
|
|
|
|
}
|
|
|
|
}
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-11 20:42:11 +02:00
|
|
|
public DungeonGenerator exportDungeon(World world, int xI, int yI, int zI, String file)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
|
|
|
int xMin;
|
|
|
|
int yMin;
|
|
|
|
int zMin;
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
int xMax;
|
|
|
|
int yMax;
|
|
|
|
int zMax;
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
xMin=xMax=xI;
|
|
|
|
yMin=yMax=yI;
|
|
|
|
zMin=zMax=zI;
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
for(int count=0;count<50;count++)
|
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-14 01:01:54 +02:00
|
|
|
if(world.getBlockId(xMin, yI, zI)!=properties.PermaFabricBlockID)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
|
|
|
xMin--;
|
|
|
|
}
|
2013-06-14 01:01:54 +02:00
|
|
|
if(world.getBlockId(xI, yMin, zI)!=properties.PermaFabricBlockID)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
|
|
|
yMin--;
|
|
|
|
}
|
2013-06-14 01:01:54 +02:00
|
|
|
if(world.getBlockId(xI, yI, zMin)!=properties.PermaFabricBlockID)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
|
|
|
zMin--;
|
|
|
|
}
|
2013-06-14 01:01:54 +02:00
|
|
|
if(world.getBlockId(xMax, yI, zI)!=properties.PermaFabricBlockID)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
|
|
|
xMax++;
|
|
|
|
}
|
2013-06-14 01:01:54 +02:00
|
|
|
if(world.getBlockId(xI, yMax, zI)!=properties.PermaFabricBlockID)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
|
|
|
yMax++;
|
|
|
|
}
|
2013-06-14 01:01:54 +02:00
|
|
|
if(world.getBlockId(xI, yI, zMax)!=properties.PermaFabricBlockID)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
|
|
|
zMax++;
|
|
|
|
}
|
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
short width =(short) (xMax-xMin);
|
|
|
|
short height= (short) (yMax-yMin);
|
|
|
|
short length= (short) (zMax-zMin);
|
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
//ArrayList<NBTTagCompound> tileEntities = new ArrayList<NBTTagCompound>();
|
|
|
|
ArrayList<Tag> tileEntites = new ArrayList<Tag>();
|
|
|
|
byte[] blocks = new byte[width * height * length];
|
|
|
|
byte[] addBlocks = null;
|
|
|
|
byte[] blockData = new byte[width * height * length];
|
|
|
|
|
|
|
|
for (int x = 0; x < width; ++x)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < height; ++y)
|
|
|
|
{
|
|
|
|
for (int z = 0; z < length; ++z)
|
|
|
|
{
|
|
|
|
int index = y * width * length + z * width + x;
|
|
|
|
int blockID = world.getBlockId(x+xMin, y+yMin, z+zMin);
|
|
|
|
int meta= world.getBlockMetadata(x+xMin, y+yMin, z+zMin);
|
|
|
|
|
|
|
|
if(blockID==properties.DimensionalDoorID)
|
|
|
|
{
|
|
|
|
blockID=Block.doorIron.blockID;
|
|
|
|
}
|
|
|
|
if(blockID==properties.WarpDoorID)
|
|
|
|
{
|
|
|
|
blockID=Block.doorWood.blockID;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save 4096 IDs in an AddBlocks section
|
|
|
|
if (blockID > 255)
|
|
|
|
{
|
|
|
|
if (addBlocks == null)
|
|
|
|
{ // Lazily create section
|
|
|
|
addBlocks = new byte[(blocks.length >> 1) + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
|
|
|
|
addBlocks[index >> 1] & 0xF0 | (blockID >> 8) & 0xF
|
|
|
|
: addBlocks[index >> 1] & 0xF | ((blockID >> 8) & 0xF) << 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
blocks[index] = (byte) blockID;
|
|
|
|
blockData[index] = (byte) meta;
|
|
|
|
|
|
|
|
if (Block.blocksList[blockID] instanceof BlockContainer)
|
|
|
|
{
|
|
|
|
//TODO fix this
|
|
|
|
/**
|
2013-06-12 06:42:24 +02:00
|
|
|
TileEntity tileEntityBlock = world.getBlockTileEntity(x+xMin, y+yMin, z+zMin);
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
tileEntityBlock.writeToNBT(tag);
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-12 23:59:34 +02:00
|
|
|
CompoundTag tagC = new CompoundTag("TileEntity",Map.class.cast(tag.getTags()));
|
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
|
|
|
|
|
2013-06-12 06:42:24 +02:00
|
|
|
// Get the list of key/values from the block
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-12 23:59:34 +02:00
|
|
|
if (tagC != null)
|
2013-06-12 06:42:24 +02:00
|
|
|
{
|
2013-06-12 23:59:34 +02:00
|
|
|
tileEntites.add(tagC);
|
2013-06-12 06:42:24 +02:00
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
**/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* this.nbtdata.setShort("Width", width);
|
2013-06-10 23:03:52 +02:00
|
|
|
this.nbtdata.setShort("Height", height);
|
|
|
|
this.nbtdata.setShort("Length", length);
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
this.nbtdata.setByteArray("Blocks", blocks);
|
|
|
|
this.nbtdata.setByteArray("Data", blockData);
|
2013-06-15 14:07:33 +02:00
|
|
|
*/
|
|
|
|
|
2013-06-15 14:13:50 +02:00
|
|
|
HashMap<String, Tag> schematic = new HashMap<String, Tag>();
|
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
|
|
|
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
2013-06-15 14:13:50 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
schematic.put("Width", new ShortTag("Width", (short) width));
|
|
|
|
schematic.put("Length", new ShortTag("Length", (short) length));
|
|
|
|
schematic.put("Height", new ShortTag("Height", (short) height));
|
2013-06-15 14:13:50 +02:00
|
|
|
schematic.put("TileEntites", new ListTag("TileEntities", CompoundTag.class,tileEntites));
|
|
|
|
|
|
|
|
if (addBlocks != null)
|
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks));
|
|
|
|
}
|
|
|
|
|
|
|
|
CompoundTag schematicTag = new CompoundTag("Schematic", schematic);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NBTOutputStream stream = new NBTOutputStream(new FileOutputStream(file));
|
|
|
|
stream.writeTag(schematicTag);
|
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
this.registerCustomDungeon(new File(file));
|
|
|
|
|
|
|
|
return new DungeonGenerator(0, file, true);
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
public void generateDungeonlink(LinkData incoming)
|
|
|
|
{
|
|
|
|
//DungeonGenerator dungeon = mod_pocketDim.registeredDungeons.get(new Random().nextInt(mod_pocketDim.registeredDungeons.size()));
|
2013-06-11 20:42:11 +02:00
|
|
|
DungeonGenerator dungeon;
|
2013-06-10 23:03:52 +02:00
|
|
|
int depth = dimHelper.instance.getDimDepth(incoming.locDimID)+2;
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
int depthWeight = rand.nextInt(depth)+rand.nextInt(depth)-2;
|
2013-06-15 14:07:33 +02:00
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
depth=depth-2;
|
2013-06-15 14:07:33 +02:00
|
|
|
// DungeonGenerator
|
2013-06-10 23:03:52 +02:00
|
|
|
boolean flag = true;
|
|
|
|
int count=10;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if(dimHelper.dimList.get(incoming.destDimID)!=null&&dimHelper.dimList.get(incoming.destDimID).dungeonGenerator!=null)
|
|
|
|
{
|
|
|
|
mod_pocketDim.loader.init(incoming);
|
|
|
|
dimHelper.dimList.get(incoming.destDimID).dungeonGenerator=dimHelper.dimList.get(incoming.destDimID).dungeonGenerator;
|
|
|
|
return;
|
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
if(incoming.destYCoord>15)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
do
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
count--;
|
|
|
|
flag = true;
|
|
|
|
dungeon = this.weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size()));
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
if(depth<=1)
|
|
|
|
{
|
|
|
|
if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = complexHalls.get(rand.nextInt(complexHalls.size()));
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
}
|
|
|
|
else if(rand.nextBoolean())
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
dungeon = hubs.get(rand.nextInt(hubs.size()));
|
|
|
|
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
else if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = hubs.get(rand.nextInt(hubs.size()));
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
}
|
|
|
|
else if(deadEnds.contains(dungeon)||exits.contains(dungeon))
|
|
|
|
{
|
|
|
|
flag=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (depth<=3&&(deadEnds.contains(dungeon)||exits.contains(dungeon)||rand.nextBoolean()))
|
|
|
|
{
|
|
|
|
if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = hubs.get(rand.nextInt(hubs.size()));
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
}
|
|
|
|
else if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = mazes.get(rand.nextInt(mazes.size()));
|
|
|
|
}
|
|
|
|
else if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size()));
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flag=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(rand.nextInt(3)==0&&!complexHalls.contains(dungeon))
|
|
|
|
{
|
|
|
|
if(rand.nextInt(3)==0)
|
|
|
|
{
|
|
|
|
dungeon = simpleHalls.get(rand.nextInt(simpleHalls.size()));
|
|
|
|
}
|
|
|
|
else if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size()));
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
}
|
|
|
|
else if(depth<4)
|
|
|
|
{
|
|
|
|
dungeon = hubs.get(rand.nextInt(hubs.size()));
|
2013-06-10 23:03:52 +02:00
|
|
|
|
2013-06-15 14:07:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(depthWeight-depthWeight/2>depth-4&&(deadEnds.contains(dungeon)||exits.contains(dungeon)))
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = simpleHalls.get(rand.nextInt(simpleHalls.size()));
|
|
|
|
}
|
|
|
|
else if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = complexHalls.get(rand.nextInt(complexHalls.size()));
|
|
|
|
}
|
|
|
|
else if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size()));
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flag=false;
|
|
|
|
}
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
else if(depthWeight>7&&hubs.contains(dungeon))
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
if(rand.nextInt(12)+5<depthWeight)
|
|
|
|
{
|
|
|
|
if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = exits.get(rand.nextInt(exits.size()));
|
|
|
|
}
|
|
|
|
else if(rand.nextBoolean())
|
|
|
|
{
|
|
|
|
dungeon = deadEnds.get(rand.nextInt(deadEnds.size()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flag = false;
|
|
|
|
}
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
else if(depth>10&&hubs.contains(dungeon))
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
flag = false;
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
while (!flag && count > 0);
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
else
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
dungeon = defaultUp;
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
catch (Exception e)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
2013-06-15 14:07:33 +02:00
|
|
|
if (weightedDungeonGenList.size() > 0)
|
2013-06-10 23:03:52 +02:00
|
|
|
{
|
|
|
|
dungeon = weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-06-15 14:07:33 +02:00
|
|
|
dimHelper.dimList.get(incoming.destDimID).dungeonGenerator = dungeon;
|
2013-06-10 23:03:52 +02:00
|
|
|
}
|
|
|
|
}
|