下面列出了net.minecraft.util.ResourceLocation#getResourcePath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static Template getBuiltinTemplate(World world, ResourceLocation templateId) {
if (templateMap.containsKey(templateId)) {
return templateMap.get(templateId);
}
Template template = new Template();
String resourcePath = "/assets/" + templateId.getResourceDomain() + "/structures/" + templateId.getResourcePath() + ".nbt";
InputStream inputStream = TemplateManager.class.getResourceAsStream(resourcePath);
if (inputStream != null) {
try {
NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(inputStream);
if (!nbttagcompound.hasKey("DataVersion", 99)) {
nbttagcompound.setInteger("DataVersion", 500);
}
DataFixer dataFixer = world.getMinecraftServer().getDataFixer();
template.read(dataFixer.process(FixTypes.STRUCTURE, nbttagcompound));
} catch (IOException exception) {
GTLog.logger.error("Failed to load builtin template {}", templateId, exception);
} finally {
IOUtils.closeQuietly(inputStream);
}
} else {
GTLog.logger.warn("Failed to find builtin structure with path {}", resourcePath);
}
templateMap.put(templateId, template);
return template;
}
@Override
public IModel loadModel(ResourceLocation resourceLocation) {
String resourcePath = resourceLocation.getResourcePath();
/*if (!resourcePath.startsWith(SMART_MODEL_RESOURCE_LOCATION)) {
assert false : "loadModel expected " + SMART_MODEL_RESOURCE_LOCATION + " but found " + resourcePath;
}*/
String modelName = resourcePath;//.substring(SMART_MODEL_RESOURCE_LOCATION.length());
if (modelName.contains("rocketmotor")) {
return new ModelRocket();
} else {
try {
return ModelLoaderRegistry.getModel(new ResourceLocation(modelName));
} catch (Exception e) {
return ModelLoaderRegistry.getMissingModel();
}// ModelLoaderRegistry.getMissingModel();
}
}
@Override
public InputStream getInputStream(ResourceLocation location) throws IOException {
String resourcePath = location.getResourcePath(); // blockstates/compressed_1.json
resourcePath = resourcePath.substring(0, resourcePath.length() - 5); //remove .json
resourcePath = resourcePath.substring(12); //remove blockstates/
if (resourcePath.startsWith(blockNamePrefix)) {
Block block = Block.REGISTRY.getObject(new ResourceLocation(location.getResourceDomain(), resourcePath));
if (block != null && block != Blocks.AIR) {
return FileUtility.writeInputStream(fillSample(block, blockStateSample));
}
throw new IllegalArgumentException("Block not found: " + resourcePath);
}
throw new FileNotFoundException(location.toString());
}
@Override
public ResourceLocation func_152789_a(final MinecraftProfileTexture texture, final Type type, final SkinManager.SkinAvailableCallback callBack) {
if (type != Type.SKIN)
return super.func_152789_a(texture, type, callBack);
final boolean isSpecialCallBack = callBack instanceof ISkinDownloadCallback;
final ResourceLocation resLocationOld = new ResourceLocation("skins/" + texture.getHash());
final ResourceLocation resLocation = new ResourceLocation(Reference.MOD_ID, resLocationOld.getResourcePath());
ITextureObject itextureobject = textureManager.getTexture(resLocation);
if (itextureobject != null) {
if (callBack != null)
callBack.func_152121_a(type, resLocation);
} else {
File file1 = new File(skinFolder, texture.getHash().substring(0, 2));
File file2 = new File(file1, texture.getHash());
final NewImageBufferDownload imgDownload = new NewImageBufferDownload();
ITextureObject imgData = new NewThreadDownloadImageData(file2, texture.getUrl(), field_152793_a, imgDownload, resLocationOld, new IImageBuffer() {
@Override
public BufferedImage parseUserSkin(BufferedImage buffImg) {
if (buffImg != null)
PlayerModelManager.analyseTexture(buffImg, resLocation);
return imgDownload.parseUserSkin(buffImg);
}
@Override
public void func_152634_a() {
imgDownload.func_152634_a();
if (callBack != null)
callBack.func_152121_a(type, isSpecialCallBack ? resLocation : resLocationOld);
}
});
textureManager.loadTexture(resLocation, imgData);
textureManager.loadTexture(resLocationOld, imgData); // Avoid thrown exception if the image is requested before the download is done
}
return isSpecialCallBack ? resLocation : resLocationOld;
}
public static Template loadTemplate(ResourceLocation loc, WorldServer world, boolean allowNull)
{
boolean config = "/config/".equals(loc.getResourceDomain());
File file = new File(YUNoMakeGoodMap.instance.getStructFolder(), loc.getResourcePath() + ".nbt");
if (config && file.exists())
{
try
{
return loadTemplate(new FileInputStream(file));
}
catch (FileNotFoundException e) //literally cant happen but whatever..
{
e.printStackTrace();
return allowNull ? null : getDefault(world);
}
}
else
{
ResourceLocation res = config ? new ResourceLocation(YUNoMakeGoodMap.MODID + ":" + loc.getResourcePath()) : loc;
Template ret = loadTemplate(StructureLoader.class.getResourceAsStream("/assets/" + res.getResourceDomain() + "/structures/" + res.getResourcePath() + ".nbt")); //We're on the server we don't have Resource Packs.
if (ret != null)
return ret;
//Cant find it, lets load the one shipped with this mod.
(new FileNotFoundException(file.toString())).printStackTrace();
return allowNull ? null : getDefault(world);
}
}
public static String getPageForEntityClass(Class<? extends Entity> entityClass){
String page = entityPageEntries.get(entityClass);
if(page != null) {
return page;
} else {
ResourceLocation entityName = EntityList.getKey(entityClass);
return entityName == null ? null : "entity/" + entityName.getResourcePath();
}
}
public static NamespacedKey fromMinecraft(ResourceLocation minecraft) {
return new NamespacedKey(minecraft.getResourceDomain(), minecraft.getResourcePath());
}
@Override
public Asset toNova(ResourceLocation resource) {
return new Asset(resource.getResourceDomain(), resource.getResourcePath()) {};
}
public Texture toNovaTexture(ResourceLocation resource) {
return new Texture(resource.getResourceDomain(), resource.getResourcePath());
}
@Override
public Asset toNova(ResourceLocation resource) {
return new Asset(resource.getResourceDomain(), resource.getResourcePath());
}
public Texture toNovaTexture(ResourceLocation resource) {
return new Texture(resource.getResourceDomain(), resource.getResourcePath());
}
@Override
public Asset toNova(ResourceLocation resource) {
return new Asset(resource.getResourceDomain(), resource.getResourcePath());
}
public Asset toNovaTexture(ResourceLocation resource) {
return new Texture(resource.getResourceDomain(), resource.getResourcePath());
}
public Holder(ResourceLocation location) {
this.location = new ResourceLocation(location.getResourceDomain(), "hitboxes/" + location.getResourcePath() + ".json");
}