diff --git a/src/main/java/com/zixiken/dimdoors/shared/PocketRegistry.java b/src/main/java/com/zixiken/dimdoors/shared/PocketRegistry.java index bb6b294d..a7e4f11c 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/PocketRegistry.java +++ b/src/main/java/com/zixiken/dimdoors/shared/PocketRegistry.java @@ -7,7 +7,9 @@ package com.zixiken.dimdoors.shared; import com.zixiken.dimdoors.DDConfig; import com.zixiken.dimdoors.DimDoors; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -25,13 +27,17 @@ public class PocketRegistry { private int maxPocketSize; private int privatePocketSize; private int publicPocketSize; - private int nextUnusedID = -1; + private int nextUnusedID = 0; + private final Map privatePockets; //maps the UUID's of players to their private pocket's ID private final Map pocketList; //when adding any new variables, don't forget to add them to the write and load functions + private final List> pocketListsPerDepth; // Methods private PocketRegistry() { + privatePockets = new HashMap(); pocketList = new HashMap(); + pocketListsPerDepth = new ArrayList(); } public int getGridSize() { @@ -113,12 +119,11 @@ public class PocketRegistry { } public int getEntranceDoorIDOfNewPocket(EnumPocketType typeID, int depth) {//should return the riftID of the entrance door of the newly generated pocket - Location shortenedLocation = getGenerationlocation(nextUnusedID, typeID); + Location shortenedLocation = getGenerationlocation(nextUnusedID, typeID); //@todo, we should have different values of "nextUnusedID" for different pocket-types int x = shortenedLocation.getPos().getX(); int z = shortenedLocation.getPos().getZ(); Pocket pocket = generateRandomPocketAt(typeID, depth, shortenedLocation); - registerNewPocket(pocket); - nextUnusedID++; + registerNewPocket(pocket); //nextUnusedID++ int entranceDoorID = pocket.getEntranceDoorID(); return entranceDoorID; } @@ -135,7 +140,6 @@ public class PocketRegistry { int entranceDoorID = pocketPlacer.place(actualX, 0, actualZ, dimID); Pocket pocket = new Pocket(nextUnusedID, pocketPlacer.getSize(), depth, typeID, x, z, entranceDoorID); - return pocket; } @@ -161,7 +165,7 @@ public class PocketRegistry { return SchematicHandler.Instance.getPublicPocketSchematic(maxPocketSize); case DUNGEON: default: - return SchematicHandler.Instance.getRandomDungeonSchematic(depth, maxPocketSize); + return SchematicHandler.Instance.getRandomDungeonPocketTemplate(depth, maxPocketSize); } } diff --git a/src/main/java/com/zixiken/dimdoors/shared/PocketTemplate.java b/src/main/java/com/zixiken/dimdoors/shared/PocketTemplate.java index 09dba1ab..579e43a6 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/PocketTemplate.java +++ b/src/main/java/com/zixiken/dimdoors/shared/PocketTemplate.java @@ -23,7 +23,7 @@ import net.minecraft.world.World; */ class PocketTemplate { //there is exactly one pocket placer for each different schematic that is loaded into the game (a Json might load several schematics though) - private final int[] weights; + private final int[] weights; //weights for chanced generation of dungeons per depth level | weights[0] is the weight for depth "minDepth" private final int minDepth; private final int maxDepth; private final int size; @@ -57,6 +57,22 @@ class PocketTemplate { //there is exactly one pocket placer for each different s return size; } + int getMinDepth() { + return minDepth; + } + + int getMaxDepth() { + return maxDepth; + } + + int getWeight(int depth) { + int index = depth - minDepth; + if (index >= 0 && index < weights.length) { + return weights[index]; + } + return 0; //do not generate + } + int place(int xBase, int yBase, int zBase, int dimID) { //returns the riftID of the entrance DimDoor IBlockState outerWallBlock = ModBlocks.blockDimWall.getStateFromMeta(2); //@todo, does this return the correct wall? IBlockState innerWallBlock; @@ -186,5 +202,4 @@ class PocketTemplate { //there is exactly one pocket placer for each different s return EnumFacing.NORTH; } } - } diff --git a/src/main/java/com/zixiken/dimdoors/shared/SchematicHandler.java b/src/main/java/com/zixiken/dimdoors/shared/SchematicHandler.java index 5b7a65fb..d701bbaa 100644 --- a/src/main/java/com/zixiken/dimdoors/shared/SchematicHandler.java +++ b/src/main/java/com/zixiken/dimdoors/shared/SchematicHandler.java @@ -8,6 +8,7 @@ package com.zixiken.dimdoors.shared; import com.zixiken.dimdoors.DDConfig; import java.util.ArrayList; import java.util.List; +import java.util.Random; /** * @@ -28,8 +29,27 @@ public class SchematicHandler { return publicPocketSchematic; } - PocketTemplate getRandomDungeonSchematic(int depth, int maxPocketSize) { - + PocketTemplate getRandomDungeonPocketTemplate(int depth, int maxPocketSize) { + List validTemplates = new ArrayList(); + int totalWeight = 0; + for (PocketTemplate template : dungeonSchematics) { + if (template.getMinDepth() > depth || template.getMaxDepth() < depth) { + //do nothing + } else { + validTemplates.add(template); + totalWeight += template.getWeight(depth); + } + } + + Random random = new Random(); + int chosenTemplatePointer = random.nextInt(totalWeight); + for (PocketTemplate template : validTemplates) { + if (chosenTemplatePointer < 0) { + return template; + } + chosenTemplatePointer -= template.getWeight(depth); + } + return null; } public void loadSchematics() {