Fix render error when loading resource-variants with no successfully loaded models
This commit is contained in:
parent
fe3f8eb53e
commit
9427c1cc58
|
@ -104,7 +104,7 @@ public class BukkitPlugin extends JavaPlugin implements ServerInterface {
|
|||
if (worldFolder.equals(world.getWorldFolder().getCanonicalFile())) return world.getUID();
|
||||
}
|
||||
|
||||
throw new IOException("There is no world with this folder loaded: " + worldFolder.getCanonicalPath());
|
||||
throw new IOException("There is no world with this folder loaded: " + worldFolder.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -83,9 +83,8 @@ public class HiresModelRenderer {
|
|||
} catch (NoSuchResourceException e2) {
|
||||
e.addSuppressed(e2);
|
||||
blockModel = new BlockStateModel();
|
||||
}
|
||||
|
||||
Logger.global.noFloodDebug(block.getBlockState().getFullId() + "-hiresModelRenderer-blockmodelerr", "Failed to create BlockModel for BlockState: " + block.getBlockState() + " (" + e.toString() + ")");
|
||||
}
|
||||
//Logger.global.noFloodDebug(block.getBlockState().getFullId() + "-hiresModelRenderer-blockmodelerr", "Failed to create BlockModel for BlockState: " + block.getBlockState() + " (" + e.toString() + ")");
|
||||
}
|
||||
|
||||
blockModel.translate(new Vector3f(x, y, z).sub(modelMin.toFloat()));
|
||||
|
|
|
@ -66,7 +66,7 @@ public class BlockStateResource {
|
|||
Variant allMatch = null;
|
||||
for (Variant variant : variants) {
|
||||
if (variant.condition.matches(blockState)) {
|
||||
if (variant.condition instanceof All) { //only use "all" conditioned if nothing else matched
|
||||
if (variant.condition instanceof All) { //only use "all" condition if nothing else matched
|
||||
if (allMatch == null) allMatch = variant;
|
||||
continue;
|
||||
}
|
||||
|
@ -106,16 +106,21 @@ public class BlockStateResource {
|
|||
}
|
||||
|
||||
public TransformedBlockModelResource getModel(Vector3i pos) {
|
||||
if (models.isEmpty()) throw new IllegalStateException("A variant must have at least one model!");
|
||||
|
||||
double selection = MathUtils.hashToFloat(pos, 827364) * totalWeight; // random based on position
|
||||
for (Weighted<TransformedBlockModelResource> w : models) {
|
||||
selection -= w.weight;
|
||||
if (selection < 0)
|
||||
return w.value;
|
||||
if (selection <= 0) return w.value;
|
||||
}
|
||||
|
||||
throw new RuntimeException("This line should never be reached!");
|
||||
}
|
||||
|
||||
public void checkValid() throws ParseResourceException {
|
||||
if (models.isEmpty()) throw new ParseResourceException("A variant must have at least one model!");
|
||||
}
|
||||
|
||||
public void updateTotalWeight() {
|
||||
totalWeight = 0d;
|
||||
for (Weighted<?> w : models) {
|
||||
|
@ -178,10 +183,11 @@ public class BlockStateResource {
|
|||
variant.models = loadModels(transformedModelNode, blockstateFile, null);
|
||||
|
||||
variant.updateTotalWeight();
|
||||
variant.checkValid();
|
||||
|
||||
blockState.variants.add(variant);
|
||||
} catch (Exception ex) {
|
||||
Logger.global.logWarning("Failed to parse a variant of " + blockstateFile + ": " + ex);
|
||||
} catch (Throwable t) {
|
||||
Logger.global.logWarning("Failed to parse a variant of " + blockstateFile + ": " + t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,10 +202,11 @@ public class BlockStateResource {
|
|||
variant.models = loadModels(partNode.getNode("apply"), blockstateFile, null);
|
||||
|
||||
variant.updateTotalWeight();
|
||||
variant.checkValid();
|
||||
|
||||
blockState.multipart.add(variant);
|
||||
} catch (Exception ex) {
|
||||
Logger.global.logWarning("Failed to parse a multipart-part of " + blockstateFile + ": " + ex);
|
||||
} catch (Throwable t) {
|
||||
Logger.global.logWarning("Failed to parse a multipart-part of " + blockstateFile + ": " + t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -360,7 +367,14 @@ public class BlockStateResource {
|
|||
}
|
||||
|
||||
variant.updateTotalWeight();
|
||||
blockState.variants.add(variant);
|
||||
|
||||
try {
|
||||
variant.checkValid();
|
||||
blockState.variants.add(variant);
|
||||
} catch (ParseResourceException ex) {
|
||||
Logger.global.logWarning("Failed to parse a variant (forge/property) of " + blockstateFile + ": " + ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//create default straight variant
|
||||
|
@ -386,7 +400,14 @@ public class BlockStateResource {
|
|||
}
|
||||
|
||||
variant.updateTotalWeight();
|
||||
blockState.variants.add(variant);
|
||||
|
||||
try {
|
||||
variant.checkValid();
|
||||
blockState.variants.add(variant);
|
||||
} catch (ParseResourceException ex) {
|
||||
Logger.global.logWarning("Failed to parse a variant (forge/straight) of " + blockstateFile + ": " + ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return blockState;
|
||||
|
|
Loading…
Reference in New Issue