net.minecraft.client.resources.IResource Java Examples

The following examples show how to use net.minecraft.client.resources.IResource. 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: RenderUtility.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void preInit(FMLPreInitializationEvent event) {
	//Load models
	Game.render().modelProviders.forEach(m -> {
		ResourceLocation resource = new ResourceLocation(m.domain, "models/" + m.name + "." + m.getType());
		try {
			IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
			m.load(res.getInputStream());
		} catch (IOException e) {
			throw new RuntimeException("IO Exception reading model format", e);
		}
	});
}
 
Example #2
Source File: LocatedTexture.java    From IGW-mod with GNU General Public License v2.0 6 votes vote down vote up
public LocatedTexture(ResourceLocation texture, int x, int y, double scale){
    this(texture, x, y, 0, 0);
    try {
        BufferedImage bufferedimage;
        if(texture.getResourcePath().startsWith("server")) {
            bufferedimage = ImageIO.read(new FileInputStream(new File(IGWMod.proxy.getSaveLocation() + File.separator + "igwmod" + File.separator + texture.getResourcePath().substring(7))));
        } else {
            IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(texture);
            InputStream inputstream = iresource.getInputStream();
            bufferedimage = ImageIO.read(inputstream);
        }
        width = (int)(bufferedimage.getWidth() * scale);
        height = (int)(bufferedimage.getHeight() * scale);
    } catch(Exception e) {
        e.printStackTrace();
    }
}
 
Example #3
Source File: HitboxManager.java    From OpenModsLib with MIT License 6 votes vote down vote up
private List<Hitbox> load(ResourceLocation location) {
	final List<Hitbox> result = Lists.newArrayList();
	if (resourceManager != null) {
		try {
			IResource resource = resourceManager.getResource(location);

			Closer closer = Closer.create();
			try {
				final InputStream is = closer.register(resource.getInputStream());
				final Reader reader = closer.register(new InputStreamReader(is, Charsets.UTF_8));
				final HitboxList list = GSON.fromJson(reader, HitboxList.class);
				result.addAll(list);
			} catch (Throwable t) {
				throw closer.rethrow(t);
			} finally {
				closer.close();
			}
		} catch (IOException e) {
			Log.warn(e, "Failed to find hitbox %s", location);
		}
	}

	return result;
}
 
Example #4
Source File: GuiCustomizeWorld.java    From YUNoMakeGoodMap with Apache License 2.0 6 votes vote down vote up
private StructInfo getInfo(ResourceLocation res)
{
    StructInfo ret = structInfo.get(res);
    if (ret != null)
        return ret;

    try
    {
        IResource ir = this.mc.getResourceManager().getResource(new ResourceLocation(res.getResourceDomain(), "structures/" + res.getResourcePath() + ".json"));
        ret = GSON.fromJson(new InputStreamReader(ir.getInputStream()), StructInfo.class);

        if (ret.logo != null)
        {
            ir = this.mc.getResourceManager().getResource(new ResourceLocation(res.getResourceDomain(), "structures/" + ret.logo));
            if (ir != null)
            {
                BufferedImage l = ImageIO.read(ir.getInputStream());
                ret.logoPath = this.mc.getTextureManager().getDynamicTextureLocation("platformlogo", new DynamicTexture(l));
                ret.logoSize = new Dimension(l.getWidth(), l.getHeight());
            }
        }
    }
    catch (IOException e)
    {
        //Ugh wish it had a 'hasResource'
    }

    if (ret == null)
        ret = new StructInfo();

    if (ret.name == null)
        ret.name = res.toString();

    structInfo.put(res, ret);
    return ret;
}
 
Example #5
Source File: WavefrontObject.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
public WavefrontObject(ResourceLocation resource) throws ModelFormatException
{
    this.fileName = resource.toString();

    try
    {
        IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
        loadObjModel(res.getInputStream());
    }
    catch (IOException e)
    {
        throw new ModelFormatException("IO Exception reading model format", e);
    }
}
 
Example #6
Source File: BaseTexture.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected BufferedImage loadImage(IResourceManager resourceManager, ResourceLocation location) throws IOException {
    InputStream inputstream = null;

    try {
        IResource iresource = resourceManager.getResource(location);
        inputstream = iresource.getInputStream();
        return ImageIO.read(inputstream);
    }
    finally {
        if (inputstream != null) {
            inputstream.close();
        }
    }
}
 
Example #7
Source File: RenderUtility.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void preInit(FMLPreInitializationEvent event) {
	//Load models
	Game.render().modelProviders.forEach(m -> {
		ResourceLocation resource = new ResourceLocation(m.domain, "models/" + m.name + "." + m.getType());
		try {
			IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
			m.load(res.getInputStream());
		} catch (IOException e) {
			throw new ModelFormatException("IO Exception reading model format", e);
		}
	});
}
 
