Cleaned up and tweaked DungeonHelper

Cleaned up the indentation and empty lines in DungeonHelper. Set
metadataFlipList and metadataNextList to have generic type Integer,
since they're used to store block IDs. Whenever possible, we should
always be using parameterized collections instead of leaving their types
unspecified. I'd like to fix up the schematic HashMap in the future -
unless it's necessary, we shouldn't be storing values of various types
in that collection. Strongly typed variables or a class with the
appropriate fields would be much cleaner.
This commit is contained in:
SenseiKiwi 2013-06-15 08:07:33 -04:00
parent 4e8b8deab7
commit 172e3e3af1

View file

@ -4,14 +4,10 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.DungeonGenerator; import StevenDimDoors.mod_pocketDim.DungeonGenerator;
@ -19,29 +15,13 @@ import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.ByteArrayTag; import StevenDimDoors.mod_pocketDim.helpers.jnbt.ByteArrayTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.CompoundTag; import StevenDimDoors.mod_pocketDim.helpers.jnbt.CompoundTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.IntTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.ListTag; import StevenDimDoors.mod_pocketDim.helpers.jnbt.ListTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.NBTOutputStream; import StevenDimDoors.mod_pocketDim.helpers.jnbt.NBTOutputStream;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.ShortTag; import StevenDimDoors.mod_pocketDim.helpers.jnbt.ShortTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.StringTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.Tag; import StevenDimDoors.mod_pocketDim.helpers.jnbt.Tag;
/**
* @Return
*/
public class DungeonHelper public class DungeonHelper
{ {
public DungeonHelper()
{
if (properties == null)
properties = DDProperties.instance();
}
private static DDProperties properties = null; private static DDProperties properties = null;
private Random rand = new Random(); private Random rand = new Random();
@ -49,39 +29,20 @@ public class DungeonHelper
public HashMap<Integer, LinkData> customDungeonStatus = new HashMap<Integer, LinkData>(); public HashMap<Integer, LinkData> customDungeonStatus = new HashMap<Integer, LinkData>();
public ArrayList<DungeonGenerator> customDungeons = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> customDungeons = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> registeredDungeons = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> registeredDungeons = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> weightedDungeonGenList = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> weightedDungeonGenList = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> simpleHalls = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> simpleHalls = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> complexHalls = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> complexHalls = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> deadEnds = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> deadEnds = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> hubs = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> hubs = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> mazes = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> mazes = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> pistonTraps = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> pistonTraps = new ArrayList<DungeonGenerator>();
public ArrayList<DungeonGenerator> exits = new ArrayList<DungeonGenerator>(); public ArrayList<DungeonGenerator> exits = new ArrayList<DungeonGenerator>();
public ArrayList<String> tagList = new ArrayList<String>(); public ArrayList<String> tagList = new ArrayList<String>();
public ArrayList<Integer> metadataFlipList = new ArrayList<Integer>();
public ArrayList<Integer> metadataNextList = new ArrayList<Integer>();
public ArrayList metadataFlipList = new ArrayList();
public ArrayList metadataNextList = new ArrayList();
public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true);
@ -89,7 +50,6 @@ public class DungeonHelper
{ {
try try
{ {
if(schematicFile.getName().contains(".schematic")) if(schematicFile.getName().contains(".schematic"))
{ {
String[] name = schematicFile.getName().split("_"); String[] name = schematicFile.getName().split("_");
@ -158,19 +118,10 @@ public class DungeonHelper
count++; count++;
this.weightedDungeonGenList.add(new DungeonGenerator(weight,path,open)); this.weightedDungeonGenList.add(new DungeonGenerator(weight,path,open));
} }
this.registeredDungeons.add(new DungeonGenerator(weight,path,open)); this.registeredDungeons.add(new DungeonGenerator(weight,path,open));
System.out.println("Imported "+schematicFile.getName()); System.out.println("Imported "+schematicFile.getName());
} }
} }
} }
catch(Exception e) catch(Exception e)
{ {
@ -186,24 +137,13 @@ public class DungeonHelper
if(schematicNames!=null) if(schematicNames!=null)
{ {
for(File schematicFile: schematicNames) for(File schematicFile: schematicNames)
{ {
this.registerCustomDungeon(schematicFile); this.registerCustomDungeon(schematicFile);
} }
} }
} }
public void registerFlipBlocks() public void registerFlipBlocks()
{ {
this.metadataFlipList.add(Block.dispenser.blockID); this.metadataFlipList.add(Block.dispenser.blockID);
@ -220,10 +160,7 @@ public class DungeonHelper
this.metadataFlipList.add(Block.doorWood.blockID); this.metadataFlipList.add(Block.doorWood.blockID);
this.metadataFlipList.add(Block.pistonBase.blockID); this.metadataFlipList.add(Block.pistonBase.blockID);
this.metadataFlipList.add(Block.pistonStickyBase.blockID); this.metadataFlipList.add(Block.pistonStickyBase.blockID);
this.metadataFlipList.add(Block.pistonExtension.blockID); this.metadataFlipList.add(Block.pistonExtension.blockID);
this.metadataFlipList.add(Block.redstoneComparatorIdle.blockID); this.metadataFlipList.add(Block.redstoneComparatorIdle.blockID);
this.metadataFlipList.add(Block.redstoneComparatorActive.blockID); this.metadataFlipList.add(Block.redstoneComparatorActive.blockID);
this.metadataFlipList.add(Block.signPost.blockID); this.metadataFlipList.add(Block.signPost.blockID);
@ -235,18 +172,16 @@ public class DungeonHelper
this.metadataFlipList.add(Block.chest.blockID); this.metadataFlipList.add(Block.chest.blockID);
this.metadataFlipList.add(Block.chestTrapped.blockID); this.metadataFlipList.add(Block.chestTrapped.blockID);
this.metadataFlipList.add(Block.hopperBlock.blockID); this.metadataFlipList.add(Block.hopperBlock.blockID);
this.metadataFlipList.add(Block.stairsNetherBrick.blockID); this.metadataFlipList.add(Block.stairsNetherBrick.blockID);
this.metadataFlipList.add(Block.stairsCobblestone.blockID); this.metadataFlipList.add(Block.stairsCobblestone.blockID);
this.metadataFlipList.add(Block.stairsNetherBrick.blockID); this.metadataFlipList.add(Block.stairsNetherBrick.blockID);
this.metadataFlipList.add(Block.stairsNetherQuartz.blockID); this.metadataFlipList.add(Block.stairsNetherQuartz.blockID);
this.metadataFlipList.add(Block.stairsSandStone.blockID); this.metadataFlipList.add(Block.stairsSandStone.blockID);
this.metadataNextList.add(Block.redstoneRepeaterIdle.blockID); this.metadataNextList.add(Block.redstoneRepeaterIdle.blockID);
this.metadataNextList.add(Block.redstoneRepeaterActive.blockID); this.metadataNextList.add(Block.redstoneRepeaterActive.blockID);
} }
public void registerDungeonTypeTags() public void registerDungeonTypeTags()
{ {
tagList.add("hub"); tagList.add("hub");
@ -257,6 +192,7 @@ public class DungeonHelper
tagList.add("deadEnd"); tagList.add("deadEnd");
tagList.add("maze"); tagList.add("maze");
} }
public void registerBaseDungeons() public void registerBaseDungeons()
{ {
this.hubs.add(new DungeonGenerator(0, "/schematics/4WayBasicHall.schematic", false)); this.hubs.add(new DungeonGenerator(0, "/schematics/4WayBasicHall.schematic", false));
@ -269,7 +205,6 @@ public class DungeonHelper
this.hubs.add(new DungeonGenerator(0, "/schematics/4WayHallExit.schematic", false)); this.hubs.add(new DungeonGenerator(0, "/schematics/4WayHallExit.schematic", false));
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/collapsedSingleTunnel1.schematic", false));
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/singleStraightHall1.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/smallBranchWithExit.schematic", false));
@ -279,7 +214,6 @@ public class DungeonHelper
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/simpleStairsDown.schematic", false)); this.simpleHalls.add(new DungeonGenerator(0, "/schematics/simpleStairsDown.schematic", false));
this.simpleHalls.add(new DungeonGenerator(0, "/schematics/simpleSmallT1.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/tntPuzzleTrap.schematic", false));
this.complexHalls.add(new DungeonGenerator(0, "/schematics/brokenPillarsO.schematic", true)); 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/buggyTopEntry1.schematic", true));
@ -289,7 +223,6 @@ public class DungeonHelper
this.complexHalls.add(new DungeonGenerator(0, "/schematics/ruinsO.schematic", true)); this.complexHalls.add(new DungeonGenerator(0, "/schematics/ruinsO.schematic", true));
this.complexHalls.add(new DungeonGenerator(0, "/schematics/pitStairs.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/azersDungeonO.schematic", false));
this.deadEnds.add(new DungeonGenerator(0, "/schematics/diamondTowerTemple1.schematic", true)); 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/fallingTrapO.schematic", false));
@ -302,37 +235,27 @@ public class DungeonHelper
this.deadEnds.add(new DungeonGenerator(0, "/schematics/smallDesert.schematic", true)); this.deadEnds.add(new DungeonGenerator(0, "/schematics/smallDesert.schematic", true));
this.deadEnds.add(new DungeonGenerator(0, "/schematics/smallPond.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/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/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/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/pistonFloorHall.schematic", false)); this.pistonTraps.add(new DungeonGenerator(0, "/schematics/pistonFloorHall.schematic", false));
// this.pistonTraps.add(new DungeonGenerator(0, "/schematics/pistonHallway.schematic", null));
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/pistonSmasherHall.schematic", false)); this.pistonTraps.add(new DungeonGenerator(0, "/schematics/pistonSmasherHall.schematic", false));
// this.pistonTraps.add(new DungeonGenerator(0, "/schematics/raceTheTNTHall.schematic", false));
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/simpleDropHall.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/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/fallingTNThall.schematic", false));
this.pistonTraps.add(new DungeonGenerator(0, "/schematics/lavaPyramid.schematic", true)); 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/smallMaze1.schematic", false));
this.mazes.add(new DungeonGenerator(0, "/schematics/smallMultilevelMaze.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/exitCube.schematic", true));
this.exits.add(new DungeonGenerator(0, "/schematics/lockingExitHall.schematic", false)); 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/smallExitPrison.schematic", true));
this.exits.add(new DungeonGenerator(0, "/schematics/lockingExitHall.schematic", false)); this.exits.add(new DungeonGenerator(0, "/schematics/lockingExitHall.schematic", false));
this.weightedDungeonGenList.addAll(this.simpleHalls); this.weightedDungeonGenList.addAll(this.simpleHalls);
this.weightedDungeonGenList.addAll(this.exits); this.weightedDungeonGenList.addAll(this.exits);
this.weightedDungeonGenList.addAll(this.pistonTraps); this.weightedDungeonGenList.addAll(this.pistonTraps);
@ -346,15 +269,12 @@ public class DungeonHelper
if(!this.registeredDungeons.contains(data)) if(!this.registeredDungeons.contains(data))
{ {
this.registeredDungeons.add(data); this.registeredDungeons.add(data);
} }
} }
} }
public DungeonGenerator exportDungeon(World world, int xI, int yI, int zI, String file) public DungeonGenerator exportDungeon(World world, int xI, int yI, int zI, String file)
{ {
int xMin; int xMin;
int yMin; int yMin;
int zMin; int zMin;
@ -401,9 +321,7 @@ public class DungeonHelper
short length= (short) (zMax-zMin); short length= (short) (zMax-zMin);
//ArrayList<NBTTagCompound> tileEntities = new ArrayList<NBTTagCompound>(); //ArrayList<NBTTagCompound> tileEntities = new ArrayList<NBTTagCompound>();
ArrayList<Tag> tileEntites = new ArrayList<Tag>();
ArrayList<Tag> tileEntites= new ArrayList<Tag>();
byte[] blocks = new byte[width * height * length]; byte[] blocks = new byte[width * height * length];
byte[] addBlocks = null; byte[] addBlocks = null;
byte[] blockData = new byte[width * height * length]; byte[] blockData = new byte[width * height * length];
@ -464,8 +382,6 @@ public class DungeonHelper
} }
**/ **/
} }
} }
} }
} }
@ -506,11 +422,9 @@ public class DungeonHelper
} }
this.registerCustomDungeon(new File(file)); this.registerCustomDungeon(new File(file));
return new DungeonGenerator(0,file,true); return new DungeonGenerator(0, file, true);
} }
public void generateDungeonlink(LinkData incoming) public void generateDungeonlink(LinkData incoming)
{ {
//DungeonGenerator dungeon = mod_pocketDim.registeredDungeons.get(new Random().nextInt(mod_pocketDim.registeredDungeons.size())); //DungeonGenerator dungeon = mod_pocketDim.registeredDungeons.get(new Random().nextInt(mod_pocketDim.registeredDungeons.size()));
@ -525,7 +439,6 @@ public class DungeonHelper
int count=10; int count=10;
try try
{ {
if(dimHelper.dimList.get(incoming.destDimID)!=null&&dimHelper.dimList.get(incoming.destDimID).dungeonGenerator!=null) if(dimHelper.dimList.get(incoming.destDimID)!=null&&dimHelper.dimList.get(incoming.destDimID).dungeonGenerator!=null)
{ {
mod_pocketDim.loader.init(incoming); mod_pocketDim.loader.init(incoming);
@ -561,11 +474,8 @@ public class DungeonHelper
{ {
flag=false; flag=false;
} }
} }
else if(depth<=3&&(deadEnds.contains(dungeon)||exits.contains(dungeon)||rand.nextBoolean())) else if (depth<=3&&(deadEnds.contains(dungeon)||exits.contains(dungeon)||rand.nextBoolean()))
{ {
if(rand.nextBoolean()) if(rand.nextBoolean())
{ {
@ -602,7 +512,6 @@ public class DungeonHelper
dungeon = hubs.get(rand.nextInt(hubs.size())); dungeon = hubs.get(rand.nextInt(hubs.size()));
} }
} }
else if(depthWeight-depthWeight/2>depth-4&&(deadEnds.contains(dungeon)||exits.contains(dungeon))) else if(depthWeight-depthWeight/2>depth-4&&(deadEnds.contains(dungeon)||exits.contains(dungeon)))
{ {
@ -641,7 +550,6 @@ public class DungeonHelper
dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size())); dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size()));
} }
} }
else else
{ {
@ -652,18 +560,17 @@ public class DungeonHelper
{ {
flag = false; flag = false;
} }
} }
while(!flag&&count>0); while (!flag && count > 0);
} }
else else
{ {
dungeon= defaultUp; dungeon = defaultUp;
} }
} }
catch(Exception e) catch (Exception e)
{ {
if(weightedDungeonGenList.size()>0) if (weightedDungeonGenList.size() > 0)
{ {
dungeon = weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size())); dungeon = weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size()));
} }
@ -673,22 +580,6 @@ public class DungeonHelper
return; return;
} }
} }
dimHelper.dimList.get(incoming.destDimID).dungeonGenerator = dungeon;
dimHelper.dimList.get(incoming.destDimID).dungeonGenerator=dungeon;
//loader.generateSchematic(incoming,0,0,0);
} }
} }