net.minecraft.client.resources.AbstractResourcePack Java Examples

The following examples show how to use net.minecraft.client.resources.AbstractResourcePack. 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: ResourcePackFix.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void fixResourcePackLocation(ModContainer selfContainer) {
    File sourceFile = selfContainer.getSource();
    if (sourceFile.isDirectory()) {
        AbstractResourcePack resourcePack = getModResourcePack(selfContainer.getModId());
        File actualPackRoot = ObfuscationReflectionHelper.getPrivateValue(AbstractResourcePack.class, resourcePack, "field_110597_b");
        File expectedPackRoot = getGTCEResourcePackRoot();

        if (!expectedPackRoot.getAbsolutePath().equals(actualPackRoot.getAbsolutePath())) {
            System.out.println("[GTCE] Found unexpected resource pack path in dev environment");
            System.out.println("[GTCE] Expected path: " + expectedPackRoot.getAbsolutePath());
            System.out.println("[GTCE] Actual path: " + actualPackRoot.getAbsolutePath());
            System.out.println("[GTCE] Fixed resource pack patch automatically.");
            ObfuscationReflectionHelper.setPrivateValue(AbstractResourcePack.class, resourcePack, expectedPackRoot, "field_110597_b");
            setModResourcePack(selfContainer.getModId(), resourcePack);
        }
    }
}
 
Example #2
Source File: NovaMinecraftPreloader.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Dynamically generates a sound JSON file based on a resource pack's file structure.
 *
 * If it's a folder, then load it as a sound collection.
 * A sound collection falls under the same resource name. When called to play, it will pick a random sound from the collection to play it.
 *
 * If it's just a sound file, then load the sound file
 *
 * @param pack The resource pack to generate the sound JSON for.
 * @return The generated sound JSON.
 */
public static String generateSoundJSON(AbstractResourcePack pack) {
	StringWriter sw = new StringWriter();
	try (JsonGenerator json = Json.createGenerator(sw);) {
		json.writeStartObject();
		if (pack instanceof FileResourcePack) {
			//For zip resource packs
			try {
				generateSoundJSON((FileResourcePack) pack, json);
			} catch (Exception e) {
				Error error = new ExceptionInInitializerError("Error generating fake sound JSON file.");
				error.addSuppressed(e);
				throw error;
			}
		} else if (pack instanceof FolderResourcePack) {
			//For folder resource packs
			generateSoundJSON((FolderResourcePack) pack, json);
		}
		json.writeEnd().flush();
		return sw.toString();
	}
}
 
Example #3
Source File: NovaMinecraftPreloader.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Dynamically generates a sound JSON file based on a resource pack's file structure.
 *
 * If it's a folder, then load it as a sound collection.
 * A sound collection falls under the same resource name. When called to play, it will pick a random sound from the collection to play it.
 *
 * If it's just a sound file, then load the sound file
 *
 * @param pack The resource pack to generate the sound JSON for.
 * @return The generated sound JSON.
 */
public static String generateSoundJSON(AbstractResourcePack pack) {
	StringWriter sw = new StringWriter();
	try (JsonGenerator json = Json.createGenerator(sw);) {
		json.writeStartObject();
		if (pack instanceof FileResourcePack) {
			//For zip resource packs
			try {
				generateSoundJSON((FileResourcePack) pack, json);
			} catch (Exception e) {
				Error error = new ExceptionInInitializerError("Error generating fake sound JSON file.");
				error.addSuppressed(e);
				throw error;
			}
		} else if (pack instanceof FolderResourcePack) {
			//For folder resource packs
			generateSoundJSON((FolderResourcePack) pack, json);
		}
		json.writeEnd().flush();
		return sw.toString();
	}
}
 
Example #4
Source File: NovaMinecraftPreloader.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Dynamically generates a sound JSON file based on a resource pack's file structure.
 *
 * If it's a folder, then load it as a sound collection.
 * A sound collection falls under the same resource name. When called to play, it will pick a random sound from the collection to play it.
 *
 * If it's just a sound file, then load the sound file
 *
 * @param pack The resource pack to generate the sound JSON for.
 * @return The generated sound JSON.
 */
public static String generateSoundJSON(AbstractResourcePack pack) {
	StringWriter sw = new StringWriter();
	try (JsonGenerator json = Json.createGenerator(sw);) {
		json.writeStartObject();
		if (pack instanceof FileResourcePack) {
			//For zip resource packs
			try {
				generateSoundJSON((FileResourcePack) pack, json);
			} catch (Exception e) {
				Error error = new ExceptionInInitializerError("Error generating fake sound JSON file.");
				error.addSuppressed(e);
				throw error;
			}
		} else if (pack instanceof FolderResourcePack) {
			//For folder resource packs
			generateSoundJSON((FolderResourcePack) pack, json);
		}
		json.writeEnd().flush();
		return sw.toString();
	}
}
 
Example #5
Source File: ResourcePackFix.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void setModResourcePack(String modid, AbstractResourcePack newPack) {
    FMLClientHandler clientHandler = FMLClientHandler.instance();
    IResourcePack oldPack = clientHandler.getResourcePackFor(modid);
    Map<String, IResourcePack> resourcePackMap = ObfuscationReflectionHelper.getPrivateValue(FMLClientHandler.class, clientHandler, "resourcePackMap");
    resourcePackMap.put(modid, newPack);
    List<IResourcePack> resourcePackList = ObfuscationReflectionHelper.getPrivateValue(FMLClientHandler.class, clientHandler, "resourcePackList");
    resourcePackList.remove(oldPack);
    resourcePackList.add(newPack);
}
 
Example #6
Source File: HyperiumAbstractResourcePack.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public HyperiumAbstractResourcePack(AbstractResourcePack parent) {
    this.parent = parent;
}