Fixed crash when generating gateways
At @runemoro 's instruction: - Made replacePlaceholders static and need a Schematic parameter - Applied the replacePlaceholders method to Transient Portal gateway Schematics as well - Still, setting the gateway generation chance too high may force the gateways to be generated in each other's space, causing a crash on worldgen
This commit is contained in:
parent
773773f76d
commit
57bb0fbb79
4 changed files with 11 additions and 9 deletions
|
@ -69,7 +69,7 @@ public class DimDoors {
|
|||
@Mod.EventHandler
|
||||
public void onInitialization(FMLInitializationEvent event) {
|
||||
proxy.onInitialization(event);
|
||||
gatewayGenerator = new GatewayGenerator();
|
||||
gatewayGenerator = new GatewayGenerator(); //TODO put this in a proxy and structure this modularly instead of writing whole new classes per gateway type...
|
||||
GameRegistry.registerWorldGenerator(gatewayGenerator, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,16 +57,16 @@ public class PocketTemplate {
|
|||
}
|
||||
}
|
||||
|
||||
public void replacePlaceholders() { // TODO: it should be possible to place a schematic without replacing placeholders
|
||||
public static void replacePlaceholders(Schematic parSchematic) { // TODO: it should be possible to place a schematic without replacing placeholders
|
||||
// Replace placeholders (some schematics will contain them)
|
||||
List<NBTTagCompound> tileEntities = new ArrayList<>();
|
||||
for (NBTTagCompound tileEntityNBT : schematic.tileEntities) {
|
||||
for (NBTTagCompound tileEntityNBT : parSchematic.tileEntities) {
|
||||
if (tileEntityNBT.hasKey("placeholder")) {
|
||||
int x = tileEntityNBT.getInteger("x");
|
||||
int y = tileEntityNBT.getInteger("y");
|
||||
int z = tileEntityNBT.getInteger("z");
|
||||
|
||||
IBlockState state = schematic.palette.get(schematic.blockData[x][y][z]);
|
||||
IBlockState state = parSchematic.palette.get(parSchematic.blockData[x][y][z]);
|
||||
|
||||
NBTTagCompound newNBT;
|
||||
switch (tileEntityNBT.getString("placeholder")) {
|
||||
|
@ -115,11 +115,11 @@ public class PocketTemplate {
|
|||
tileEntities.add(tileEntityNBT);
|
||||
}
|
||||
}
|
||||
schematic.tileEntities = tileEntities;
|
||||
parSchematic.tileEntities = tileEntities;
|
||||
|
||||
|
||||
List<NBTTagCompound> entities = new ArrayList<>();
|
||||
for (NBTTagCompound entitiesNBT : schematic.entities) {
|
||||
for (NBTTagCompound entitiesNBT : parSchematic.entities) {
|
||||
if (entitiesNBT.hasKey("placeholder")) {
|
||||
double x = entitiesNBT.getDouble("x");
|
||||
double y = entitiesNBT.getDouble("y");
|
||||
|
@ -143,7 +143,7 @@ public class PocketTemplate {
|
|||
entities.add(entitiesNBT);
|
||||
}
|
||||
}
|
||||
schematic.entities = entities;
|
||||
parSchematic.entities = entities;
|
||||
}
|
||||
|
||||
public void place(Pocket pocket) {
|
||||
|
|
|
@ -82,7 +82,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
|
|||
try {
|
||||
Schematic schematic = Schematic.loadFromNBT(CompressedStreamTools.readCompressed(new FileInputStream(file)));
|
||||
PocketTemplate template = new PocketTemplate(SAVED_POCKETS_GROUP_NAME, file.getName(), null, null, null, schematic, -1, 0);
|
||||
template.replacePlaceholders();
|
||||
template.replacePlaceholders(schematic);
|
||||
templates.add(template);
|
||||
} catch (IOException e) {
|
||||
DimDoors.log.error("Error reading schematic " + file.getName() + ": " + e);
|
||||
|
@ -156,7 +156,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
|
|||
DimDoors.log.warn("Schematic " + template.getId() + " was bigger than specified in its json file and therefore wasn't loaded");
|
||||
}
|
||||
template.setSchematic(schematic);
|
||||
template.replacePlaceholders();
|
||||
template.replacePlaceholders(schematic);
|
||||
}
|
||||
return validTemplates;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.minecraft.world.World;
|
|||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.dimdev.dimdoors.shared.pockets.PocketTemplate;
|
||||
|
||||
public abstract class BaseSchematicGateway extends BaseGateway {
|
||||
private Schematic schematic;
|
||||
|
@ -35,6 +36,7 @@ public abstract class BaseSchematicGateway extends BaseGateway {
|
|||
try {
|
||||
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
|
||||
schematic = Schematic.loadFromNBT(schematicNBT);
|
||||
PocketTemplate.replacePlaceholders(schematic);
|
||||
schematicDataStream.close();
|
||||
} catch (IOException ex) {
|
||||
DimDoors.log.error("Schematic file for " + id + " could not be read as a valid schematic NBT file.", ex);
|
||||
|
|
Loading…
Add table
Reference in a new issue