package StevenDimDoors.mod_pocketDim.helpers; import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DungeonGenerator; 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; import StevenDimDoors.mod_pocketDim.helpers.jnbt.NBTOutputStream; import StevenDimDoors.mod_pocketDim.helpers.jnbt.ShortTag; /** * @Return */ public class DungeonHelper { public DungeonHelper() { } private Random rand = new Random(); public HashMap customDungeonStatus = new HashMap(); public ArrayList customDungeons = new ArrayList(); public ArrayList registeredDungeons = new ArrayList(); public ArrayList weightedDungeonGenList = new ArrayList(); public ArrayList simpleHalls = new ArrayList(); public ArrayList complexHalls = new ArrayList(); public ArrayList deadEnds = new ArrayList(); public ArrayList hubs = new ArrayList(); public ArrayList mazes = new ArrayList(); public ArrayList pistonTraps = new ArrayList(); public ArrayList exits = new ArrayList(); public ArrayList metadataFlipList = new ArrayList(); public ArrayList metadataNextList = new ArrayList(); public DungeonGenerator defaultUp = new DungeonGenerator(0, "/schematic/simpleStairsUp.schematic", true); public void registerCustomDungeon(File schematicFile) { try { if(schematicFile.getName().contains(".schematic")) { String[] name = schematicFile.getName().split("_"); if(name.length<4) { System.out.println("Importing custom dungeon gen mechanics failed, adding to secondary list"); this.customDungeons.add(new DungeonGenerator(0,schematicFile.getAbsolutePath(),true)); System.out.println("Imported "+schematicFile.getName()); } else { int count=0; boolean open= name[2].equals("open"); int weight = Integer.parseInt(name[3].replace(".schematic", "")); String path = schematicFile.getAbsolutePath(); while(count 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; } } } /** * * this.nbtdata.setShort("Width", width); this.nbtdata.setShort("Height", height); this.nbtdata.setShort("Length", length); this.nbtdata.setByteArray("Blocks", blocks); this.nbtdata.setByteArray("Data", blockData); */ HashMap schematic = new HashMap(); schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); schematic.put("Data", new ByteArrayTag("Data", blockData)); schematic.put("Width", new ShortTag("Width", (short) width)); schematic.put("Length", new ShortTag("Length", (short) length)); schematic.put("Height", new ShortTag("Height", (short) height)); if (addBlocks != null) { 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); } public void generateDungeonlink(LinkData incoming) { //DungeonGenerator dungeon = mod_pocketDim.registeredDungeons.get(new Random().nextInt(mod_pocketDim.registeredDungeons.size())); DungeonGenerator dungeon; int depth = dimHelper.instance.getDimDepth(incoming.locDimID)+2; int depthWeight = rand.nextInt(depth)+rand.nextInt(depth)-2; depth=depth-2; // DungeonGenerator 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; } if(incoming.destYCoord>15) { do { count--; flag = true; dungeon = this.weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size())); if(depth<=1) { if(rand.nextBoolean()) { dungeon = complexHalls.get(rand.nextInt(complexHalls.size())); } else if(rand.nextBoolean()) { dungeon = hubs.get(rand.nextInt(hubs.size())); } else if(rand.nextBoolean()) { dungeon = hubs.get(rand.nextInt(hubs.size())); } 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())); } else if(rand.nextBoolean()) { dungeon = mazes.get(rand.nextInt(mazes.size())); } else if(rand.nextBoolean()) { dungeon = pistonTraps.get(rand.nextInt(pistonTraps.size())); } 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())); } else if(depth<4) { dungeon = hubs.get(rand.nextInt(hubs.size())); } } else if(depthWeight-depthWeight/2>depth-4&&(deadEnds.contains(dungeon)||exits.contains(dungeon))) { 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; } } else if(depthWeight>7&&hubs.contains(dungeon)) { if(rand.nextInt(12)+510&&hubs.contains(dungeon)) { flag = false; } } while(!flag&&count>0); } else { dungeon= defaultUp; } } catch(Exception e) { if(weightedDungeonGenList.size()>0) { dungeon = weightedDungeonGenList.get(rand.nextInt(weightedDungeonGenList.size())); } else { e.printStackTrace(); return; } } dimHelper.dimList.get(incoming.destDimID).dungeonGenerator=dungeon; //loader.generateSchematic(incoming,0,0,0); } }