Changing plans about Pocket gen
-Added Schematic (loads itself) class to load and store schematic files in memory. -Removed dependency on Pillar mod Todo: -Code doesn't compile again
This commit is contained in:
parent
5c383bde1d
commit
732ceee40b
4 changed files with 164 additions and 17 deletions
|
@ -33,16 +33,8 @@ minecraft {
|
|||
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
|
||||
}
|
||||
|
||||
repositories {
|
||||
ivy {
|
||||
name "Pillar"
|
||||
artifactPattern "https://addons-origin.cursecdn.com/files/2318/492/[module]-[revision].[ext]"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.flowpowered:flow-math:1.0.3'
|
||||
compile name: 'Pillar', version: '1.0-5', ext: 'jar'
|
||||
}
|
||||
|
||||
processResources
|
||||
|
|
|
@ -19,8 +19,6 @@ import net.minecraft.util.Rotation;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import vazkii.pillar.schema.StructureSchema;
|
||||
import vazkii.pillar.StructureGenerator;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -29,7 +27,7 @@ import vazkii.pillar.StructureGenerator;
|
|||
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)
|
||||
|
||||
//generation parameters
|
||||
private StructureSchema schematic;
|
||||
private Schematic schematic;
|
||||
private final int size;
|
||||
private final int entranceDoorX;
|
||||
private final int entranceDoorY;
|
||||
|
@ -45,7 +43,7 @@ class PocketTemplate { //there is exactly one pocket placer for each different s
|
|||
private final int[] weights; //weights for chanced generation of dungeons per depth level | weights[0] is the weight for depth "minDepth"
|
||||
|
||||
//this class should contain the actual schematic info, as well as some of the Json info (placement of Rifts and stuff)
|
||||
public PocketTemplate(String variantName, StructureSchema schematic, int size, int entranceDoorX, int entranceDoorY, int entranceDoorZ, int wallThickness, int floorThickness, int roofThickness, EnumPocketType typeID,
|
||||
public PocketTemplate(String variantName, Schematic schematic, int size, int entranceDoorX, int entranceDoorY, int entranceDoorZ, int wallThickness, int floorThickness, int roofThickness, EnumPocketType typeID,
|
||||
int minDepth, int maxDepth, int[] weights) {
|
||||
this.variantName = variantName;
|
||||
this.weights = weights; //chance that this Pocket will get generated
|
||||
|
@ -95,11 +93,19 @@ class PocketTemplate { //there is exactly one pocket placer for each different s
|
|||
return schematic;
|
||||
}
|
||||
|
||||
void setSchematic(StructureSchema schematic) {
|
||||
void setSchematic(Schematic schematic) {
|
||||
this.schematic = schematic;
|
||||
}
|
||||
|
||||
int place(int xBase, int yBase, int zBase, int dimID) { //returns the riftID of the entrance DimDoor
|
||||
if (schematic == null) {
|
||||
DimDoors.log(this.getClass(), "The schematic for variant " + variantName + " somehow didn't load correctly against despite all precautions.");
|
||||
}
|
||||
//@todo make sure that the door tile entities get registered!
|
||||
|
||||
//String tileEntityID = tileEntityTagCompound.getString("id");
|
||||
|
||||
|
||||
IBlockState outerWallBlock = ModBlocks.blockDimWall.getStateFromMeta(2); //@todo, does this return the correct wall?
|
||||
IBlockState innerWallBlock;
|
||||
IBlockState entryDoorBlock;
|
||||
|
|
151
src/main/java/com/zixiken/dimdoors/shared/Schematic.java
Normal file
151
src/main/java/com/zixiken/dimdoors/shared/Schematic.java
Normal file
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.zixiken.dimdoors.shared;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
class Schematic {
|
||||
|
||||
int version;
|
||||
String author;
|
||||
String schematicName;
|
||||
long creationDate;
|
||||
String[] requiredMods;
|
||||
short width;
|
||||
short height;
|
||||
short length;
|
||||
int[] offset = new int[3];
|
||||
int paletteMax;
|
||||
List<IBlockState> pallette = new ArrayList();
|
||||
int[][][] blockData; //[x][y][z]
|
||||
List<NBTTagCompound> tileEntities = new ArrayList();
|
||||
|
||||
private Schematic() {
|
||||
}
|
||||
|
||||
Schematic loadFromNBT(NBTTagCompound nbt) {
|
||||
Schematic schematic = new Schematic();
|
||||
|
||||
schematic.version = nbt.getInteger("Version");
|
||||
NBTTagCompound metadataCompound = nbt.getCompoundTag("Metadata").getCompoundTag(".");
|
||||
schematic.author = metadataCompound.getString("Author");
|
||||
schematic.schematicName = metadataCompound.getString("Name");
|
||||
schematic.creationDate = metadataCompound.getInteger("Date");
|
||||
NBTTagList requiredModsTagList = ((NBTTagList) metadataCompound.getTag("RequiredMods"));
|
||||
schematic.requiredMods = new String[requiredModsTagList.tagCount()];
|
||||
for (int i = 0; i < requiredModsTagList.tagCount(); i++) {
|
||||
schematic.requiredMods[i] = requiredModsTagList.getStringTagAt(i);
|
||||
}
|
||||
|
||||
//@todo, check if the needed mods are loade; otherwise abort
|
||||
schematic.width = nbt.getShort("Width");
|
||||
schematic.height = nbt.getShort("Height");
|
||||
schematic.length = nbt.getShort("Length");
|
||||
schematic.offset = nbt.getIntArray("Offset");
|
||||
schematic.paletteMax = nbt.getInteger("PaletteMax");
|
||||
|
||||
NBTTagCompound paletteNBT = nbt.getCompoundTag("Palette");
|
||||
Map<Integer, String> paletteMap = new HashMap();
|
||||
for (String key : paletteNBT.getKeySet()) {
|
||||
int paletteID = paletteNBT.getInteger(key);
|
||||
paletteMap.put(paletteID, key); //basically use the reversed order
|
||||
}
|
||||
for (int i = 0; i <= schematic.paletteMax; i++) {
|
||||
String blockStateString = paletteMap.get(i);
|
||||
char lastBlockStateStringChar = blockStateString.charAt(blockStateString.length() - 1);
|
||||
String blockString;
|
||||
String stateString;
|
||||
if (lastBlockStateStringChar == ']') {
|
||||
String[] blockAndStateStrings = blockStateString.split("[");
|
||||
blockString = blockAndStateStrings[0];
|
||||
stateString = blockAndStateStrings[1];
|
||||
stateString = stateString.substring(0, stateString.length() - 1); //remove the "]" at the end
|
||||
} else {
|
||||
blockString = blockStateString;
|
||||
stateString = "";
|
||||
}
|
||||
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockString)); //@todo is this okay?
|
||||
|
||||
IBlockState blockstate = block.getDefaultState();
|
||||
if (!stateString.equals("")) {
|
||||
String[] properties = stateString.split(",");
|
||||
blockstate = getBlockStateWithProperties(block, properties); //@todo get the blockState from string
|
||||
} else {
|
||||
}
|
||||
pallette.add(blockstate);
|
||||
}
|
||||
|
||||
byte[] blockDataIntArray = nbt.getByteArray("BlockData");
|
||||
schematic.blockData = new int[schematic.width][schematic.height][schematic.length];
|
||||
for (int x = 0; x < schematic.width; x++) {
|
||||
for (int y = 0; y < schematic.height; y++) {
|
||||
for (int z = 0; z < schematic.length; z++) {
|
||||
schematic.blockData[x][y][z] = blockDataIntArray[x + z * schematic.width + y * schematic.width * schematic.length]; //according to the documentation on https://github.com/SpongePowered/Schematic-Specification/blob/master/versions/schematic-1.md
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagList tileEntitiesTagList = (NBTTagList) nbt.getTag("TileEntities");
|
||||
for (int i = 0; i < tileEntitiesTagList.tagCount(); i++) {
|
||||
NBTTagCompound tileEntityTagCompound = tileEntitiesTagList.getCompoundTagAt(i);
|
||||
schematic.tileEntities.add(tileEntityTagCompound);
|
||||
}
|
||||
|
||||
return schematic;
|
||||
}
|
||||
|
||||
private IBlockState getBlockStateWithProperties(Block block, String[] properties) {
|
||||
Map<String, String> propertyAndBlockStringsMap = new HashMap();
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
String propertyString = properties[i];
|
||||
String[] propertyAndBlockStrings = propertyString.split("=");
|
||||
String propertyName = propertyAndBlockStrings[0];
|
||||
String blockValue = propertyAndBlockStrings[1];
|
||||
propertyAndBlockStringsMap.put(propertyName, blockValue);
|
||||
}
|
||||
BlockStateContainer container = block.getBlockState();
|
||||
Collection<IBlockState> possibleBlockStates = container.getValidStates();
|
||||
|
||||
IBlockState chosenState = block.getDefaultState();
|
||||
for (IBlockState blockState : possibleBlockStates) {
|
||||
for (Entry<String, String> entry : propertyAndBlockStringsMap.entrySet()) {
|
||||
IProperty<?> property = container.getProperty(entry.getKey());
|
||||
if (property != null) {
|
||||
Comparable<?> value = null;
|
||||
for (Comparable<?> object : property.getAllowedValues()) {
|
||||
if (object.equals(entry.getValue())) {
|
||||
value = object;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (value != null) {
|
||||
chosenState = chosenState.withProperty((IProperty) property, (Comparable) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return chosenState;
|
||||
}
|
||||
}
|
|
@ -23,8 +23,6 @@ import java.util.Random;
|
|||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import vazkii.pillar.StructureLoader;
|
||||
import vazkii.pillar.schema.StructureSchema;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -70,7 +68,7 @@ public class SchematicHandler {
|
|||
}
|
||||
|
||||
public void loadSchematics() {
|
||||
//@todo, extend the Pillar StructureLoader, so we can load the structures from a different location?
|
||||
|
||||
StructureLoader.loadStructures(DimDoors.getDefWorld()); //@todo change this to get the DimDoors Dimension?
|
||||
personalPocketTemplate = loadTemplatesFromJson("defaultPersonal", PocketRegistry.Instance.getPrivatePocketSize()).get(0);
|
||||
publicPocketTemplate = loadTemplatesFromJson("defaultPublic", PocketRegistry.Instance.getPublicPocketSize()).get(0);
|
||||
|
@ -104,7 +102,7 @@ public class SchematicHandler {
|
|||
List<PocketTemplate> validTemplates = getAllValidVariations(jsonTemplate, maxPocketSize);
|
||||
|
||||
for (PocketTemplate template : validTemplates) { //it's okay to "tap" this for-loop, even if validTemplates is empty.
|
||||
StructureSchema schematic = StructureLoader.loadedSchemas.get(template.getName());
|
||||
Schematic schematic = StructureLoader.loadedSchemas.get(template.getName());
|
||||
template.setSchematic(schematic);
|
||||
//@todo make sure that the dungeon content fits inside the pocket walls (and floor and roof) and otherwise ¿crop it?
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue