Dungeon Pocket Template Randomisation

-Changed some method names
-Fixed a mistake in registering a new pocket upon generation
-Added some get functions for privates
-Implemented functionality for randomising what dungeon pocket may be
generated upon entering an unlinked DimDoor.

Todo:
-Still the same
This commit is contained in:
Mathijs Riezebos 2017-01-22 17:28:16 +01:00
parent 82b05010c3
commit 88dbcf152a
3 changed files with 49 additions and 10 deletions

View file

@ -7,7 +7,9 @@ package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.DDConfig; import com.zixiken.dimdoors.DDConfig;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
@ -25,13 +27,17 @@ public class PocketRegistry {
private int maxPocketSize; private int maxPocketSize;
private int privatePocketSize; private int privatePocketSize;
private int publicPocketSize; private int publicPocketSize;
private int nextUnusedID = -1; private int nextUnusedID = 0;
private final Map<String, Integer> privatePockets; //maps the UUID's of players to their private pocket's ID
private final Map<Integer, Pocket> pocketList; private final Map<Integer, Pocket> pocketList;
//when adding any new variables, don't forget to add them to the write and load functions //when adding any new variables, don't forget to add them to the write and load functions
private final List<Map<Integer, Pocket>> pocketListsPerDepth;
// Methods // Methods
private PocketRegistry() { private PocketRegistry() {
privatePockets = new HashMap();
pocketList = new HashMap(); pocketList = new HashMap();
pocketListsPerDepth = new ArrayList();
} }
public int getGridSize() { 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 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 x = shortenedLocation.getPos().getX();
int z = shortenedLocation.getPos().getZ(); int z = shortenedLocation.getPos().getZ();
Pocket pocket = generateRandomPocketAt(typeID, depth, shortenedLocation); Pocket pocket = generateRandomPocketAt(typeID, depth, shortenedLocation);
registerNewPocket(pocket); registerNewPocket(pocket); //nextUnusedID++
nextUnusedID++;
int entranceDoorID = pocket.getEntranceDoorID(); int entranceDoorID = pocket.getEntranceDoorID();
return entranceDoorID; return entranceDoorID;
} }
@ -135,7 +140,6 @@ public class PocketRegistry {
int entranceDoorID = pocketPlacer.place(actualX, 0, actualZ, dimID); int entranceDoorID = pocketPlacer.place(actualX, 0, actualZ, dimID);
Pocket pocket = new Pocket(nextUnusedID, pocketPlacer.getSize(), depth, typeID, x, z, entranceDoorID); Pocket pocket = new Pocket(nextUnusedID, pocketPlacer.getSize(), depth, typeID, x, z, entranceDoorID);
return pocket; return pocket;
} }
@ -161,7 +165,7 @@ public class PocketRegistry {
return SchematicHandler.Instance.getPublicPocketSchematic(maxPocketSize); return SchematicHandler.Instance.getPublicPocketSchematic(maxPocketSize);
case DUNGEON: case DUNGEON:
default: default:
return SchematicHandler.Instance.getRandomDungeonSchematic(depth, maxPocketSize); return SchematicHandler.Instance.getRandomDungeonPocketTemplate(depth, maxPocketSize);
} }
} }

View file

@ -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) 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 minDepth;
private final int maxDepth; private final int maxDepth;
private final int size; private final int size;
@ -57,6 +57,22 @@ class PocketTemplate { //there is exactly one pocket placer for each different s
return size; 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 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 outerWallBlock = ModBlocks.blockDimWall.getStateFromMeta(2); //@todo, does this return the correct wall?
IBlockState innerWallBlock; IBlockState innerWallBlock;
@ -186,5 +202,4 @@ class PocketTemplate { //there is exactly one pocket placer for each different s
return EnumFacing.NORTH; return EnumFacing.NORTH;
} }
} }
} }

View file

@ -8,6 +8,7 @@ package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.DDConfig; import com.zixiken.dimdoors.DDConfig;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
/** /**
* *
@ -28,8 +29,27 @@ public class SchematicHandler {
return publicPocketSchematic; return publicPocketSchematic;
} }
PocketTemplate getRandomDungeonSchematic(int depth, int maxPocketSize) { PocketTemplate getRandomDungeonPocketTemplate(int depth, int maxPocketSize) {
List<PocketTemplate> 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() { public void loadSchematics() {