Example #8
Source File: RenderUtility.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void preInit(FMLPreInitializationEvent event) {
	//Load models
	Game.render().modelProviders.forEach(m -> {
		ResourceLocation resource = new ResourceLocation(m.domain, "models/" + m.name + "." + m.getType());
		try {
			IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
			m.load(res.getInputStream());
		} catch (IOException e) {
			throw new RuntimeException("IO Exception reading model format", e);
		}
	});
}
 
Example #9
Source File: MinecraftHook.java    From SkyblockAddons with MIT License 6 votes vote down vote up
public static void onRefreshResources(IReloadableResourceManager resourceManager) {
    boolean usingOldPackTexture = false;
    boolean usingDefaultTexture = true;
    try {
        IResource currentResource = resourceManager.getResource(currentLocation);
        String currentHash = DigestUtils.md5Hex(currentResource.getInputStream());

        InputStream oldStream = SkyblockAddons.class.getClassLoader().getResourceAsStream("assets/skyblockaddons/imperialoldbars.png");
        if (oldStream != null) {
            String oldHash = DigestUtils.md5Hex(oldStream);
            usingOldPackTexture = currentHash.equals(oldHash);
        }

        InputStream barsStream = SkyblockAddons.class.getClassLoader().getResourceAsStream("assets/skyblockaddons/bars.png");
        if (barsStream != null) {
            String barsHash = DigestUtils.md5Hex(barsStream);
            usingDefaultTexture = currentHash.equals(barsHash);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    SkyblockAddons main = SkyblockAddons.getInstance();
    if (main != null) { // Minecraft reloads textures before and after mods are loaded. So only set the variable if sba was initialized.
        main.getUtils().setUsingOldSkyBlockTexture(usingOldPackTexture);
        main.getUtils().setUsingDefaultBarTextures(usingDefaultTexture);
    }
}
 
Example #10
Source File: TextureDynamic.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
private BufferedImage tryLoadImage(IResourceManager manager, ResourceLocation location)
{
  try
  {
    IResource res = manager.getResource(location);
    BufferedImage imgOutput = ImageIO.read(res.getInputStream());
    
    return imgOutput;
  }
  catch (Exception e)
  {
    //ExNihilo.log.error("Failed to load image: " + location.toString());
    return null;
  }
}
 
Example #11
Source File: GibsAnimationRegistry.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
public static void registerAnimation(String name, ResourceLocation location) {
    try {
        IResource animationResource = Minecraft.getMinecraft().getResourceManager()
            .getResource(location);
        Scanner data = new Scanner(animationResource.getInputStream());
        AtomParser dataParser = new AtomParser(data);
        IAtomAnimationBuilder animationBuilder = new BasicAtomAnimationBuilder(dataParser);
        // Then register all the models associated with this animation
        Set<String> modelsUsed = animationBuilder.getModelObjsUsed();
        String resourceDomainName = location.getNamespace();

        StringBuilder modelResourceFolder = new StringBuilder();
        String[] temp = location.getPath()
            .split("/");
        for (int i = 1; i < temp.length - 1; i++) {
            modelResourceFolder.append(temp[i]).append("/");
        }

        for (String modelName : modelsUsed) {
            String modelFullPath = modelResourceFolder + modelName;
            ResourceLocation modelToRegister = new ResourceLocation(resourceDomainName,
                modelResourceFolder + modelName + ".obj");
            GibsModelRegistry.registerGibsModel(modelFullPath, modelToRegister);
        }

        final String modelResourceFolderFinal = modelResourceFolder.toString();
        ANIMATION_MAP.put(name, animationBuilder.build((modelName, renderBrightness) ->
            GibsModelRegistry
                .renderGibsModel(modelResourceFolderFinal + modelName, renderBrightness)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #12
Source File: VanillaLoader.java    From VanillaFix with MIT License 6 votes vote down vote up
@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);
}
 
Example #13
Source File: VariantLoader.java    From VanillaFix with MIT License 6 votes vote down vote up
private ModelBlockDefinition loadModelBlockDefinition(ResourceLocation location, IResource resource) {
    ModelBlockDefinition definition;

    try (InputStream is = resource.getInputStream()) {
        definition = ModelBlockDefinition.parseFromReader(new InputStreamReader(is, StandardCharsets.UTF_8), location);
    } catch (Exception exception) {
        throw new RuntimeException("Encountered an exception when loading model definition of '" + location + "' from: '" + resource.getResourceLocation() + "' in resourcepack: '" + resource.getResourcePackName() + "'", exception);
    }

    return definition;
}
 
Example #14
Source File: VariantLoader.java    From VanillaFix with MIT License 6 votes vote down vote up
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);
}
 
Example #15
Source File: HarvesterAnimationStateMachine.java    From EmergingTechnology with MIT License 6 votes vote down vote up
/**
 * Load a new instance of HarvesterAnimationStateMachine at specified location,
 * with specified custom parameters.
 */
@SideOnly(Side.CLIENT)
public static HarvesterAnimationStateMachine load(IResourceManager manager, ResourceLocation location,
        ImmutableMap<String, ITimeValue> customParameters) {
    try (IResource resource = manager.getResource(location)) {
        ClipResolver clipResolver = new ClipResolver();
        ParameterResolver parameterResolver = new ParameterResolver(customParameters);
        Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(clipResolver);
        TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(parameterResolver);
        HarvesterAnimationStateMachine asm = asmGson.fromJson(
                new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8),
                HarvesterAnimationStateMachine.class);
        clipResolver.asm = asm;
        parameterResolver.asm = asm;
        asm.initialize();

        return asm;
    } catch (IOException | JsonParseException e) {
        FMLLog.log.error("Exception loading Animation State Machine {}, skipping", location, e);
        return missing;
    } finally {
        Clips.CommonClipTypeAdapterFactory.INSTANCE.setClipResolver(null);
        TimeValues.CommonTimeValueTypeAdapterFactory.INSTANCE.setValueResolver(null);
    }
}
 
Example #16
Source File: MotionBlurResourceManager.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<IResource> getAllResources(ResourceLocation location) throws IOException {
    return null;
}
 
Example #17
Source File: MotionBlurResourceManager.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public IResource getResource(ResourceLocation location) throws IOException {
    return new MotionBlurResource();
}
 
Example #18
Source File: DynamicTextureMap.java    From VanillaFix with MIT License 4 votes vote down vote up
protected TextureAtlasSprite loadSprite(String name) {
//        LOGGER.info("Loading texture " + name);

        TextureAtlasSprite sprite = mapRegisteredSprites.get(name);
        if (sprite == null) {
            sprite = new TextureAtlasSprite(name);
        }

        // Load the sprite
        ResourceLocation location = getResourceLocation(sprite);

        if (sprite.hasCustomLoader(resourceManager, location)) {
            sprite.load(resourceManager, location, l -> getAtlasSprite(l.toString()));
        } else if (name.equals("minecraft:missingno")) {
            return missingImage;
        } else {
            try (IResource resource = resourceManager.getResource(location)) {
                PngSizeInfo pngSizeInfo = PngSizeInfo.makeFromResource(resourceManager.getResource(location));
                boolean isAnimated = resource.getMetadata("animation") != null;
                sprite.loadSprite(pngSizeInfo, isAnimated);
            } catch (Throwable t) {
                LOGGER.error("Couldn't load sprite " + location, t);
                return missingImage;
            }
        }

        if (!generateMipmaps(resourceManager, sprite)) {
            return missingImage;
        }

        // Allocate it a spot on the texture map
        int oldWidth = stitcher.getImageWidth();
        int oldHeight = stitcher.getImageHeight();

        stitcher.addSprite(sprite);

        // Texture map got resized, recreate it and upload all textures
        if (stitcher.getImageWidth() != oldWidth || stitcher.getImageHeight() != oldHeight) {
            atlasNeedsExpansion = true;
        }

        // Upload the texture
        spritesNeedingUpload.add(sprite);

        // Add animated sprites to a list so that it's ticked every tick
        if (sprite.hasAnimationMetadata()) {
            listAnimatedSprites.add(sprite);
        }

        // Updade if calling from Minecraft thread so that inventory items don't flicker
        // Don't load during init to avoid problems with loading screen
        if (minecraft.isCallingFromMinecraftThread() && ((IPatchedMinecraft) minecraft).isDoneLoading()) {
            update();
        }

        return sprite;
    }
 
Example #19
Source File: GolemGuiTexture.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void loadTexture(IResourceManager resourceManager) throws IOException {
    this.deleteGlTexture();
    InputStream inputstream = null;

    try
    {
        IResource iresource = resourceManager.getResource(this.textureLocation);
        inputstream = iresource.getInputStream();
        BufferedImage bufferedimage = manipulateImage(resourceManager, ImageIO.read(inputstream));

        boolean flag = false;
        boolean flag1 = false;

        if (iresource.hasMetadata())
        {
            try
            {
                TextureMetadataSection texturemetadatasection = (TextureMetadataSection)iresource.getMetadata("texture");

                if (texturemetadatasection != null)
                {
                    flag = texturemetadatasection.getTextureBlur();
                    flag1 = texturemetadatasection.getTextureClamp();
                }
            }
            catch (RuntimeException runtimeexception)
            {
                LOGGER.warn("Failed reading metadata of: " + this.textureLocation, runtimeexception);
            }
        }

        TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), bufferedimage, flag, flag1);
    }
    finally
    {
        if (inputstream != null)
        {
            inputstream.close();
        }
    }
}
 
Example #20
Source File: BufferedResourceWrapper.java    From OpenModsLib with MIT License 3 votes vote down vote up
public BufferedResourceWrapper(IResource resource) {
	this.resource = resource;
	this.stream = ensureStreamIsBuffered(resource.getInputStream());
}