From 8c36b3e3303a739319c67d595ed512b64300206e Mon Sep 17 00:00:00 2001 From: Boy Date: Thu, 28 Nov 2024 02:13:31 +0100 Subject: [PATCH 1/2] feat: begin impl for Equipment --- .../unnamed/creative/equipment/Equipment.java | 92 ++++++++++ .../creative/equipment/EquipmentImpl.java | 161 ++++++++++++++++++ .../creative/overlay/ResourceContainer.java | 9 + .../overlay/ResourceContainerImpl.java | 27 +++ .../minecraft/ResourceCategories.java | 2 + .../equipment/EquipmentSerializer.java | 132 ++++++++++++++ .../EquipmentDeserializationTest.java | 82 +++++++++ .../src/test/resources/equipment/elytra.json | 9 + .../test/resources/equipment/netherite.json | 14 ++ 9 files changed, 528 insertions(+) create mode 100644 api/src/main/java/team/unnamed/creative/equipment/Equipment.java create mode 100644 api/src/main/java/team/unnamed/creative/equipment/EquipmentImpl.java create mode 100644 serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentSerializer.java create mode 100644 serializer-minecraft/src/test/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentDeserializationTest.java create mode 100644 serializer-minecraft/src/test/resources/equipment/elytra.json create mode 100644 serializer-minecraft/src/test/resources/equipment/netherite.json diff --git a/api/src/main/java/team/unnamed/creative/equipment/Equipment.java b/api/src/main/java/team/unnamed/creative/equipment/Equipment.java new file mode 100644 index 00000000..0a322609 --- /dev/null +++ b/api/src/main/java/team/unnamed/creative/equipment/Equipment.java @@ -0,0 +1,92 @@ +/* + * This file is part of creative, licensed under the MIT license + * + * Copyright (c) 2021-2023 Unnamed Team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package team.unnamed.creative.equipment; + + +import net.kyori.adventure.key.Key; +import net.kyori.adventure.key.Keyed; +import net.kyori.examination.Examinable; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import team.unnamed.creative.overlay.ResourceContainer; +import team.unnamed.creative.part.ResourcePackPart; + +/** + * Represents a Minecraft equipment model for 1.21.2+. + * + * @since 1.7.4 + */ +@ApiStatus.NonExtendable +public interface Equipment extends ResourcePackPart, Keyed, Examinable { + @Contract("-> new") + static @NotNull Builder equipment() { + return new EquipmentImpl.BuilderImpl(); + } + + @Override + @NotNull Key key(); + + @Nullable Key humanoid(); + + @Nullable Key humanoidLeggings(); + + @Nullable Key horseBody(); + + @Nullable Key wings(); + + @Contract("-> new") + @NotNull default Builder toBuilder() { + return Equipment.equipment().key(key()) + .humanoid(humanoid()) + .humanoidLeggings(humanoidLeggings()); + } + + @Override + default void addTo(final @NotNull ResourceContainer resourceContainer) { + resourceContainer.equipment(this); + } + + interface Builder { + @Contract("_ -> this") + @NotNull Builder key(final @Nullable Key key); + + @Contract("_ -> this") + @NotNull Builder humanoid(final @Nullable Key humanoid); + + @Contract("_ -> this") + @NotNull Builder humanoidLeggings(final @Nullable Key humanoidLeggings); + + @Contract("_ -> this") + @NotNull Builder horseBody(final @Nullable Key horseBody); + + @Contract("_ -> this") + @NotNull Builder wings(final @Nullable Key wings); + + @Contract("-> new") + @NotNull Equipment build(); + + } +} diff --git a/api/src/main/java/team/unnamed/creative/equipment/EquipmentImpl.java b/api/src/main/java/team/unnamed/creative/equipment/EquipmentImpl.java new file mode 100644 index 00000000..351c4e9f --- /dev/null +++ b/api/src/main/java/team/unnamed/creative/equipment/EquipmentImpl.java @@ -0,0 +1,161 @@ +/* + * This file is part of creative, licensed under the MIT license + * + * Copyright (c) 2021-2023 Unnamed Team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package team.unnamed.creative.equipment; + +import net.kyori.adventure.key.Key; +import net.kyori.examination.ExaminableProperty; +import net.kyori.examination.string.StringExaminer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; +import java.util.stream.Stream; + +import static java.util.Objects.requireNonNull; + +public class EquipmentImpl implements Equipment { + private final Key key; + private final Key humanoid; + private final Key humanoidLeggings; + private final Key horseBody; + private final Key wings; + + EquipmentImpl( + final Key key, + final @Nullable Key humanoid, + final @Nullable Key humanoidLeggings, + final @Nullable Key horseBody, + final @Nullable Key wings + ) { + this.key = key; + this.humanoid = humanoid; + this.humanoidLeggings = humanoidLeggings; + this.horseBody = horseBody; + this.wings = wings; + } + + @Override + public @NotNull Key key() { + return key; + } + + @Override + public @Nullable Key humanoid() { + return humanoid; + } + + @Override + public @Nullable Key humanoidLeggings() { + return humanoidLeggings; + } + + @Override + public @Nullable Key horseBody() { + return horseBody; + } + + @Override + public @Nullable Key wings() { + return wings; + } + + @Override + public @NotNull Stream examinableProperties() { + return Stream.of( + ExaminableProperty.of("key", key), + ExaminableProperty.of("humanoid", humanoid), + ExaminableProperty.of("humanoidLeggings", humanoidLeggings), + ExaminableProperty.of("horseBody", horseBody), + ExaminableProperty.of("wings", wings) + ); + } + + @Override + public @NotNull String toString() { + return examine(StringExaminer.simpleEscaping()); + } + + @Override + public boolean equals(final @Nullable Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + final EquipmentImpl that = (EquipmentImpl) o; + return key.equals(that.key) + && Objects.equals(humanoid, that.humanoid) + && Objects.equals(humanoidLeggings, that.humanoidLeggings) + && Objects.equals(horseBody, that.horseBody) + && Objects.equals(wings, that.wings); + } + + @Override + public int hashCode() { + return Objects.hash(key, humanoid, humanoidLeggings, horseBody, wings); + } + + + + static final class BuilderImpl implements Equipment.Builder { + private Key key; + private Key humanoid; + private Key humanoidLeggings; + private Key horseBody; + private Key wings; + + @Override + public @NotNull Builder key(final @NotNull Key key) { + this.key = requireNonNull(key, "key"); + return this; + } + + @Override + public @NotNull Builder humanoid(final @Nullable Key humanoid) { + this.humanoid = humanoid; + return this; + } + + @Override + public @NotNull Builder humanoidLeggings(final @Nullable Key humanoidLeggings) { + this.humanoidLeggings = humanoidLeggings; + return this; + } + + @Override + public @NotNull Builder horseBody(final @Nullable Key horseBody) { + this.horseBody = horseBody; + return this; + } + + @Override + public @NotNull Builder wings(final @Nullable Key wings) { + this.wings = wings; + return this; + } + + @Override + public @NotNull Equipment build() { + return new EquipmentImpl(key, humanoid, humanoidLeggings, horseBody, wings); + } + + } +} diff --git a/api/src/main/java/team/unnamed/creative/overlay/ResourceContainer.java b/api/src/main/java/team/unnamed/creative/overlay/ResourceContainer.java index f25f2ea4..a0bd9697 100644 --- a/api/src/main/java/team/unnamed/creative/overlay/ResourceContainer.java +++ b/api/src/main/java/team/unnamed/creative/overlay/ResourceContainer.java @@ -30,6 +30,7 @@ import team.unnamed.creative.atlas.Atlas; import team.unnamed.creative.base.Writable; import team.unnamed.creative.blockstate.BlockState; +import team.unnamed.creative.equipment.Equipment; import team.unnamed.creative.font.Font; import team.unnamed.creative.font.FontProvider; import team.unnamed.creative.lang.Language; @@ -304,6 +305,14 @@ default void font(final @NotNull Key key, final @NotNull List prov @NotNull Collection models(); //#endregion + //#region Equipment Models + + void equipment(final @NotNull Equipment equipmentModel); + @Nullable Equipment equipment(final @NotNull Key key); + boolean removeEquipment(final @NotNull Key key); + @NotNull Collection equipments(); + //#endregion + //#region Sound Registries (Namespaced) /** diff --git a/api/src/main/java/team/unnamed/creative/overlay/ResourceContainerImpl.java b/api/src/main/java/team/unnamed/creative/overlay/ResourceContainerImpl.java index 6e8b9b10..10541662 100644 --- a/api/src/main/java/team/unnamed/creative/overlay/ResourceContainerImpl.java +++ b/api/src/main/java/team/unnamed/creative/overlay/ResourceContainerImpl.java @@ -31,6 +31,7 @@ import team.unnamed.creative.atlas.AtlasSource; import team.unnamed.creative.base.Writable; import team.unnamed.creative.blockstate.BlockState; +import team.unnamed.creative.equipment.Equipment; import team.unnamed.creative.font.Font; import team.unnamed.creative.font.FontProvider; import team.unnamed.creative.lang.Language; @@ -64,6 +65,7 @@ public class ResourceContainerImpl implements ResourceContainer { private final Map soundRegistries = new LinkedHashMap<>(); private final Map sounds = new LinkedHashMap<>(); private final Map textures = new LinkedHashMap<>(); + private final Map equipments = new LinkedHashMap<>(); // Unknown files we don't know how to parse private final Map files = new LinkedHashMap<>(); @@ -268,6 +270,31 @@ public boolean removeTexture(final @NotNull Key key) { } //#endregion + //#region Fonts (Keyed) + @Override + public void equipment(final @NotNull Equipment equipment) { + requireNonNull(equipment, "equipment"); + equipments.put(equipment.key(), equipment); + } + + @Override + public @Nullable Equipment equipment(final @NotNull Key key) { + requireNonNull(key, "key"); + return equipments.get(key); + } + + @Override + public boolean removeEquipment(final @NotNull Key key) { + requireNonNull(key, "key"); + return equipments.remove(key) != null; + } + + @Override + public @NotNull Collection equipments() { + return equipments.values(); + } + //#endregion + //#region Unknown Files (By absolute path) @Override public void unknownFile(final @NotNull String path, final @NotNull Writable data) { diff --git a/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/ResourceCategories.java b/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/ResourceCategories.java index f448f9be..89123d50 100644 --- a/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/ResourceCategories.java +++ b/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/ResourceCategories.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.Nullable; import team.unnamed.creative.serialize.minecraft.atlas.AtlasSerializer; import team.unnamed.creative.serialize.minecraft.blockstate.BlockStateSerializer; +import team.unnamed.creative.serialize.minecraft.equipment.EquipmentSerializer; import team.unnamed.creative.serialize.minecraft.font.FontSerializer; import team.unnamed.creative.serialize.minecraft.language.LanguageSerializer; import team.unnamed.creative.serialize.minecraft.model.ModelSerializer; @@ -47,6 +48,7 @@ public class ResourceCategories { registerCategory(LanguageSerializer.CATEGORY); registerCategory(BlockStateSerializer.CATEGORY); registerCategory(FontSerializer.CATEGORY); + registerCategory(EquipmentSerializer.CATEGORY); } private ResourceCategories() { diff --git a/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentSerializer.java b/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentSerializer.java new file mode 100644 index 00000000..7ce224ab --- /dev/null +++ b/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentSerializer.java @@ -0,0 +1,132 @@ +/* + * This file is part of creative, licensed under the MIT license + * + * Copyright (c) 2021-2023 Unnamed Team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package team.unnamed.creative.serialize.minecraft.equipment; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; +import net.kyori.adventure.key.Key; +import org.jetbrains.annotations.ApiStatus; +import team.unnamed.creative.equipment.Equipment; +import team.unnamed.creative.overlay.ResourceContainer; +import team.unnamed.creative.serialize.minecraft.ResourceCategory; +import team.unnamed.creative.serialize.minecraft.io.JsonResourceDeserializer; +import team.unnamed.creative.serialize.minecraft.io.JsonResourceSerializer; + +import java.io.IOException; + +@ApiStatus.Internal +public class EquipmentSerializer implements JsonResourceSerializer, JsonResourceDeserializer { + + public static final EquipmentSerializer INSTANCE; + public static final ResourceCategory CATEGORY; + + static { + INSTANCE = new EquipmentSerializer(); + CATEGORY = new ResourceCategory<>( + "equipment", + ".json", + ResourceContainer::equipment, + ResourceContainer::equipments, + EquipmentSerializer.INSTANCE + ); + } + + @Override + public void serializeToJson(Equipment equipment, JsonWriter writer) throws IOException { + writer.beginObject().name("layers").beginObject(); + + // humanoid + Key humanoid = equipment.humanoid(); + if (humanoid != null) { + writer.name("humanoid").beginArray(); + writer.name("texture").value(humanoid.toString()); + writer.endArray(); + } + + // humanoid_leggings + Key humanoidLeggings = equipment.humanoidLeggings(); + if (humanoidLeggings != null) { + writer.name("humanoid_leggings").beginArray(); + writer.name("texture").value(humanoidLeggings.toString()); + writer.endArray(); + } + + // horse_body + Key horseBody = equipment.horseBody(); + if (horseBody != null) { + writer.name("horse_body").beginArray(); + writer.name("texture").value(horseBody.toString()); + writer.endArray(); + } + + // wings + Key wings = equipment.wings(); + if (horseBody != null) { + writer.name("wings").beginArray(); + writer.name("texture").value(wings.toString()); + writer.endArray(); + } + + writer.endObject(); + writer.endObject(); + } + + @Override + public Equipment deserializeFromJson(JsonElement node, Key key) { + + JsonObject objectNode = node.getAsJsonObject().getAsJsonObject("layers"); + + // humanoid + Key humanoid = null; + if (objectNode.has("humanoid")) { + humanoid = Key.key(objectNode.getAsJsonArray("humanoid").get(0).getAsJsonObject().get("texture").getAsString()); + } + + // humanoid_leggings + Key humanoidLeggings = null; + if (objectNode.has("humanoid_leggings")) { + humanoidLeggings = Key.key(objectNode.getAsJsonArray("humanoid_leggings").get(0).getAsJsonObject().get("texture").getAsString()); + } + + // horse_body + Key horseBody = null; + if (objectNode.has("horse_body")) { + horseBody = Key.key(objectNode.getAsJsonArray("horse_body").get(0).getAsJsonObject().get("texture").getAsString()); + } + + // humanoid_leggings + Key wings = null; + if (objectNode.has("wings")) { + wings = Key.key(objectNode.getAsJsonArray("wings").get(0).getAsJsonObject().get("texture").getAsString()); + } + + return Equipment.equipment().key(key) + .humanoid(humanoid) + .humanoidLeggings(humanoidLeggings) + .horseBody(horseBody) + .wings(wings) + .build(); + } +} diff --git a/serializer-minecraft/src/test/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentDeserializationTest.java b/serializer-minecraft/src/test/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentDeserializationTest.java new file mode 100644 index 00000000..b5ac435b --- /dev/null +++ b/serializer-minecraft/src/test/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentDeserializationTest.java @@ -0,0 +1,82 @@ +/* + * This file is part of creative, licensed under the MIT license + * + * Copyright (c) 2021-2023 Unnamed Team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package team.unnamed.creative.serialize.minecraft.equipment; + +import net.kyori.adventure.key.Key; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import team.unnamed.creative.base.Axis3D; +import team.unnamed.creative.base.CubeFace; +import team.unnamed.creative.base.Readable; +import team.unnamed.creative.base.Vector3Float; +import team.unnamed.creative.equipment.Equipment; +import team.unnamed.creative.model.Element; +import team.unnamed.creative.model.ElementFace; +import team.unnamed.creative.model.ElementRotation; +import team.unnamed.creative.model.Model; +import team.unnamed.creative.model.ModelTexture; +import team.unnamed.creative.model.ModelTextures; +import team.unnamed.creative.serialize.minecraft.model.ModelSerializer; +import team.unnamed.creative.texture.TextureUV; + +import java.util.HashMap; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class EquipmentDeserializationTest { + @Test + @DisplayName("Test 'netherite.json' equipment deserialization") + void test_deserialize_netherite() throws Exception { + Equipment equipment = EquipmentSerializer.INSTANCE.deserialize( + Readable.resource(getClass().getClassLoader(), "equipment/netherite.json"), + Key.key("netherite") + ); + + assertEquals( + Equipment.equipment() + .key(Key.key("minecraft:netherite")) + .humanoid(Key.key("minecraft:netherite")) + .humanoidLeggings(Key.key("minecraft:netherite")) + .build(), + equipment + ); + } + + @Test + @DisplayName("Test 'wings.json' equipment deserialization") + void test_deserialize_wings() throws Exception { + Equipment equipment = EquipmentSerializer.INSTANCE.deserialize( + Readable.resource(getClass().getClassLoader(), "equipment/elytra.json"), + Key.key("elytra") + ); + + assertEquals( + Equipment.equipment() + .key(Key.key("minecraft:elytra")) + .wings(Key.key("minecraft:elytra")) + .build(), + equipment + ); + } +} diff --git a/serializer-minecraft/src/test/resources/equipment/elytra.json b/serializer-minecraft/src/test/resources/equipment/elytra.json new file mode 100644 index 00000000..e65c0d6d --- /dev/null +++ b/serializer-minecraft/src/test/resources/equipment/elytra.json @@ -0,0 +1,9 @@ +{ + "layers": { + "wings": [ + { + "texture": "minecraft:elytra" + } + ] + } +} \ No newline at end of file diff --git a/serializer-minecraft/src/test/resources/equipment/netherite.json b/serializer-minecraft/src/test/resources/equipment/netherite.json new file mode 100644 index 00000000..3f22e634 --- /dev/null +++ b/serializer-minecraft/src/test/resources/equipment/netherite.json @@ -0,0 +1,14 @@ +{ + "layers": { + "humanoid": [ + { + "texture": "minecraft:netherite" + } + ], + "humanoid_leggings": [ + { + "texture": "minecraft:netherite" + } + ] + } +} \ No newline at end of file From 93f9509b5144b7cf9c2b7180b0692f3d24152abe Mon Sep 17 00:00:00 2001 From: Boy Date: Thu, 28 Nov 2024 02:23:57 +0100 Subject: [PATCH 2/2] feat: add llama- & wolf-body fields --- .../unnamed/creative/equipment/Equipment.java | 20 ++++++- .../creative/equipment/EquipmentImpl.java | 56 +++++++++++++++---- .../equipment/EquipmentSerializer.java | 50 +++++++++++++---- 3 files changed, 102 insertions(+), 24 deletions(-) diff --git a/api/src/main/java/team/unnamed/creative/equipment/Equipment.java b/api/src/main/java/team/unnamed/creative/equipment/Equipment.java index 0a322609..fd782bd1 100644 --- a/api/src/main/java/team/unnamed/creative/equipment/Equipment.java +++ b/api/src/main/java/team/unnamed/creative/equipment/Equipment.java @@ -53,15 +53,23 @@ public interface Equipment extends ResourcePackPart, Keyed, Examinable { @Nullable Key humanoidLeggings(); + @Nullable Key wings(); + @Nullable Key horseBody(); - @Nullable Key wings(); + @Nullable Key llamaBody(); + + @Nullable Key wolfBody(); @Contract("-> new") @NotNull default Builder toBuilder() { return Equipment.equipment().key(key()) .humanoid(humanoid()) - .humanoidLeggings(humanoidLeggings()); + .humanoidLeggings(humanoidLeggings()) + .wings(wings()) + .horseBody(horseBody()) + .llamaBody(llamaBody()) + .wolfBody(wolfBody()); } @Override @@ -79,11 +87,17 @@ interface Builder { @Contract("_ -> this") @NotNull Builder humanoidLeggings(final @Nullable Key humanoidLeggings); + @Contract("_ -> this") + @NotNull Builder wings(final @Nullable Key wings); + @Contract("_ -> this") @NotNull Builder horseBody(final @Nullable Key horseBody); @Contract("_ -> this") - @NotNull Builder wings(final @Nullable Key wings); + @NotNull Builder llamaBody(final @Nullable Key llamaBody); + + @Contract("_ -> this") + @NotNull Builder wolfBody(final @Nullable Key wolfBody); @Contract("-> new") @NotNull Equipment build(); diff --git a/api/src/main/java/team/unnamed/creative/equipment/EquipmentImpl.java b/api/src/main/java/team/unnamed/creative/equipment/EquipmentImpl.java index 351c4e9f..a749b55b 100644 --- a/api/src/main/java/team/unnamed/creative/equipment/EquipmentImpl.java +++ b/api/src/main/java/team/unnamed/creative/equipment/EquipmentImpl.java @@ -38,21 +38,27 @@ public class EquipmentImpl implements Equipment { private final Key key; private final Key humanoid; private final Key humanoidLeggings; - private final Key horseBody; private final Key wings; + private final Key horseBody; + private final Key llamaBody; + private final Key wolfBody; EquipmentImpl( final Key key, final @Nullable Key humanoid, final @Nullable Key humanoidLeggings, + final @Nullable Key wings, final @Nullable Key horseBody, - final @Nullable Key wings + final @Nullable Key llamaBody, + final @Nullable Key wolfBody ) { this.key = key; this.humanoid = humanoid; this.humanoidLeggings = humanoidLeggings; - this.horseBody = horseBody; this.wings = wings; + this.horseBody = horseBody; + this.llamaBody = llamaBody; + this.wolfBody = wolfBody; } @Override @@ -70,14 +76,24 @@ public class EquipmentImpl implements Equipment { return humanoidLeggings; } + @Override + public @Nullable Key wings() { + return wings; + } + @Override public @Nullable Key horseBody() { return horseBody; } @Override - public @Nullable Key wings() { - return wings; + public @Nullable Key llamaBody() { + return llamaBody; + } + + @Override + public @Nullable Key wolfBody() { + return wolfBody; } @Override @@ -86,8 +102,10 @@ public class EquipmentImpl implements Equipment { ExaminableProperty.of("key", key), ExaminableProperty.of("humanoid", humanoid), ExaminableProperty.of("humanoidLeggings", humanoidLeggings), + ExaminableProperty.of("wings", wings), ExaminableProperty.of("horseBody", horseBody), - ExaminableProperty.of("wings", wings) + ExaminableProperty.of("llamaBody", llamaBody), + ExaminableProperty.of("wolfBody", wolfBody) ); } @@ -104,8 +122,10 @@ public boolean equals(final @Nullable Object o) { return key.equals(that.key) && Objects.equals(humanoid, that.humanoid) && Objects.equals(humanoidLeggings, that.humanoidLeggings) + && Objects.equals(wings, that.wings) && Objects.equals(horseBody, that.horseBody) - && Objects.equals(wings, that.wings); + && Objects.equals(llamaBody, that.llamaBody) + && Objects.equals(wolfBody, that.wolfBody); } @Override @@ -119,8 +139,10 @@ static final class BuilderImpl implements Equipment.Builder { private Key key; private Key humanoid; private Key humanoidLeggings; - private Key horseBody; private Key wings; + private Key horseBody; + private Key llamaBody; + private Key wolfBody; @Override public @NotNull Builder key(final @NotNull Key key) { @@ -140,6 +162,12 @@ static final class BuilderImpl implements Equipment.Builder { return this; } + @Override + public @NotNull Builder wings(final @Nullable Key wings) { + this.wings = wings; + return this; + } + @Override public @NotNull Builder horseBody(final @Nullable Key horseBody) { this.horseBody = horseBody; @@ -147,14 +175,20 @@ static final class BuilderImpl implements Equipment.Builder { } @Override - public @NotNull Builder wings(final @Nullable Key wings) { - this.wings = wings; + public @NotNull Builder llamaBody(final @Nullable Key llamaBody) { + this.llamaBody = llamaBody; + return this; + } + + @Override + public @NotNull Builder wolfBody(final @Nullable Key wolfBody) { + this.wolfBody = wolfBody; return this; } @Override public @NotNull Equipment build() { - return new EquipmentImpl(key, humanoid, humanoidLeggings, horseBody, wings); + return new EquipmentImpl(key, humanoid, humanoidLeggings, wings, horseBody, llamaBody, wolfBody); } } diff --git a/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentSerializer.java b/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentSerializer.java index 7ce224ab..92142d22 100644 --- a/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentSerializer.java +++ b/serializer-minecraft/src/main/java/team/unnamed/creative/serialize/minecraft/equipment/EquipmentSerializer.java @@ -73,6 +73,14 @@ public void serializeToJson(Equipment equipment, JsonWriter writer) throws IOExc writer.endArray(); } + // wings + Key wings = equipment.wings(); + if (wings != null) { + writer.name("wings").beginArray(); + writer.name("texture").value(wings.toString()); + writer.endArray(); + } + // horse_body Key horseBody = equipment.horseBody(); if (horseBody != null) { @@ -81,11 +89,19 @@ public void serializeToJson(Equipment equipment, JsonWriter writer) throws IOExc writer.endArray(); } - // wings - Key wings = equipment.wings(); - if (horseBody != null) { - writer.name("wings").beginArray(); - writer.name("texture").value(wings.toString()); + // llama_body + Key llamaBody = equipment.llamaBody(); + if (llamaBody != null) { + writer.name("llama_body").beginArray(); + writer.name("texture").value(llamaBody.toString()); + writer.endArray(); + } + + // wolf_body + Key wolfBody = equipment.wolfBody(); + if (wolfBody != null) { + writer.name("wolf_body").beginArray(); + writer.name("texture").value(wolfBody.toString()); writer.endArray(); } @@ -110,23 +126,37 @@ public Equipment deserializeFromJson(JsonElement node, Key key) { humanoidLeggings = Key.key(objectNode.getAsJsonArray("humanoid_leggings").get(0).getAsJsonObject().get("texture").getAsString()); } + // wings + Key wings = null; + if (objectNode.has("wings")) { + wings = Key.key(objectNode.getAsJsonArray("wings").get(0).getAsJsonObject().get("texture").getAsString()); + } + // horse_body Key horseBody = null; if (objectNode.has("horse_body")) { horseBody = Key.key(objectNode.getAsJsonArray("horse_body").get(0).getAsJsonObject().get("texture").getAsString()); } - // humanoid_leggings - Key wings = null; - if (objectNode.has("wings")) { - wings = Key.key(objectNode.getAsJsonArray("wings").get(0).getAsJsonObject().get("texture").getAsString()); + // llama_body + Key llamaBody = null; + if (objectNode.has("llama_body")) { + llamaBody = Key.key(objectNode.getAsJsonArray("llama_body").get(0).getAsJsonObject().get("texture").getAsString()); + } + + // wolf_body + Key wolfBody = null; + if (objectNode.has("wolf_body")) { + wolfBody = Key.key(objectNode.getAsJsonArray("wolf_body").get(0).getAsJsonObject().get("texture").getAsString()); } return Equipment.equipment().key(key) .humanoid(humanoid) .humanoidLeggings(humanoidLeggings) - .horseBody(horseBody) .wings(wings) + .horseBody(horseBody) + .llamaBody(llamaBody) + .wolfBody(wolfBody) .build(); } }