use of net.minecraft.client.renderer.block.model.VariantList in project MinecraftForge by MinecraftForge.
the class BlockStateLoader method load.
/**
* Loads a BlockStates json file.
* Will attempt to parse it as a Forge Enhanced version if possible.
* Will fall back to standard loading if marker is not present.
*
* Note: This method is NOT thread safe
*
* @param reader json read
* @param vanillaGSON ModelBlockDefinition's GSON reader.
*
* @return Model definition including variants for all known combinations.
*/
public static ModelBlockDefinition load(Reader reader, final Gson vanillaGSON) {
try {
byte[] data = IOUtils.toByteArray(reader);
reader = new InputStreamReader(new ByteArrayInputStream(data), Charsets.UTF_8);
// Read "forge_marker" to determine what to load.
Marker marker = GSON.fromJson(new String(data), Marker.class);
switch(marker.forge_marker) {
case // Version 1
1:
ForgeBlockStateV1 v1 = GSON.fromJson(reader, ForgeBlockStateV1.class);
Map<String, VariantList> variants = Maps.newHashMap();
for (Entry<String, Collection<ForgeBlockStateV1.Variant>> entry : v1.variants.asMap().entrySet()) {
// Convert Version1 variants into vanilla variants for the ModelBlockDefinition.
List<Variant> mcVars = Lists.newArrayList();
for (ForgeBlockStateV1.Variant var : entry.getValue()) {
boolean uvLock = var.getUvLock().or(false);
boolean smooth = var.getSmooth().or(true);
boolean gui3d = var.getGui3d().or(true);
int weight = var.getWeight().or(1);
if (var.getModel() != null && var.getSubmodels().size() == 0 && var.getTextures().size() == 0 && var.getCustomData().size() == 0 && var.getState().orNull() instanceof ModelRotation)
mcVars.add(new Variant(var.getModel(), (ModelRotation) var.getState().get(), uvLock, weight));
else
mcVars.add(new ForgeVariant(var.getModel(), var.getState().or(TRSRTransformation.identity()), uvLock, smooth, gui3d, weight, var.getTextures(), var.getOnlyPartsVariant(), var.getCustomData()));
}
variants.put(entry.getKey(), new VariantList(mcVars));
}
return new ModelBlockDefinition(variants, null);
default:
//Unknown version.. try loading it as normal.
return vanillaGSON.fromJson(reader, ModelBlockDefinition.class);
}
} catch (IOException e) {
Throwables.propagate(e);
}
return null;
}
Aggregations