fix to handle invalid structures with invalid boxes.
This commit is contained in:
1 parent
6206753198
commit
45e3abf19c
3 files changed
+23
-9
No files matched your search
@@ -685,7 +685,7 @@ making it preferred for scoping ungenerated terrain, but it takes some compute r
|
|||||||
Unlike `'structure'` this will return a tentative structure location. Random factors in world generation may prevent
|
Unlike `'structure'` this will return a tentative structure location. Random factors in world generation may prevent
|
||||||
the actual structure from forming.
|
the actual structure from forming.
|
||||||
|
|
||||||
If structure is specified, it will return `null` if a chunk is not eligible, `true` if the structure should appear, or
|
If structure is specified, it will return `null` if a chunk is not eligible or invalid, `true` if the structure should appear, or
|
||||||
a map with two values: `'box'` for a pair of coordinates indicating bounding box of the structure, and `'pieces'` for
|
a map with two values: `'box'` for a pair of coordinates indicating bounding box of the structure, and `'pieces'` for
|
||||||
list of elements of the structure (as a tuple), with its name, direction, and box coordinates of the piece.
|
list of elements of the structure (as a tuple), with its name, direction, and box coordinates of the piece.
|
||||||
|
|
||||||
@@ -702,7 +702,7 @@ the first case it returns a map of structures at a given position, keyed by stru
|
|||||||
the bounding box of the structure - a pair of two 3-value coords (see examples). When called with an extra structure
|
the bounding box of the structure - a pair of two 3-value coords (see examples). When called with an extra structure
|
||||||
name, returns a map with two values, `'box'` for bounding box of the structure, and `'pieces'` for a list of
|
name, returns a map with two values, `'box'` for bounding box of the structure, and `'pieces'` for a list of
|
||||||
components for that structure, with their name, direction and two sets of coordinates
|
components for that structure, with their name, direction and two sets of coordinates
|
||||||
indicating the bounding box of the structure piece.
|
indicating the bounding box of the structure piece. If structure is invalid, its data will be `null`.
|
||||||
|
|
||||||
Requires a `Standard Structure` name (see above).
|
Requires a `Standard Structure` name (see above).
|
||||||
|
|
||||||
|
|||||||
@@ -1128,7 +1128,17 @@ public class WorldAccess {
|
|||||||
Map<Value, Value> ret = new HashMap<>();
|
Map<Value, Value> ret = new HashMap<>();
|
||||||
for(StructureFeature<?> str : StructureFeature.STRUCTURES.values())
|
for(StructureFeature<?> str : StructureFeature.STRUCTURES.values())
|
||||||
{
|
{
|
||||||
StructureStart start = FeatureGenerator.shouldStructureStartAt(world, pos, str, needSize);
|
StructureStart<?> start;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
start = FeatureGenerator.shouldStructureStartAt(world, pos, str, needSize);
|
||||||
|
}
|
||||||
|
catch (NullPointerException npe)
|
||||||
|
{
|
||||||
|
CarpetSettings.LOG.error("Failed to detect structure: "+str.getName());
|
||||||
|
start = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (start == null) continue;
|
if (start == null) continue;
|
||||||
|
|
||||||
Value key = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_FEATURE.getId(str)));
|
Value key = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_FEATURE.getId(str)));
|
||||||
|
|||||||
@@ -299,10 +299,19 @@ public class ValueConversions
|
|||||||
public static Value of(StructureStart<?> structure)
|
public static Value of(StructureStart<?> structure)
|
||||||
{
|
{
|
||||||
if (structure == null || structure == StructureStart.DEFAULT) return Value.NULL;
|
if (structure == null || structure == StructureStart.DEFAULT) return Value.NULL;
|
||||||
|
BlockBox boundingBox = structure.getBoundingBox();
|
||||||
|
if (boundingBox.maxX < boundingBox.minX || boundingBox.maxY < boundingBox.minY || boundingBox.maxZ < boundingBox.minZ) return Value.NULL;
|
||||||
|
Map<Value, Value> ret = new HashMap<>();
|
||||||
|
ret.put(new StringValue("box"), ListValue.of(
|
||||||
|
ListValue.fromTriple(boundingBox.minX, boundingBox.minY, boundingBox.minZ),
|
||||||
|
ListValue.fromTriple(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ)
|
||||||
|
));
|
||||||
List<Value> pieces = new ArrayList<>();
|
List<Value> pieces = new ArrayList<>();
|
||||||
for (StructurePiece piece : structure.getChildren())
|
for (StructurePiece piece : structure.getChildren())
|
||||||
{
|
{
|
||||||
BlockBox box = piece.getBoundingBox();
|
BlockBox box = piece.getBoundingBox();
|
||||||
|
if (box.maxX >= box.minX && box.maxY >= box.minY && box.maxZ >= box.minZ)
|
||||||
|
{
|
||||||
pieces.add(ListValue.of(
|
pieces.add(ListValue.of(
|
||||||
new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_PIECE.getId(piece.getType()))),
|
new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_PIECE.getId(piece.getType()))),
|
||||||
(piece.getFacing() == null) ? Value.NULL : new StringValue(piece.getFacing().getName()),
|
(piece.getFacing() == null) ? Value.NULL : new StringValue(piece.getFacing().getName()),
|
||||||
@@ -310,12 +319,7 @@ public class ValueConversions
|
|||||||
ListValue.fromTriple(box.maxX, box.maxY, box.maxZ)
|
ListValue.fromTriple(box.maxX, box.maxY, box.maxZ)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
BlockBox boundingBox = structure.getBoundingBox();
|
}
|
||||||
Map<Value, Value> ret = new HashMap<>();
|
|
||||||
ret.put(new StringValue("box"), ListValue.of(
|
|
||||||
ListValue.fromTriple(boundingBox.minX, boundingBox.minY, boundingBox.minZ),
|
|
||||||
ListValue.fromTriple(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ)
|
|
||||||
));
|
|
||||||
ret.put(new StringValue("pieces"), ListValue.wrap(pieces));
|
ret.put(new StringValue("pieces"), ListValue.wrap(pieces));
|
||||||
return MapValue.wrap(ret);
|
return MapValue.wrap(ret);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user