下面列出了net.minecraft.util.ResourceLocation#getPath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public IModel loadModel(ResourceLocation modelLocation) throws Exception {
String path = modelLocation.getPath();
if ("builtin/generated".equals(path) || "block/builtin/generated".equals(path) || "item/builtin/generated".equals(path)) { // TODO: why is this necessary?
return ItemLayerModel.INSTANCE; //new VanillaModelWrapper(modelLocation, MODEL_GENERATED);
}
if ("builtin/entity".equals(path)) {
return new VanillaModelWrapper(modelLocation, MODEL_ENTITY);
}
if ("builtin/missing".equals(path)) {
return WRAPPED_MODEL_MISSING;
}
throw new FileNotFoundException(modelLocation.toString());
}
@Override
public IModel loadModel(ResourceLocation modelLocation) throws Exception {
// Load vanilla model
ModelBlock vanillaModel;
ResourceLocation vanillaModelLocation = new ResourceLocation(modelLocation.getNamespace(), modelLocation.getPath() + ".json");
try (IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(vanillaModelLocation);
Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) {
vanillaModel = ModelBlock.deserialize(reader);
vanillaModel.name = modelLocation.toString();
}
// Load armature animation (currently disabled for efficiency, see MixinModelBlockAnimation)
String modelPath = modelLocation.getPath();
if (modelPath.startsWith("models/")) {
modelPath = modelPath.substring("models/".length());
}
ResourceLocation armatureLocation = new ResourceLocation(modelLocation.getNamespace(), "armatures/" + modelPath + ".json");
ModelBlockAnimation animation = ModelBlockAnimation.loadVanillaAnimation(Minecraft.getMinecraft().getResourceManager(), armatureLocation);
// Return the vanilla model weapped in a VanillaModelWrapper
return new VanillaModelWrapper(modelLocation, vanillaModel , false, animation);
}
public TemplateEnderUtilities getTemplate(ResourceLocation id)
{
String s = id.getPath();
if (this.templates.containsKey(s))
{
return this.templates.get(s);
}
this.readTemplate(id);
if (this.templates.containsKey(s))
{
return this.templates.get(s);
}
TemplateEnderUtilities template = new TemplateEnderUtilities();
this.templates.put(s, template);
return template;
}
public TemplateMetadata getTemplateMetadata(ResourceLocation rl)
{
String s = rl.getPath();
if (this.templateMetas.containsKey(s))
{
return this.templateMetas.get(s);
}
this.readTemplateMetadata(rl);
if (this.templateMetas.containsKey(s))
{
return this.templateMetas.get(s);
}
TemplateMetadata templateMeta = new TemplateMetadata();
this.templateMetas.put(s, templateMeta);
return templateMeta;
}
private ModelBlockDefinition getModelBlockDefinition(ResourceLocation location) {
ResourceLocation simpleLocation = new ResourceLocation(location.getNamespace(), location.getPath());
try {
return modelBlockDefinitionCache.get(simpleLocation, () -> loadModelBlockDefinition(simpleLocation));
} catch (ExecutionException e) {
throw new RuntimeException(e.getCause());
}
}
private ModelBlockDefinition loadModelBlockDefinition(ResourceLocation location) {
ResourceLocation blockstateLocation = new ResourceLocation(location.getNamespace(), "blockstates/" + location.getPath() + ".json");
List<ModelBlockDefinition> list = Lists.newArrayList();
try {
for (IResource resource : Minecraft.getMinecraft().getResourceManager().getAllResources(blockstateLocation)) {
list.add(loadModelBlockDefinition(location, resource));
}
} catch (IOException e) {
throw new RuntimeException("Encountered an exception when loading model definition of model " + blockstateLocation, e);
}
return new ModelBlockDefinition(list);
}
private ResourceLocation getActualLocation(ResourceLocation location) {
if (location instanceof ModelResourceLocation) {
return location;
}
if (location.getPath().startsWith("builtin/") ||
location.getPath().startsWith("block/builtin/") ||
location.getPath().startsWith("item/builtin/")) { // TODO: why is this necessary
return location;
}
return new ResourceLocation(location.getNamespace(), "models/" + location.getPath());
}
public static ResourceLocation getItemLocation(String location) {
ResourceLocation resourcelocation = new ResourceLocation(location.replaceAll("#.*", ""));
return new ResourceLocation(resourcelocation.getNamespace(), "item/" + resourcelocation.getPath());
}
public boolean writeTemplate(ResourceLocation id)
{
String fileName = id.getPath();
if (this.templates.containsKey(fileName) == false)
{
return false;
}
else
{
if (this.directory.exists() == false)
{
if (this.directory.mkdirs() == false)
{
return false;
}
}
else if (this.directory.isDirectory() == false)
{
return false;
}
final File templateFile = new File(this.directory, fileName + ".nbt");
final NBTTagCompound nbt = new NBTTagCompound();
final TemplateEnderUtilities template = this.templates.get(fileName);
template.write(nbt);
ThreadedFileIOBase.getThreadedIOInstance().queueIO(() ->
{
try
{
OutputStream outputStream = new FileOutputStream(templateFile);
CompressedStreamTools.writeCompressed(nbt, outputStream);
outputStream.close();
}
catch (IOException e)
{
EnderUtilities.logger.warn("Failed to write template to file '{}'", templateFile, e);
}
return false;
});
return true;
}
}
protected File getTemplateMetadataFile(ResourceLocation rl)
{
return new File(this.directory, rl.getPath() + "_meta.nbt");
}
public boolean writeTemplateMetadata(ResourceLocation rl)
{
String fileName = rl.getPath();
if (this.templateMetas.containsKey(fileName) == false)
{
return false;
}
else
{
if (this.directory.exists() == false)
{
if (this.directory.mkdirs() == false)
{
return false;
}
}
else if (this.directory.isDirectory() == false)
{
return false;
}
final File templateFile = new File(this.directory, fileName + "_meta.nbt");
final NBTTagCompound nbt = new NBTTagCompound();
final TemplateMetadata templateMeta = this.templateMetas.get(fileName);
templateMeta.write(nbt);
ThreadedFileIOBase.getThreadedIOInstance().queueIO(() ->
{
try
{
OutputStream outputStream = new FileOutputStream(templateFile);
CompressedStreamTools.writeCompressed(nbt, outputStream);
outputStream.close();
}
catch (IOException e)
{
EnderUtilities.logger.warn("Failed to write template metadata to file '{}'", templateFile);
}
return false;
});
return true;
}
}