Java Code Examples for net.minecraft.util.ResourceLocation#getResourcePath()

The following examples show how to use net.minecraft.util.ResourceLocation#getResourcePath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateManager.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: ModelLoader.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@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();
	}
}
 
Example 3
Source File: AbstractBlockModelFactory.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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());
}
 
Example 4
Source File: NewSkinManager.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@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;
}
 
Example 5
Source File: StructureUtil.java    From YUNoMakeGoodMap with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 6
Source File: WikiRegistry.java    From IGW-mod with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 7
Source File: CraftNamespacedKey.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public static NamespacedKey fromMinecraft(ResourceLocation minecraft) {
    return new NamespacedKey(minecraft.getResourceDomain(), minecraft.getResourcePath());
}
 
Example 8
Source File: AssetConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Asset toNova(ResourceLocation resource) {
	return new Asset(resource.getResourceDomain(), resource.getResourcePath()) {};
}
 
Example 9
Source File: AssetConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Texture toNovaTexture(ResourceLocation resource) {
	return new Texture(resource.getResourceDomain(), resource.getResourcePath());
}
 
Example 10
Source File: AssetConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Asset toNova(ResourceLocation resource) {
	return new Asset(resource.getResourceDomain(), resource.getResourcePath());
}
 
Example 11
Source File: AssetConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Texture toNovaTexture(ResourceLocation resource) {
	return new Texture(resource.getResourceDomain(), resource.getResourcePath());
}
 
Example 12
Source File: AssetConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Asset toNova(ResourceLocation resource) {
	return new Asset(resource.getResourceDomain(), resource.getResourcePath());
}
 
Example 13
Source File: AssetConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Asset toNovaTexture(ResourceLocation resource) {
	return new Texture(resource.getResourceDomain(), resource.getResourcePath());
}
 
Example 14
Source File: HitboxManager.java    From OpenModsLib with MIT License 4 votes vote down vote up
public Holder(ResourceLocation location) {
	this.location = new ResourceLocation(location.getResourceDomain(), "hitboxes/" + location.getResourcePath() + ".json");
}