Java Code Examples for net.minecraft.client.resources.AbstractResourcePack

The following examples show how to use net.minecraft.client.resources.AbstractResourcePack. These examples are extracted from open source projects. 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
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
/**
 * 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
/**
 * 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
/**
 * 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
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
public HyperiumAbstractResourcePack(AbstractResourcePack parent) {
    this.parent = parent;
}