### Creative API Example Source: https://github.com/unnamed/creative/blob/main/docs/getting-started.md This example demonstrates how to use the creative API to create a resource pack, add metadata, an icon, a texture, an unknown file, and then write it to a ZIP file. ```java ResourcePack resourcePack = ResourcePack.resourcePack(); // Required to have a valid resource pack resourcePack.packMeta(9, "Description!"); // adding the resource pack icon resourcePack.icon(Writable.file(new File("my-icon.png"))); // adding a texture resourcePack.texture(texture); // adding a non special file resourcePack.unknownFile("credits.txt", Writable.stringUtf8("Unnamed Team")); // now we have a resource pack ready to be exported/written // as a ZIP file or as a file tree (you need the 'creative-serializer-minecraft' // dependency for this class) MinecraftResourcePackWriter.minecraft().writeToZipFile( new File("my-resource-pack.zip"), resourcePack ); ``` -------------------------------- ### Building a ResourcePackServer Source: https://github.com/unnamed/creative/blob/main/docs/server/start-stop.md Example of building a ResourcePackServer with essential configurations like address, port, pack, and optional settings such as executor, SSL/TLS, and handler path. ```java ResourcePackServer server = ResourcePackServer.server() .address("127.0.0.1", 7270) // (required) address and port .pack(ResourcePack) // (required) pack to serve .executor(Executor) // (optional) request executor (IMPORTANT!) .secure(...) .path("/get/") // (optional) handler path, default = "/" .build(); ``` -------------------------------- ### Gradle Dependencies Source: https://github.com/unnamed/creative/blob/main/docs/installation.md Add these dependencies to your project's build.gradle file for Gradle. ```kotlin dependencies { implementation("team.unnamed:creative-api:%%REPLACE_latestRelease{team.unnamed:creative-api}%%") // Serializer for Minecraft format (ZIP / Folder) implementation("team.unnamed:creative-serializer-minecraft:%%REPLACE_latestRelease{team.unnamed:creative-serializer-minecraft}%%") // Resource Pack server implementation("team.unnamed:creative-server:%%REPLACE_latestRelease{team.unnamed:creative-server}%%") } ``` -------------------------------- ### Maven Dependency Source: https://github.com/unnamed/creative/blob/main/docs/installation.md Add this dependency to your project's pom.xml file for Maven. ```xml team.unnamed creative-api %%REPLACE_latestRelease{team.unnamed:creative-api}%% ``` -------------------------------- ### Gradle Dependency Source: https://github.com/unnamed/creative/blob/main/docs/server/installation.md Add the creative-server dependency to your project using Gradle. ```kotlin dependencies { implementation("team.unnamed:creative-server:%%REPLACE_latestRelease{team.unnamed:creative-server}%%") } ``` -------------------------------- ### Maven Dependency Source: https://github.com/unnamed/creative/blob/main/docs/server/installation.md Add the creative-server dependency to your project using Maven. ```xml team.unnamed creative-server %%REPLACE_latestRelease{team.unnamed:creative-server}%% ``` -------------------------------- ### Starting the ResourcePackServer Source: https://github.com/unnamed/creative/blob/main/docs/server/start-stop.md Code to start the ResourcePackServer, which listens for incoming requests. This operation is non-blocking. ```java server.start(); // NOT BLOCKING! ``` -------------------------------- ### Basic Texture Creation Source: https://github.com/unnamed/creative/blob/main/docs/textures.md Example of creating a basic texture with a key and PNG data from a file. ```java Texture texture = Texture.texture() .key(Key.key("namespace", "my_texture.png")) .data(Writable.file(new File("exampleTexture.png"))) .build(); ``` -------------------------------- ### Bitmap Font Provider Example Source: https://github.com/unnamed/creative/blob/main/docs/fonts.md Example of creating a bitmap font provider with a texture, ascent, and characters. ```java Texture texture = ...; FontProvider provider = FontProvider.bitMap() .file(texture.key()) .ascent(7) .characters( "abcdef", "012345", "6789ñá" ) .build(); ``` -------------------------------- ### Creating a Font Source: https://github.com/unnamed/creative/blob/main/docs/fonts.md Example of merging font providers to create a Font object with a specific key. ```java Font font = Font.font( Key.key("namespace", "my_font"), fontProvider1, fontProvider2, ... ); ``` -------------------------------- ### Setting a custom handler Source: https://github.com/unnamed/creative/blob/main/docs/server/handle-request.md Example of setting a custom resource pack handler when building the server. ```java ResourcePackServer server = ResourcePackServer.server() .address("127.0.0.1", 7270) .handler(handler) // <-- Here, see below // ... .build(); ``` -------------------------------- ### Item Override Example Source: https://github.com/unnamed/creative/blob/main/docs/models.md Example of creating an ItemOverride to change a model based on item state, such as custom model data. ```java // this will change the model when the item has a custom model data of '2' ItemOverride override = ItemOverride.of( Key.key("key/to/the/model"), ItemPredicate.customModelData(2) ); ``` -------------------------------- ### Adding Model to Resource Pack Source: https://github.com/unnamed/creative/blob/main/docs/models.md Example of how to add a created Model to a ResourcePack. ```java ResourcePack resourcePack = ...; Model model = ...; resourcePack.model(model); ``` -------------------------------- ### Resource Pack Download Request Example Source: https://github.com/unnamed/creative/blob/main/docs/server/download-request.md This Java code snippet demonstrates how to construct a resource pack URL using its SHA-1 hash and a base server address. It also notes a potential client bug related to hash checking. ```java BuiltResourcePack pack = ...; String hash = pack.hash(); // The resource-pack path, can be empty, but due to a bug // on the Minecraft client, the hashes are not correctly // checked, and it will fail to update String path = hash + ".zip"; // just an example! replace this by your server's // public address for production // HTTP is required if you did not configure HTTPS String url = "http://127.0.0.1:7270/" + path; ``` -------------------------------- ### Complete Model Creation Source: https://github.com/unnamed/creative/blob/main/docs/models.md Example demonstrating how to assemble elements, textures, displays, and overrides into a complete Minecraft Model. ```java Model model = Model.model() .key(Key.key("custom/my_model")) .addElement(element) // the element we created before .addOverride(override) // the override we created before .displays(displays) // the displays we created before .textures(textures) // the textures we created before .build(); // There are some extra options like: // .parent(Key.key("parent/model")) // to inherit from another model // .ambientOcclusion(false) // to disable ambient occlusion // .guiLight(ModelGuiLight.FRONT) // to change the gui light ``` -------------------------------- ### Merging Resource Packs Example Source: https://github.com/unnamed/creative/blob/main/docs/merging.md Demonstrates how to merge two resource packs using the ResourcePack#merge method with the override strategy. ```java // get our resource packs ResourcePack base = ...; ResourcePack other = ...; // merge base.merge(other, MergeStrategy.override()); // now base contains all the resources from other ``` -------------------------------- ### Texture Creation with Animation Metadata Source: https://github.com/unnamed/creative/blob/main/docs/textures.md Example of creating a texture and adding animation metadata, specifying height. ```java Texture texture = Texture.texture() .key(Key.key("namespace", "my_texture.png")) .data(Writable.file(new File("exampleTexture.png"))) .meta( Metadata.builder() .add(AnimationMeta.builder().height(16).build()) .build() ) .build(); ``` -------------------------------- ### Display Configuration Source: https://github.com/unnamed/creative/blob/main/docs/models.md Example of configuring how a model is displayed in different contexts, such as in an entity's head, by setting transformations like scale. ```java // (API subject to change in next major version) Map displays = new HashMap<>(); // this will scale the model to 0.5 when it's displayed in an entity's head displays.put(ItemTransform.Type.HEAD, ItemTransform.transform( Vector3Float.ZERO, // rotation: no rotation Vector3Float.ZERO, // translation: no translation new Vector3Float(0.5, 0.5, 0.5) )); ``` -------------------------------- ### Playing a custom sound in Paper Source: https://github.com/unnamed/creative/blob/main/docs/sounds.md Provides an example of how to play a custom sound event using the Paper API. ```java SoundEvent soundEvent = ...; player.playSound(Sound.sound(soundEvent, Sound.Source.AMBIENT, 1f, 1.1f)); ``` -------------------------------- ### Deserializing Font Source: https://github.com/unnamed/creative/blob/main/docs/serialization/minecraft.md Example of deserializing a font from resources using the experimental Unitary Serialization. ```java Font font = FontSerializer.INSTANCE.deserialize( Readable.resource(getClass().getClassLoader(), "font.json"), Key.key("custom:fontkey") ); ``` -------------------------------- ### Texture Definition Source: https://github.com/unnamed/creative/blob/main/docs/models.md Example of how to define textures for a model. Textures are specified with a key and can be referenced by elements using an ID. ```java ModelTextures textures = ModelTextures.builder() .layers( // without .png extension ModelTexture.ofKey(Key.key("key/to/my/texture")) ) .build(); ``` -------------------------------- ### Compiling Resource Pack in Memory Source: https://github.com/unnamed/creative/blob/main/docs/serialization/minecraft.md Example of compiling a ResourcePack object into a BuiltResourcePack in memory. ```java ResourcePack resourcePack = ...; BuiltResourcePack builtResourcePack = MinecraftResourcePackWriter.minecraft().build(resourcePack); ``` -------------------------------- ### Using a Font with Adventure Source: https://github.com/unnamed/creative/blob/main/docs/fonts.md Example of using a custom font with Adventure API to send a message to a player. ```java Font font = MyFonts.MY_SPECIAL_FONT; player.sendMessage( text() .content("Hello world") .font(font.key()) ); ``` -------------------------------- ### Custom ResourcePackRequestHandler implementation Source: https://github.com/unnamed/creative/blob/main/docs/server/handle-request.md An example implementation of a ResourcePackRequestHandler that serves different resource packs based on the client's requested pack format. ```java BuiltResourcePack pack8 = MinecraftResourcePackWriter.minecraft().build(this::createPack8); BuiltResorucePack pack9 = MinecraftResourcePackWriter.minecraft().build(this::createPack9); ResourcePackRequestHandler handler = (request, exchange) -> { // available methods: // - request.uuid() // - request.username() // - request.clientVersion() // - request.clientVersionId() // - request.packFormat() int expectedPackFormat; if (request == null) { // no information provided, fall back to 9 expectedPackFormat = 9; } else { expectedPackFormat = request.packFormat(); } BuiltResourcePack pack; if (expectedPackFormat == 9) { pack = pack9; } else if (expectedPackFormat == 8) { pack = pack8; } else { // no pack with this format :( byte[] response = "No pack for u\n".getBytes(StandardCharsets.UTF_8); exchange.getResponseHeaders().set("Content-Type", "text/plain"); exchange.sendResponseHeaders(400, response.length); try (OutputStream responseStream = exchange.getResponseBody()) { responseStream.write(response); } return; } // write our resource pack byte[] data = pack.bytes(); exchange.getResponseHeaders().set("Content-Type", "application/zip"); exchange.sendResponseHeaders(200, data.length); try (OutputStream responseStream = exchange.getResponseBody()) { responseStream.write(data); } }; ``` -------------------------------- ### Setting a multithreaded executor Source: https://github.com/unnamed/creative/blob/main/docs/server/handle-request.md Example of configuring the server to use a fixed thread pool for executing request handlers. ```java ResourcePackServer server = ResourcePackServer.server() .address("127.0.0.1", 7270) .handler(...) .executor(Executors.newFixedThreadPool(8)) // <-- will use 8 threads .build(); ``` -------------------------------- ### Serializing Language to File Source: https://github.com/unnamed/creative/blob/main/docs/serialization/minecraft.md Example of serializing a Language object to a file using the experimental Unitary Serialization. ```java Language language = ...; try (OutputStream output = new FileOutputStream("es.json")) { LanguageSerializer.INSTANCE.serialize(language, output); } ``` -------------------------------- ### Element Creation Source: https://github.com/unnamed/creative/blob/main/docs/models.md Example of how to create an Element, which represents a cube in a Minecraft model. It defines the cube's dimensions, faces, and textures. ```java Element element = Element.element() .from(0, 0, 0) .to(16, 16, 16) .addFace(CubeFace.UP, ElementFace.face() .texture("#0") // use the texture with id '0' .uv(TextureUV.uv(0, 0, 1, 1)) // use the full texture .build()) // add more faces, if you do not add one, it won't be visible .build(); ``` -------------------------------- ### Reading Resource Pack from Zip File Source: https://github.com/unnamed/creative/blob/main/docs/serialization/minecraft.md Example of reading a ResourcePack object from a ZIP file using Minecraft serializers. ```java File input = new File("/path/to/input/resource-pack.zip"); ResourcePack resourcePack = MinecraftResourcePackReader.minecraft().readFromZipFile(input); ``` -------------------------------- ### Writing Resource Pack to Zip File Source: https://github.com/unnamed/creative/blob/main/docs/serialization/minecraft.md Example of writing a ResourcePack object to a ZIP file using Minecraft serializers. ```java ResourcePack resourcePack = ...; File output = new File("/path/to/resource-pack.zip"); MinecraftResourcePackWriter.minecraft().writeToZipFile(output, resourcePack); ``` -------------------------------- ### Stopping the ResourcePackServer Source: https://github.com/unnamed/creative/blob/main/docs/server/start-stop.md Code to stop the ResourcePackServer, specifying a maximum wait time in seconds for ongoing requests to finish. A value of 0 means no waiting. ```java server.stop(0); // BLOCKING IF NOT ZERO! ``` -------------------------------- ### Create a simple resource pack Source: https://github.com/unnamed/creative/blob/main/docs/examples/hello-world.md This code snippet demonstrates how to create a basic resource pack with a pack meta file. ```java ResourcePack resourcePack = ResourcePack.resourcePack(); // Here we specify the resource-pack format (12) and description (Hello world!) resourcePack.packMeta(12, "Hello world!"); // Then we write the resource-pack to a folder MinecraftResourcePackWriter.minecraft() .writeToDirectory(new File("folder"), resourcePack); ``` -------------------------------- ### Resource Pack Creation and Export Source: https://github.com/unnamed/creative/blob/main/docs/putting-all-together.md Demonstrates how to create a resource pack, add essential components like meta information, icon, fonts, and textures, include custom files, and finally export the resource pack as a ZIP file using MinecraftResourcePackWriter. ```java ResourcePack resourcePack = ResourcePack.create(); // Required to have a valid resource pack resourcePack.packMeta(9, "Description!"); // adding the resource pack icon resourcePack.icon(Writable.file(...)); // Use any type of Writable // adding a font resourcePack.font(font); // adding a texture resourcePack.texture(texture); // adding a non special file resourcePack.unknownFile("credits.txt", Writable.stringUtf8("Unnamed Team")); // now we have a resource pack ready to be exported/written // as a ZIP file or as a file tree (you need the 'creative-serializer-minecraft' // dependency for this class) MinecraftResourcePackWriter.minecraft().writeToZipFile( new File("my-resource-pack.zip"), resourcePack ); ``` -------------------------------- ### Creating a Sound object Source: https://github.com/unnamed/creative/blob/main/docs/sounds.md Demonstrates how to create a Sound object, specifying the sound file location and its associated data. ```java Sound sound = Sound.sound( // location of the sound file in the resource-pack // (assets//sounds/.ogg) Key.key("creative:meow_1"), // the sound data, check the Writable API, // in this case, the sound data is taken from // a file called "the_sound.ogg" Writable.file(new File("the_sound.ogg")) ); ``` -------------------------------- ### pack.mcmeta content Source: https://github.com/unnamed/creative/blob/main/docs/examples/hello-world.md The content of the pack.mcmeta file generated by the code. ```json { "pack": { "pack_format": 12, "description": "Hello world!" } } ``` -------------------------------- ### Creating a SoundEntry of type FILE Source: https://github.com/unnamed/creative/blob/main/docs/sounds.md Illustrates the creation of a SoundEntry of type FILE, which configures a single Sound with options like volume, pitch, and attenuation. ```java SoundEntry soundEntry = SoundEntry.soundEntry() .type(SoundEntry.Type.FILE) // <-- Specify type to FILE .key(Key.key("creative:meow_1")) // <-- set the key of a Sound .volume(1.0F) .pitch(1.0F) .weight(1) .stream(false) .attenuationDistance(16) .preload(false) .build(); ``` -------------------------------- ### Creating a SoundEntry of type EVENT Source: https://github.com/unnamed/creative/blob/main/docs/sounds.md Demonstrates the creation of a SoundEntry of type EVENT, which is configuration for a SoundEvent, allowing similar options as the FILE type. ```java SoundEntry soundEntry = SoundEntry.soundEntry() .type(SoundEntry.Type.EVENT) // <-- Specify type to EVENT .key(Key.key("creative:meow")) // <-- set the key of a SoundEvent .volume(1.0F) .pitch(1.0F) .weight(1) .stream(false) .attenuationDistance(16) .preload(false) .build(); ``` -------------------------------- ### Creating a SoundEvent Source: https://github.com/unnamed/creative/blob/main/docs/sounds.md Shows how to create a SoundEvent, which is a named list of SoundEntry objects. A SoundEntry is randomly selected when the event is played. ```java SoundEvent soundEvent = SoundEvent.soundEvent() .key(Key.key("creative:creative.cat.meow")) .sounds( soundEntry1, soundEntry2, soundEntry3, ... ); .replace(false) .build(); ``` -------------------------------- ### Writing a SoundEvent to a Resource Pack Source: https://github.com/unnamed/creative/blob/main/docs/sounds.md Demonstrates how to add a SoundEvent to a resource pack. ```java ResourcePack resourcePack = ...; resourcePack.soundEvent(soundEvent); ``` -------------------------------- ### Adding a Sound to a Resource Pack Source: https://github.com/unnamed/creative/blob/main/docs/sounds.md Shows how to add a previously created Sound object to a resource pack. ```java ResourcePack resourcePack = ...; resourcePack.sound(sound); ``` -------------------------------- ### Paper Server Resource Pack Download Source: https://github.com/unnamed/creative/blob/main/docs/server/download-request.md This Java code snippet shows how to use the `Player#setResourcePack` method on Paper servers to prompt a player to download a resource pack, providing the URL and hash. ```java player.setResourcePack(url, hash /*, prompt, force */); ``` -------------------------------- ### Minestom Server Resource Pack Download Source: https://github.com/unnamed/creative/blob/main/docs/server/download-request.md This Java code snippet illustrates how to use the `Player#setResourcePack` method on Minestom servers, utilizing `ResourcePack.forced()` to specify the resource pack URL, hash, and an optional prompt. ```java // forced(...) or optional(...) player.setResourcePack(ResourcePack.forced(url, hash /*, prompt */)); ``` -------------------------------- ### Gradle Dependency Source: https://github.com/unnamed/creative/blob/main/docs/serialization/minecraft.md The Gradle dependency required to use the Minecraft serializers. ```gradle dependencies { implementation("team.unnamed:creative-serializer-minecraft:%%REPLACE_latestRelease{team.unnamed:creative-serializer-minecraft}%%") } ``` -------------------------------- ### Creative Language Representation Source: https://github.com/unnamed/creative/blob/main/docs/language.md A simple keyed map of translations for a creative language representation. ```java Language language = Language.language( Key.key("minecraft", "en_US"), Map.of( // translation key // translation "gui.yes", "Yes please", "gui.no", "No!", "gui.proceed", "Do it!" ) ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.