From 7a4f7fe9e04f2062ed575a2fdbf313d9d52fab73 Mon Sep 17 00:00:00 2001 From: Patbox Date: Wed, 27 Nov 2024 21:17:01 +0100 Subject: [PATCH] Update resource pack api, now with a way to create typed item asset definitions on the fly, update to pre3 --- .github/workflows/mkdocs-publish.yml | 2 +- build.gradle | 2 + gradle.properties | 6 +- polymer-autohost/build.gradle | 1 + polymer-blocks/build.gradle | 2 + .../java/eu/pb4/blocktest/TestItem.java | 4 +- .../common/api/PolymerCommonUtils.java | 2 +- polymer-core/build.gradle | 3 +- .../java/eu/pb4/polymertest/TestMod.java | 41 +++-- polymer-resource-pack-extras/build.gradle | 37 +++++ polymer-resource-pack-extras/settings.gradle | 1 + .../extras/api/ResourcePackExtras.java | 150 ++++++++++++++++++ .../extras/api/format/item/ItemAsset.java | 31 ++++ .../api/format/item/model/BasicItemModel.java | 25 +++ .../item/model/BundleSelectedItemModel.java | 12 ++ .../format/item/model/CompositeItemModel.java | 17 ++ .../format/item/model/ConditionItemModel.java | 21 +++ .../api/format/item/model/EmptyItemModel.java | 12 ++ .../api/format/item/model/ItemModel.java | 25 +++ .../item/model/RangeDispatchItemModel.java | 30 ++++ .../format/item/model/SelectItemModel.java | 40 +++++ .../format/item/model/SpecialItemModel.java | 18 +++ .../item/property/bool/BooleanProperty.java | 28 ++++ .../item/property/bool/BrokenProperty.java | 13 ++ .../bool/BundleHasSelectedItemProperty.java | 12 ++ .../item/property/bool/CarriedProperty.java | 12 ++ .../bool/CustomModelDataFlagProperty.java | 17 ++ .../item/property/bool/DamagedProperty.java | 12 ++ .../property/bool/ExtendedViewProperty.java | 13 ++ .../property/bool/FishingRodCastProperty.java | 13 ++ .../property/bool/HasComponentProperty.java | 20 +++ .../property/bool/KeybindDownProperty.java | 16 ++ .../item/property/bool/SelectedProperty.java | 12 ++ .../item/property/bool/UsingItemProperty.java | 12 ++ .../property/bool/ViewEntityProperty.java | 12 ++ .../numeric/BundleFullnessProperty.java | 12 ++ .../property/numeric/CompassProperty.java | 37 +++++ .../property/numeric/CooldownProperty.java | 12 ++ .../item/property/numeric/CountProperty.java | 17 ++ .../numeric/CrossbowPullProperty.java | 12 ++ .../numeric/CustomModelDataFloatProperty.java | 17 ++ .../item/property/numeric/DamageProperty.java | 17 ++ .../property/numeric/NumericProperty.java | 26 +++ .../item/property/numeric/TimeProperty.java | 39 +++++ .../property/numeric/UseCycleProperty.java | 16 ++ .../property/numeric/UseDurationProperty.java | 18 +++ .../property/select/ChargeTypeProperty.java | 16 ++ .../select/ContextDimensionProperty.java | 17 ++ .../select/ContextEntityTypeProperty.java | 17 ++ .../select/CustomModelDataStringProperty.java | 19 +++ .../select/DisplayContextProperty.java | 15 ++ .../select/ItemBlockStateProperty.java | 20 +++ .../property/select/LocalTimeProperty.java | 22 +++ .../property/select/MainHandProperty.java | 13 ++ .../item/property/select/SelectProperty.java | 70 ++++++++ .../property/select/TrimMaterialProperty.java | 17 ++ .../item/special/BannerSpecialModel.java | 19 +++ .../format/item/special/BedSpecialModel.java | 18 +++ .../item/special/ChestSpecialModel.java | 20 +++ .../item/special/ConduitSpecialModel.java | 15 ++ .../special/DecoratedPotSpecialModel.java | 12 ++ .../item/special/HangingSignSpecialModel.java | 21 +++ .../format/item/special/HeadSpecialModel.java | 24 +++ .../item/special/ShieldSpecialModel.java | 12 ++ .../item/special/ShulkerBoxSpecialModel.java | 22 +++ .../format/item/special/SignSpecialModel.java | 21 +++ .../api/format/item/special/SpecialModel.java | 29 ++++ .../item/special/TridentSpecialModel.java | 12 ++ .../format/item/tint/ConstantTintSource.java | 16 ++ .../item/tint/CustomModelDataTintSource.java | 17 ++ .../api/format/item/tint/DyeTintSource.java | 16 ++ .../format/item/tint/FireworkTintSource.java | 20 +++ .../api/format/item/tint/GrassTintSource.java | 21 +++ .../api/format/item/tint/ItemTintSource.java | 26 +++ .../format/item/tint/MapColorTintSource.java | 21 +++ .../format/item/tint/PotionTintSource.java | 20 +++ .../api/format/item/tint/TeamTintSource.java | 16 ++ .../src/main/resources/assets/icon.png | Bin 0 -> 583 bytes .../src/main/resources/fabric.mod.json | 41 +++++ .../polymer/resourcepack/api/AssetPaths.java | 16 +- .../api/PolymerResourcePackUtils.java | 25 +-- .../resourcepack/api/ResourcePackBuilder.java | 2 +- .../resourcepack/api/ResourcePackCreator.java | 128 +++------------ .../resourcepack/api/model/ItemOverride.java | 98 ------------ .../impl/PolymerResourcePackImpl.java | 17 -- .../impl/generation/DefaultRPBuilder.java | 66 +------- settings.gradle | 1 + 87 files changed, 1576 insertions(+), 339 deletions(-) create mode 100644 polymer-resource-pack-extras/build.gradle create mode 100644 polymer-resource-pack-extras/settings.gradle create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/ResourcePackExtras.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/ItemAsset.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/BasicItemModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/BundleSelectedItemModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/CompositeItemModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/ConditionItemModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/EmptyItemModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/ItemModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/RangeDispatchItemModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/SelectItemModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/SpecialItemModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BooleanProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BrokenProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BundleHasSelectedItemProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/CarriedProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/CustomModelDataFlagProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/DamagedProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/ExtendedViewProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/FishingRodCastProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/HasComponentProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/KeybindDownProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/SelectedProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/UsingItemProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/ViewEntityProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/BundleFullnessProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CompassProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CooldownProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CountProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CrossbowPullProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CustomModelDataFloatProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/DamageProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/NumericProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/TimeProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/UseCycleProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/UseDurationProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ChargeTypeProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ContextDimensionProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ContextEntityTypeProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/CustomModelDataStringProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/DisplayContextProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ItemBlockStateProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/LocalTimeProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/MainHandProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/SelectProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/TrimMaterialProperty.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/BannerSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/BedSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ChestSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ConduitSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/DecoratedPotSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/HangingSignSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/HeadSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ShieldSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ShulkerBoxSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/SignSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/SpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/TridentSpecialModel.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/ConstantTintSource.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/CustomModelDataTintSource.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/DyeTintSource.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/FireworkTintSource.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/GrassTintSource.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/ItemTintSource.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/MapColorTintSource.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/PotionTintSource.java create mode 100644 polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/TeamTintSource.java create mode 100644 polymer-resource-pack-extras/src/main/resources/assets/icon.png create mode 100644 polymer-resource-pack-extras/src/main/resources/fabric.mod.json delete mode 100644 polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/model/ItemOverride.java diff --git a/.github/workflows/mkdocs-publish.yml b/.github/workflows/mkdocs-publish.yml index 68e23093..dff6fdd5 100644 --- a/.github/workflows/mkdocs-publish.yml +++ b/.github/workflows/mkdocs-publish.yml @@ -21,5 +21,5 @@ jobs: git config --global user.name Docs deploy git config --global user.email docs@dummy.bot.com mike set-default latest - mike deploy --push --update-aliases 0.10.x latest + mike deploy --push --update-aliases 0.11.x latest diff --git a/build.gradle b/build.gradle index d152bcaa..20190c86 100644 --- a/build.gradle +++ b/build.gradle @@ -118,6 +118,7 @@ dependencies { api project(path: ":polymer-core", configuration: "namedElements") api project(path: ":polymer-common", configuration: "namedElements") api project(path: ":polymer-resource-pack", configuration: "namedElements") + api project(path: ":polymer-resource-pack-extras", configuration: "namedElements") api project(path: ":polymer-blocks", configuration: "namedElements") api project(path: ":polymer-virtual-entity", configuration: "namedElements") @@ -125,6 +126,7 @@ dependencies { include(project(path: ":polymer-core")) include(project(path: ":polymer-common")) include(project(path: ":polymer-resource-pack")) + include(project(path: ":polymer-resource-pack-extras")) include(project(path: ":polymer-blocks")) include(project(path: ":polymer-virtual-entity")) } diff --git a/gradle.properties b/gradle.properties index 19e086e0..064a1504 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,12 +4,12 @@ org.gradle.jvmargs=-Xmx4G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.21.4-pre1 -yarn_mappings=1.21.4-pre1+build.1 +minecraft_version=1.21.4-pre3 +yarn_mappings=1.21.4-pre3+build.2 loader_version=0.16.9 # Fabric API -fabric_version=0.109.1+1.21.4 +fabric_version=0.110.2+1.21.4 maven_group = eu.pb4 diff --git a/polymer-autohost/build.gradle b/polymer-autohost/build.gradle index fb8df267..f9577162 100644 --- a/polymer-autohost/build.gradle +++ b/polymer-autohost/build.gradle @@ -34,6 +34,7 @@ dependencies { testmodImplementation (project(path: ':polymer-blocks', configuration: 'namedElements')) testmodImplementation (project(path: ':polymer-reg-sync-manipulator', configuration: 'namedElements')) testmodImplementation (project(path: ':polymer-networking', configuration: 'namedElements')) + testmodImplementation (project(path: ':polymer-resource-pack-extras', configuration: 'namedElements')) compileOnly (project(path: ':polymer-virtual-entity', configuration: 'namedElements')) localRuntime (project(path: ':polymer-virtual-entity', configuration: 'namedElements')) diff --git a/polymer-blocks/build.gradle b/polymer-blocks/build.gradle index 9daff2c5..2f8f051d 100644 --- a/polymer-blocks/build.gradle +++ b/polymer-blocks/build.gradle @@ -33,6 +33,8 @@ dependencies { implementation(project(path: ':polymer-core', configuration: 'namedElements')) implementation(project(path: ':polymer-common', configuration: 'namedElements')) implementation(project(path: ':polymer-resource-pack', configuration: 'namedElements')) + compileOnly project(path: ":polymer-resource-pack-extras", configuration: "namedElements") + modCompileOnly "me.lucko:fabric-permissions-api:0.1-SNAPSHOT" //modLocalRuntime "fr.catcore:server-translations-api:1.4.9+1.18.2-rc1" diff --git a/polymer-blocks/src/testmod/java/eu/pb4/blocktest/TestItem.java b/polymer-blocks/src/testmod/java/eu/pb4/blocktest/TestItem.java index 009b12c7..477a6220 100644 --- a/polymer-blocks/src/testmod/java/eu/pb4/blocktest/TestItem.java +++ b/polymer-blocks/src/testmod/java/eu/pb4/blocktest/TestItem.java @@ -1,7 +1,7 @@ package eu.pb4.blocktest; import eu.pb4.polymer.core.api.item.PolymerItem; -import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; +import eu.pb4.polymer.resourcepack.extras.api.ResourcePackExtras; import net.minecraft.block.Block; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; @@ -15,7 +15,7 @@ public class TestItem extends BlockItem implements PolymerItem { private final Identifier polymerModel; public TestItem(Settings settings, Block block, String modelId) { super(block, settings); - this.polymerModel = PolymerResourcePackUtils.getBridgedModelId(Identifier.of("blocktest", modelId)); + this.polymerModel = ResourcePackExtras.bridgeModel(Identifier.of("blocktest", modelId)); } diff --git a/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java b/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java index 7d12376c..3d78f9f5 100644 --- a/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java +++ b/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java @@ -33,7 +33,7 @@ private PolymerCommonUtils() {} public static final SimpleEvent ON_RESOURCE_PACK_STATUS_CHANGE = new SimpleEvent<>(); private static Path cachedClientPath; - private final static String SAFE_CLIENT_SHA1 = "6f67d19b4467240639cb2c368ffd4b94ba889705"; + private final static String SAFE_CLIENT_SHA1 = "b6959dbb500a337a3a26c0ab3ca27216750bcd9f"; private final static String SAFE_CLIENT_URL = "https://piston-data.mojang.com/v1/objects/" + SAFE_CLIENT_SHA1 + "/client.jar"; private static Path cachedClientJarRoot; diff --git a/polymer-core/build.gradle b/polymer-core/build.gradle index 54a78788..d50b7b05 100644 --- a/polymer-core/build.gradle +++ b/polymer-core/build.gradle @@ -85,7 +85,8 @@ dependencies { compileOnly (project(path: ':polymer-resource-pack', configuration: 'namedElements')) localRuntime (project(path: ':polymer-resource-pack', configuration: 'namedElements')) - + compileOnly (project(path: ':polymer-resource-pack-extras', configuration: 'namedElements')) + localRuntime (project(path: ':polymer-resource-pack-extras', configuration: 'namedElements')) compileOnly (project(path: ':polymer-virtual-entity', configuration: 'namedElements')) localRuntime (project(path: ':polymer-virtual-entity', configuration: 'namedElements')) } diff --git a/polymer-core/src/testmod/java/eu/pb4/polymertest/TestMod.java b/polymer-core/src/testmod/java/eu/pb4/polymertest/TestMod.java index b6cbeb39..08ed2c8f 100644 --- a/polymer-core/src/testmod/java/eu/pb4/polymertest/TestMod.java +++ b/polymer-core/src/testmod/java/eu/pb4/polymertest/TestMod.java @@ -1,5 +1,6 @@ package eu.pb4.polymertest; +import eu.pb4.polymer.common.api.PolymerCommonUtils; import eu.pb4.polymer.core.api.block.BlockMapper; import eu.pb4.polymer.core.api.block.SimplePolymerBlock; import eu.pb4.polymer.core.api.entity.PolymerEntityUtils; @@ -11,6 +12,8 @@ import eu.pb4.polymer.core.impl.PolymerImpl; import eu.pb4.polymer.core.impl.client.InternalClientRegistry; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; +import eu.pb4.polymer.resourcepack.extras.api.ResourcePackExtras; +import eu.pb4.polymer.resourcepack.extras.api.format.item.ItemAsset; import eu.pb4.polymer.virtualentity.api.tracker.EntityTrackedData; import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; @@ -34,9 +37,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.*; import net.minecraft.item.consume.ApplyEffectsConsumeEffect; -import net.minecraft.nbt.NbtElement; -import net.minecraft.network.listener.ClientPlayPacketListener; -import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.s2c.play.*; import net.minecraft.potion.Potion; import net.minecraft.recipe.RecipeSerializer; @@ -49,24 +49,20 @@ import net.minecraft.server.network.DebugInfoSender; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; import net.minecraft.stat.StatFormatter; import net.minecraft.stat.Stats; import net.minecraft.text.Text; import net.minecraft.text.TranslatableTextContent; import net.minecraft.util.*; -import net.minecraft.util.math.ColorHelper; import net.minecraft.village.TradeOffer; -import net.minecraft.village.TradeOffers; import net.minecraft.village.TradedItem; import net.minecraft.village.VillagerProfession; import net.minecraft.world.GameMode; import net.minecraft.world.World; -import net.minecraft.world.biome.source.BiomeAccess; import xyz.nucleoid.server.translations.api.LocalizationTarget; -import xyz.nucleoid.server.translations.impl.ServerTranslations; +import java.io.IOException; +import java.nio.file.Files; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; @@ -257,8 +253,8 @@ private static void regArmor(EquipmentSlot slot, String main, String id) { public void onInitialize() { //ITEM_GROUP.setIcon(); PolymerResourcePackUtils.addModAssets("apolymertest"); - PolymerResourcePackUtils.addBridgedModelsFolder(Identifier.of("polymertest", "testificate")); - PolymerResourcePackUtils.addBridgedModelsFolder(Identifier.of("blocktest", "block")); + ResourcePackExtras.forDefault().addBridgedModelsFolder(Identifier.of("polymertest", "testificate")); + ResourcePackExtras.forDefault().addBridgedModelsFolder(Identifier.of("blocktest", "block")); PolymerResourcePackUtils.getInstance().setPackDescription(Text.literal("TEST REPLACED DESCRIPTION").formatted(Formatting.GREEN)); //PolymerResourcePackUtils.markAsRequired(); //PolymerResourcePackUtils.addModAsAssetsSource("promenade"); @@ -500,6 +496,29 @@ public void onInitialize() { if (PolymerImpl.IS_CLIENT) { InternalClientRegistry.decodeState(-1); } + + new Thread(() -> { + var vanillaJar = PolymerCommonUtils.getClientJarRoot(); + + var itemsBase = vanillaJar.resolve("assets/minecraft/items/"); + + try { + Files.walk(itemsBase, 1).forEach(path -> { + try { + var asset = ItemAsset.fromJson(Files.readString(path)); + //System.out.println(path + ">" + asset); + } catch (Throwable e) { + System.err.println("Error while parsing file: " + path); + e.printStackTrace(); + } + + }); + } catch (IOException e) { + e.printStackTrace(); + } + + + }).run(); } public static T register(Registry registry, Identifier id, T obj) { diff --git a/polymer-resource-pack-extras/build.gradle b/polymer-resource-pack-extras/build.gradle new file mode 100644 index 00000000..ffc826d0 --- /dev/null +++ b/polymer-resource-pack-extras/build.gradle @@ -0,0 +1,37 @@ +archivesBaseName = "polymer-resource-pack-extras" +version = rootProject.mod_version + "+" + rootProject.minecraft_version +group = rootProject.maven_group + +sourceSets { + testmod { + compileClasspath += main.compileClasspath + runtimeClasspath += main.runtimeClasspath + } +} + +loom { + +} + +dependencies { + modCompileOnly "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}" + + api (project(path: ':polymer-common', configuration: 'namedElements')) + api (project(path: ':polymer-resource-pack', configuration: 'namedElements')) +} + +afterEvaluate { + // Disable the gen sources task on sub projects + genSourcesWithFernFlower.enabled = true + genSourcesWithCfr.enabled = false +} + +processResources { + inputs.property "version", project.version + inputs.property "minecraft_version_supported", rootProject.minecraft_version_supported + + filesMatching("fabric.mod.json") { + expand "version": project.version + expand "minecraft_version_supported": rootProject.minecraft_version_supported + } +} \ No newline at end of file diff --git a/polymer-resource-pack-extras/settings.gradle b/polymer-resource-pack-extras/settings.gradle new file mode 100644 index 00000000..485f2ef1 --- /dev/null +++ b/polymer-resource-pack-extras/settings.gradle @@ -0,0 +1 @@ +project.name = 'polymer-resource-pack-extras' \ No newline at end of file diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/ResourcePackExtras.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/ResourcePackExtras.java new file mode 100644 index 00000000..e49d42c3 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/ResourcePackExtras.java @@ -0,0 +1,150 @@ +package eu.pb4.polymer.resourcepack.extras.api; + +import eu.pb4.polymer.resourcepack.api.AssetPaths; +import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; +import eu.pb4.polymer.resourcepack.api.ResourcePackBuilder; +import eu.pb4.polymer.resourcepack.api.ResourcePackCreator; +import eu.pb4.polymer.resourcepack.extras.api.format.item.ItemAsset; +import eu.pb4.polymer.resourcepack.extras.api.format.item.model.BasicItemModel; +import eu.pb4.polymer.resourcepack.extras.api.format.item.tint.CustomModelDataTintSource; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; + +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.function.BiFunction; + +/** + * Utilities allowing simple creation of resource pack + */ +public final class ResourcePackExtras { + private static final ResourcePackExtras MAIN = new ResourcePackExtras(PolymerResourcePackUtils.getInstance()); + private final Map> bridgedModels = new HashMap<>(); + + ResourcePackExtras(ResourcePackCreator creator) { + creator.afterInitialCreationEvent.register(this::setup); + } + + public static ResourcePackExtras forDefault() { + return MAIN; + } + + public static ResourcePackExtras of(ResourcePackCreator creator) { + if (PolymerResourcePackUtils.getInstance() == creator) { + return MAIN; + } + return new ResourcePackExtras(creator); + } + + public static ResourcePackExtras of(ResourcePackCreator creator, ResourcePackExtras source) { + if (PolymerResourcePackUtils.getInstance() == creator) { + throw new IllegalArgumentException("Passed creator matches PolymerResourcePackUtils.getInstance(), so you can't copy settings from other sources to it!"); + } + + var extras = new ResourcePackExtras(creator); + extras.bridgedModels.putAll(source.bridgedModels); + return extras; + } + + public static Identifier bridgeModelNoItem(Identifier model) { + if (model.getPath().startsWith("item/")) { + return model.withPath(model.getPath().substring("item/".length())); + } + + return bridgeModel(model); + } + + public static Identifier bridgeModel(Identifier model) { + return model.withPrefixedPath("-/"); + } + + /** + * Adds a bridge, allowing you to access any model from selected folder as `namespace:-/modelpath`. + * + * @param modelFolderId Model folder to bridge. For example "mod:block" will bridge all models from "assets/mod/models/block" + * @return Success of addition. + */ + public boolean addBridgedModelsFolder(Identifier modelFolderId) { + return addBridgedModelsFolder(modelFolderId, + (identifier, resourcePackBuilder) -> new ItemAsset(new BasicItemModel(identifier), ItemAsset.Properties.DEFAULT) + ); + } + + public boolean addBridgedModelsFolderWithColor(Identifier modelFolderId) { + return addBridgedModelsFolder(modelFolderId, + (identifier, resourcePackBuilder) -> new ItemAsset(new BasicItemModel(identifier, + List.of( + new CustomModelDataTintSource(0, 0xFFFFFF), + new CustomModelDataTintSource(1, 0xFFFFFF), + new CustomModelDataTintSource(2, 0xFFFFFF), + new CustomModelDataTintSource(3, 0xFFFFFF)) + ), ItemAsset.Properties.DEFAULT) + ); + } + + public boolean addBridgedModelsFolder(Identifier modelFolderId, BiFunction bridgeBuilder) { + this.bridgedModels.put(modelFolderId.getPath().endsWith("/") ? modelFolderId.withPath(x -> x.substring(0, x.length() - 1)) : modelFolderId, bridgeBuilder); + return true; + } + + public boolean addBridgedModelsFolder(Identifier... modelFolderId) { + var b = true; + for (var model : modelFolderId) { + b &= addBridgedModelsFolder(model); + } + return b; + } + + public boolean addBridgedModelsFolder(Collection modelFolderId) { + var b = true; + for (var model : modelFolderId) { + b &= addBridgedModelsFolder(model); + } + return b; + } + + public boolean addBridgedModelsFolder(Collection modelFolderId, BiFunction bridgeBuilder) { + var b = true; + for (var model : modelFolderId) { + b &= addBridgedModelsFolder(model, bridgeBuilder); + } + return b; + } + + + private void setup(ResourcePackBuilder builder) { + if (!this.bridgedModels.isEmpty()) { + builder.addPreFinishTask((b) -> { + b.forEachFile((path, out) -> { + if (!path.startsWith("assets/")) { + return; + } + path = path.substring("assets/".length()); + + for (var x : this.bridgedModels.entrySet()) { + var key = x.getKey(); + var y = key.getNamespace() + "/models/" + key.getPath() + "/"; + if (path.startsWith(y)) { + if (!path.endsWith(".json")) { + return; + } + path = path.substring(key.getNamespace().length() + "/models/".length(), path.length() - ".json".length()); + + var assetPath = AssetPaths.itemAsset(key.withPath("-/" + path)); + + if (b.getData(assetPath) != null) { + return; + } + + var asset = x.getValue().apply(key.withPath(path), b); + if (asset != null) { + b.addData(assetPath, asset.toJson().getBytes(StandardCharsets.UTF_8)); + } + return; + } + } + }); + }); + } + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/ItemAsset.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/ItemAsset.java new file mode 100644 index 00000000..f9587f82 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/ItemAsset.java @@ -0,0 +1,31 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item; + +import com.google.gson.JsonParser; +import com.mojang.serialization.Codec; +import com.mojang.serialization.JsonOps; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import eu.pb4.polymer.resourcepack.extras.api.format.item.model.ItemModel; + +public record ItemAsset(ItemModel model, Properties properties) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ItemModel.CODEC.fieldOf("model").forGetter(ItemAsset::model), + Properties.CODEC.forGetter(ItemAsset::properties) + ).apply(instance, ItemAsset::new) + ); + + public String toJson() { + return CODEC.encodeStart(JsonOps.INSTANCE, this).getOrThrow().toString(); + } + + public static ItemAsset fromJson(String json) { + return CODEC.decode(JsonOps.INSTANCE, JsonParser.parseString(json)).getOrThrow().getFirst(); + } + + public record Properties(boolean handAnimationOnSwap) { + public static final Properties DEFAULT = new Properties(true); + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.BOOL.optionalFieldOf("hand_animation_on_swap", true).forGetter(Properties::handAnimationOnSwap) + ).apply(instance, Properties::new)); + } +} \ No newline at end of file diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/BasicItemModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/BasicItemModel.java new file mode 100644 index 00000000..0ec23be3 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/BasicItemModel.java @@ -0,0 +1,25 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.model; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import eu.pb4.polymer.resourcepack.extras.api.format.item.tint.ItemTintSource; +import net.minecraft.util.Identifier; + +import java.util.List; + +public record BasicItemModel(Identifier model, List tints) implements ItemModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Identifier.CODEC.fieldOf("model").forGetter(BasicItemModel::model), + ItemTintSource.CODEC.listOf().optionalFieldOf("tints", List.of()).forGetter(BasicItemModel::tints) + ).apply(instance, BasicItemModel::new)); + + public BasicItemModel(Identifier model) { + this(model, List.of()); + } + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/BundleSelectedItemModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/BundleSelectedItemModel.java new file mode 100644 index 00000000..afedd700 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/BundleSelectedItemModel.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.model; + +import com.mojang.serialization.MapCodec; + +public record BundleSelectedItemModel() implements ItemModel { + public static final BundleSelectedItemModel INSTANCE = new BundleSelectedItemModel(); + public static final MapCodec CODEC = MapCodec.unit(INSTANCE); + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/CompositeItemModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/CompositeItemModel.java new file mode 100644 index 00000000..bf899911 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/CompositeItemModel.java @@ -0,0 +1,17 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.model; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import java.util.List; + +public record CompositeItemModel(List models) implements ItemModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + ItemModel.CODEC.listOf().fieldOf("models").forGetter(CompositeItemModel::models) + ).apply(instance, CompositeItemModel::new)); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/ConditionItemModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/ConditionItemModel.java new file mode 100644 index 00000000..71b08e90 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/ConditionItemModel.java @@ -0,0 +1,21 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.model; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool.BooleanProperty; + + +public record ConditionItemModel(BooleanProperty property, ItemModel onTrue, ItemModel onFalse) implements ItemModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec( + instance -> instance.group( + BooleanProperty.CODEC.forGetter(ConditionItemModel::property), + ItemModel.CODEC.fieldOf("on_true").forGetter(ConditionItemModel::onTrue), + ItemModel.CODEC.fieldOf("on_false").forGetter(ConditionItemModel::onFalse) + ).apply(instance, ConditionItemModel::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} \ No newline at end of file diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/EmptyItemModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/EmptyItemModel.java new file mode 100644 index 00000000..aaf3f6e8 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/EmptyItemModel.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.model; + +import com.mojang.serialization.MapCodec; + +public record EmptyItemModel() implements ItemModel { + public static final EmptyItemModel INSTANCE = new EmptyItemModel(); + public static final MapCodec CODEC = MapCodec.unit(INSTANCE); + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/ItemModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/ItemModel.java new file mode 100644 index 00000000..83338176 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/ItemModel.java @@ -0,0 +1,25 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.model; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; +import net.minecraft.util.dynamic.Codecs; + +import java.util.function.Function; + +public interface ItemModel { + Codec CODEC = Codec.lazyInitialized(() -> ItemModel.TYPES.getCodec(Identifier.CODEC).dispatch(ItemModel::codec, Function.identity())); + Codecs.IdMapper> TYPES = Util.make(new Codecs.IdMapper<>(), m -> { + m.put(Identifier.ofVanilla("empty"), EmptyItemModel.CODEC); + m.put(Identifier.ofVanilla("model"), BasicItemModel.CODEC); + m.put(Identifier.ofVanilla("special"), SpecialItemModel.CODEC); + m.put(Identifier.ofVanilla("composite"), CompositeItemModel.CODEC); + m.put(Identifier.ofVanilla("bundle/selected_item"), BundleSelectedItemModel.CODEC); + m.put(Identifier.ofVanilla("range_dispatch"), RangeDispatchItemModel.CODEC); + m.put(Identifier.ofVanilla("select"), SelectItemModel.CODEC); + m.put(Identifier.ofVanilla("condition"), ConditionItemModel.CODEC); + }); + + MapCodec codec(); +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/RangeDispatchItemModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/RangeDispatchItemModel.java new file mode 100644 index 00000000..c58d967f --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/RangeDispatchItemModel.java @@ -0,0 +1,30 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.model; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric.NumericProperty; + +import java.util.List; +import java.util.Optional; + +public record RangeDispatchItemModel(NumericProperty property, float scale, List entries, Optional fallback) implements ItemModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + NumericProperty.CODEC.forGetter(RangeDispatchItemModel::property), + Codec.FLOAT.optionalFieldOf("scale", 1f).forGetter(RangeDispatchItemModel::scale), + Entry.CODEC.listOf().fieldOf("entries").forGetter(RangeDispatchItemModel::entries), + ItemModel.CODEC.optionalFieldOf("fallback").forGetter(RangeDispatchItemModel::fallback) + ).apply(instance, RangeDispatchItemModel::new)); + + @Override + public MapCodec codec() { + return CODEC; + } + + public record Entry(float threshold, ItemModel model) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.FLOAT.fieldOf("threshold").forGetter(Entry::threshold), + ItemModel.CODEC.fieldOf("model").forGetter(Entry::model) + ).apply(instance, Entry::new)); + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/SelectItemModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/SelectItemModel.java new file mode 100644 index 00000000..8f14b140 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/SelectItemModel.java @@ -0,0 +1,40 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.model; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import eu.pb4.polymer.resourcepack.extras.api.format.item.property.select.SelectProperty; +import net.minecraft.util.dynamic.Codecs; + +import java.util.List; +import java.util.Optional; + +public record SelectItemModel, V>(Switch switchValue, + Optional fallback) implements ItemModel { + public static final MapCodec> CODEC = RecordCodecBuilder.mapCodec( + instance -> instance.group( + Switch.CODEC.forGetter(SelectItemModel::switchValue), + ItemModel.CODEC.optionalFieldOf("fallback").forGetter(SelectItemModel::fallback) + ).apply(instance, SelectItemModel::new) + ); + + @Override + public MapCodec> codec() { + return CODEC; + } + + public record Switch, V>(T property, List> cases) { + public static final MapCodec> CODEC = SelectProperty.CODEC + .dispatchMap("property", unbakedSwitch -> unbakedSwitch.property().type(), SelectProperty.Type::switchCodec); + } + + public record Case(List values, ItemModel model) { + public static Codec> createCodec(Codec valueCodec) { + return RecordCodecBuilder.create(instance -> instance.group( + Codecs.nonEmptyList(Codecs.listOrSingle(valueCodec)).fieldOf("when").forGetter(Case::values), + ItemModel.CODEC.fieldOf("model").forGetter(Case::model) + ).apply(instance, Case::new) + ); + } + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/SpecialItemModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/SpecialItemModel.java new file mode 100644 index 00000000..71ef1725 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/model/SpecialItemModel.java @@ -0,0 +1,18 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.model; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import eu.pb4.polymer.resourcepack.extras.api.format.item.special.SpecialModel; +import net.minecraft.util.Identifier; + +public record SpecialItemModel(Identifier base, SpecialModel specialModel) implements ItemModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Identifier.CODEC.fieldOf("base").forGetter(SpecialItemModel::base), + SpecialModel.CODEC.fieldOf("model").forGetter(SpecialItemModel::specialModel) + ).apply(instance, SpecialItemModel::new)); + + @Override + public MapCodec codec() { + return CODEC; + } +} \ No newline at end of file diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BooleanProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BooleanProperty.java new file mode 100644 index 00000000..0353da44 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BooleanProperty.java @@ -0,0 +1,28 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; +import net.minecraft.util.dynamic.Codecs; + +import java.util.function.Function; + +public interface BooleanProperty { + Codecs.IdMapper> TYPES = Util.make(new Codecs.IdMapper<>(), m -> { + m.put(Identifier.of("custom_model_data"), CustomModelDataFlagProperty.CODEC); + m.put(Identifier.of("using_item"), UsingItemProperty.CODEC); + m.put(Identifier.of("broken"), BrokenProperty.CODEC); + m.put(Identifier.of("damaged"), DamagedProperty.CODEC); + m.put(Identifier.of("fishing_rod/cast"), FishingRodCastProperty.CODEC); + m.put(Identifier.of("has_component"), HasComponentProperty.CODEC); + m.put(Identifier.of("bundle/has_selected_item"), BundleHasSelectedItemProperty.CODEC); + m.put(Identifier.of("selected"), SelectedProperty.CODEC); + m.put(Identifier.of("carried"), CarriedProperty.CODEC); + m.put(Identifier.of("extended_view"), ExtendedViewProperty.CODEC); + m.put(Identifier.of("keybind_down"), KeybindDownProperty.CODEC); + m.put(Identifier.of("view_entity"), ViewEntityProperty.CODEC); + }); + MapCodec CODEC = TYPES.getCodec(Identifier.CODEC).dispatchMap("property", BooleanProperty::codec, Function.identity()); + + MapCodec codec(); +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BrokenProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BrokenProperty.java new file mode 100644 index 00000000..1e42864d --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BrokenProperty.java @@ -0,0 +1,13 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; + +public record BrokenProperty() implements BooleanProperty { + public static final MapCodec CODEC = MapCodec.unit(new BrokenProperty()); + + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BundleHasSelectedItemProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BundleHasSelectedItemProperty.java new file mode 100644 index 00000000..eafcc2ed --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/BundleHasSelectedItemProperty.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; + +public record BundleHasSelectedItemProperty() implements BooleanProperty { + public static final MapCodec CODEC = MapCodec.unit(new BundleHasSelectedItemProperty()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/CarriedProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/CarriedProperty.java new file mode 100644 index 00000000..1d20db91 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/CarriedProperty.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; + +public record CarriedProperty() implements BooleanProperty { + public static final MapCodec CODEC = MapCodec.unit(new CarriedProperty()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/CustomModelDataFlagProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/CustomModelDataFlagProperty.java new file mode 100644 index 00000000..1fa716e1 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/CustomModelDataFlagProperty.java @@ -0,0 +1,17 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record CustomModelDataFlagProperty(int index) implements BooleanProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).forGetter(CustomModelDataFlagProperty::index) + ).apply(instance, CustomModelDataFlagProperty::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/DamagedProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/DamagedProperty.java new file mode 100644 index 00000000..da43ec1b --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/DamagedProperty.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; + +public record DamagedProperty() implements BooleanProperty { + public static final MapCodec CODEC = MapCodec.unit(new DamagedProperty()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/ExtendedViewProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/ExtendedViewProperty.java new file mode 100644 index 00000000..66ffb81a --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/ExtendedViewProperty.java @@ -0,0 +1,13 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; + +public record ExtendedViewProperty() implements BooleanProperty { + public static final MapCodec CODEC = MapCodec.unit(new ExtendedViewProperty()); + + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/FishingRodCastProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/FishingRodCastProperty.java new file mode 100644 index 00000000..06ba58b4 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/FishingRodCastProperty.java @@ -0,0 +1,13 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; + +public record FishingRodCastProperty() implements BooleanProperty { + public static final MapCodec CODEC = MapCodec.unit(new FishingRodCastProperty()); + + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/HasComponentProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/HasComponentProperty.java new file mode 100644 index 00000000..6aa7b817 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/HasComponentProperty.java @@ -0,0 +1,20 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.component.ComponentType; +import net.minecraft.registry.Registries; + +public record HasComponentProperty(ComponentType componentType, boolean ignoreDefault) implements BooleanProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Registries.DATA_COMPONENT_TYPE.getCodec().fieldOf("component").forGetter(HasComponentProperty::componentType), + Codec.BOOL.optionalFieldOf("ignore_default", Boolean.valueOf(false)).forGetter(HasComponentProperty::ignoreDefault) + ).apply(instance, HasComponentProperty::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/KeybindDownProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/KeybindDownProperty.java new file mode 100644 index 00000000..50c6289c --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/KeybindDownProperty.java @@ -0,0 +1,16 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +public record KeybindDownProperty(String keybind) implements BooleanProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.STRING.fieldOf("keybind").forGetter(KeybindDownProperty::keybind) + ).apply(instance, KeybindDownProperty::new)); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/SelectedProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/SelectedProperty.java new file mode 100644 index 00000000..8feb99fd --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/SelectedProperty.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; + +public record SelectedProperty() implements BooleanProperty { + public static final MapCodec CODEC = MapCodec.unit(new SelectedProperty()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/UsingItemProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/UsingItemProperty.java new file mode 100644 index 00000000..3e0cfa87 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/UsingItemProperty.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; + +public record UsingItemProperty() implements BooleanProperty { + public static final MapCodec CODEC = MapCodec.unit(new UsingItemProperty()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/ViewEntityProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/ViewEntityProperty.java new file mode 100644 index 00000000..cdd945fc --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/bool/ViewEntityProperty.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.bool; + +import com.mojang.serialization.MapCodec; + +public record ViewEntityProperty() implements BooleanProperty { + public static final MapCodec CODEC = MapCodec.unit(new ViewEntityProperty()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/BundleFullnessProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/BundleFullnessProperty.java new file mode 100644 index 00000000..55908f19 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/BundleFullnessProperty.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.MapCodec; + +public record BundleFullnessProperty() implements NumericProperty { + public static final MapCodec CODEC = MapCodec.unit(new BundleFullnessProperty()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CompassProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CompassProperty.java new file mode 100644 index 00000000..507a1476 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CompassProperty.java @@ -0,0 +1,37 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.StringIdentifiable; + +public record CompassProperty(boolean wobble, Target target) implements NumericProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.BOOL.optionalFieldOf("wobble", true).forGetter(CompassProperty::wobble), + Target.CODEC.fieldOf("target").forGetter(CompassProperty::target) + ).apply(instance, CompassProperty::new)); + + @Override + public MapCodec codec() { + return CODEC; + } + + public enum Target implements StringIdentifiable { + NONE("none"), + LODESTONE("lodestone"), + SPAWN("spawn"), + RECOVERY("recovery"); + + public static final Codec CODEC = StringIdentifiable.createCodec(Target::values); + private final String name; + + Target(final String name) { + this.name = name; + } + + @Override + public String asString() { + return this.name; + } + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CooldownProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CooldownProperty.java new file mode 100644 index 00000000..75bfcba5 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CooldownProperty.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.MapCodec; + +public record CooldownProperty() implements NumericProperty { + public static final MapCodec CODEC = MapCodec.unit(new CooldownProperty()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CountProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CountProperty.java new file mode 100644 index 00000000..0af2b45d --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CountProperty.java @@ -0,0 +1,17 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +public record CountProperty(boolean normalize) implements NumericProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.BOOL.optionalFieldOf("normalize", true).forGetter(CountProperty::normalize) + ).apply(instance, CountProperty::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CrossbowPullProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CrossbowPullProperty.java new file mode 100644 index 00000000..f2fa1cad --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CrossbowPullProperty.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.MapCodec; + +public class CrossbowPullProperty implements NumericProperty { + public static final MapCodec CODEC = MapCodec.unit(new CrossbowPullProperty()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CustomModelDataFloatProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CustomModelDataFloatProperty.java new file mode 100644 index 00000000..2d459565 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/CustomModelDataFloatProperty.java @@ -0,0 +1,17 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record CustomModelDataFloatProperty(int index) implements NumericProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).forGetter(CustomModelDataFloatProperty::index) + ).apply(instance, CustomModelDataFloatProperty::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/DamageProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/DamageProperty.java new file mode 100644 index 00000000..a9923aa0 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/DamageProperty.java @@ -0,0 +1,17 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +public record DamageProperty(boolean normalize) implements NumericProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.BOOL.optionalFieldOf("normalize", true).forGetter(DamageProperty::normalize) + ).apply(instance, DamageProperty::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/NumericProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/NumericProperty.java new file mode 100644 index 00000000..98edf296 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/NumericProperty.java @@ -0,0 +1,26 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.MapCodec; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; +import net.minecraft.util.dynamic.Codecs; + +import java.util.function.Function; + +public interface NumericProperty { + Codecs.IdMapper> TYPES = Util.make(new Codecs.IdMapper<>(), m -> { + m.put(Identifier.of("custom_model_data"), CustomModelDataFloatProperty.CODEC); + m.put(Identifier.of("bundle/fullness"), BundleFullnessProperty.CODEC); + m.put(Identifier.of("damage"), DamageProperty.CODEC); + m.put(Identifier.of("cooldown"), CooldownProperty.CODEC); + m.put(Identifier.of("time"), TimeProperty.CODEC); + m.put(Identifier.of("compass"), CompassProperty.CODEC); + m.put(Identifier.of("crossbow/pull"), CrossbowPullProperty.CODEC); + m.put(Identifier.of("use_cycle"), UseCycleProperty.CODEC); + m.put(Identifier.of("use_duration"), UseDurationProperty.CODEC); + m.put(Identifier.of("count"), CountProperty.CODEC); + }); + MapCodec CODEC = TYPES.getCodec(Identifier.CODEC).dispatchMap("property", NumericProperty::codec, Function.identity()); + + MapCodec codec(); +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/TimeProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/TimeProperty.java new file mode 100644 index 00000000..8535719a --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/TimeProperty.java @@ -0,0 +1,39 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.StringIdentifiable; + +public record TimeProperty(boolean wobble, Source source) implements NumericProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec( + instance -> instance.group( + Codec.BOOL.optionalFieldOf("wobble", true).forGetter(TimeProperty::wobble), + Source.CODEC.fieldOf("source").forGetter(TimeProperty::source) + ) + .apply(instance, TimeProperty::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } + + public enum Source implements StringIdentifiable { + RANDOM("random"), + DAYTIME("daytime"), + MOON_PHASE("moon_phase"); + + public static final Codec CODEC = StringIdentifiable.createCodec(Source::values); + private final String name; + + Source(final String name) { + this.name = name; + } + + @Override + public String asString() { + return this.name; + } + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/UseCycleProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/UseCycleProperty.java new file mode 100644 index 00000000..b1848282 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/UseCycleProperty.java @@ -0,0 +1,16 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record UseCycleProperty(float period) implements NumericProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.POSITIVE_FLOAT.optionalFieldOf("period", 1.0F).forGetter(UseCycleProperty::period) + ).apply(instance, UseCycleProperty::new)); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/UseDurationProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/UseDurationProperty.java new file mode 100644 index 00000000..1835de4f --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/numeric/UseDurationProperty.java @@ -0,0 +1,18 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.numeric; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +public record UseDurationProperty(boolean remaining) implements NumericProperty { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.BOOL.optionalFieldOf("remaining", false).forGetter(UseDurationProperty::remaining) + ).apply(instance, UseDurationProperty::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } + +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ChargeTypeProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ChargeTypeProperty.java new file mode 100644 index 00000000..7ca3ea2e --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ChargeTypeProperty.java @@ -0,0 +1,16 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.mojang.serialization.MapCodec; + +import net.minecraft.item.CrossbowItem; + +public record ChargeTypeProperty() implements SelectProperty { + public static final Type TYPE = new Type<>( + MapCodec.unit(new ChargeTypeProperty()), CrossbowItem.ChargeType.CODEC + ); + + @Override + public Type type() { + return TYPE; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ContextDimensionProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ContextDimensionProperty.java new file mode 100644 index 00000000..823f37fc --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ContextDimensionProperty.java @@ -0,0 +1,17 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.mojang.serialization.MapCodec; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.world.World; + +public record ContextDimensionProperty() implements SelectProperty> { + public static final Type> TYPE = new Type<>( + MapCodec.unit(new ContextDimensionProperty()), RegistryKey.createCodec(RegistryKeys.WORLD) + ); + + @Override + public Type> type() { + return TYPE; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ContextEntityTypeProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ContextEntityTypeProperty.java new file mode 100644 index 00000000..57d49f6e --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ContextEntityTypeProperty.java @@ -0,0 +1,17 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.mojang.serialization.MapCodec; +import net.minecraft.entity.EntityType; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; + +public record ContextEntityTypeProperty() implements SelectProperty>> { + public static final Type>> TYPE = new Type<>( + MapCodec.unit(new ContextEntityTypeProperty()), RegistryKey.createCodec(RegistryKeys.ENTITY_TYPE) + ); + + @Override + public Type>> type() { + return TYPE; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/CustomModelDataStringProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/CustomModelDataStringProperty.java new file mode 100644 index 00000000..b050ea33 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/CustomModelDataStringProperty.java @@ -0,0 +1,19 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record CustomModelDataStringProperty(int index) implements SelectProperty { + public static final Type TYPE = new Type<>( + RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).forGetter(CustomModelDataStringProperty::index) + ).apply(instance, CustomModelDataStringProperty::new)), + Codec.STRING + ); + + @Override + public Type type() { + return TYPE; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/DisplayContextProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/DisplayContextProperty.java new file mode 100644 index 00000000..119e0f64 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/DisplayContextProperty.java @@ -0,0 +1,15 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.mojang.serialization.MapCodec; +import net.minecraft.item.ModelTransformationMode; + +public record DisplayContextProperty() implements SelectProperty { + public static final Type TYPE = new Type<>( + MapCodec.unit(new DisplayContextProperty()), ModelTransformationMode.CODEC + ); + + @Override + public Type type() { + return TYPE; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ItemBlockStateProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ItemBlockStateProperty.java new file mode 100644 index 00000000..2ec1baa5 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/ItemBlockStateProperty.java @@ -0,0 +1,20 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +public record ItemBlockStateProperty(String property) implements SelectProperty { + public static final Type TYPE = new Type<>( + RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.STRING.fieldOf("block_state_property").forGetter(ItemBlockStateProperty::property) + ) + .apply(instance, ItemBlockStateProperty::new) + ), + Codec.STRING + ); + + @Override + public Type type() { + return TYPE; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/LocalTimeProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/LocalTimeProperty.java new file mode 100644 index 00000000..b39952bc --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/LocalTimeProperty.java @@ -0,0 +1,22 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import java.util.Optional; + +public record LocalTimeProperty(String pattern, String locale, + Optional timeZone) implements SelectProperty { + public static final Type TYPE = new Type<>( + RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.STRING.fieldOf("pattern").forGetter(LocalTimeProperty::pattern), + Codec.STRING.optionalFieldOf("locale", "").forGetter(LocalTimeProperty::locale), + Codec.STRING.optionalFieldOf("time_zone").forGetter(LocalTimeProperty::timeZone) + ).apply(instance, LocalTimeProperty::new)), Codec.STRING + ); + + @Override + public Type type() { + return TYPE; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/MainHandProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/MainHandProperty.java new file mode 100644 index 00000000..145e16b9 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/MainHandProperty.java @@ -0,0 +1,13 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.mojang.serialization.MapCodec; +import net.minecraft.util.Arm; + +public record MainHandProperty() implements SelectProperty { + public static final Type TYPE = new Type<>(MapCodec.unit(new MainHandProperty()), Arm.CODEC); + + @Override + public Type type() { + return TYPE; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/SelectProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/SelectProperty.java new file mode 100644 index 00000000..57274d02 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/SelectProperty.java @@ -0,0 +1,70 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multiset; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import eu.pb4.polymer.resourcepack.extras.api.format.item.model.SelectItemModel; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; +import net.minecraft.util.dynamic.Codecs; + +import java.util.stream.Collectors; + +public interface SelectProperty { + Codecs.IdMapper> TYPES = Util.make(new Codecs.IdMapper<>(), m -> { + m.put(Identifier.ofVanilla("custom_model_data"), CustomModelDataStringProperty.TYPE); + m.put(Identifier.ofVanilla("main_hand"), MainHandProperty.TYPE); + m.put(Identifier.ofVanilla("charge_type"), ChargeTypeProperty.TYPE); + m.put(Identifier.ofVanilla("trim_material"), TrimMaterialProperty.TYPE); + m.put(Identifier.ofVanilla("block_state"), ItemBlockStateProperty.TYPE); + m.put(Identifier.ofVanilla("display_context"), DisplayContextProperty.TYPE); + m.put(Identifier.ofVanilla("local_time"), LocalTimeProperty.TYPE); + m.put(Identifier.ofVanilla("context_entity_type"), ContextEntityTypeProperty.TYPE); + m.put(Identifier.ofVanilla("context_dimension"), ContextDimensionProperty.TYPE); + }); + Codec> CODEC = TYPES.getCodec(Identifier.CODEC); + + Type, T> type(); + + record Type, Y>(MapCodec mainCodec, Codec valueCodec, + MapCodec> switchCodec) { + public Type(MapCodec mainCodec, Codec valueCodec) { + this(mainCodec, valueCodec, codec(mainCodec, valueCodec)); + } + + private static > MapCodec> codec(MapCodec mainCodec, Codec valueCodec) { + var codec = SelectItemModel.Case.createCodec(valueCodec) + .listOf() + .validate(cases -> { + if (cases.isEmpty()) { + return DataResult.error(() -> "Empty case list"); + } else { + Multiset multiset = HashMultiset.create(); + + for (var switchCase : cases) { + multiset.addAll(switchCase.values()); + } + + return multiset.size() != multiset.entrySet().size() + ? DataResult.error( + () -> "Duplicate case conditions: " + + multiset.entrySet() + .stream() + .filter(entry -> entry.getCount() > 1) + .map(entry -> entry.getElement().toString()) + .collect(Collectors.joining(", ")) + ) : DataResult.success(cases); + } + } + ); + return RecordCodecBuilder.mapCodec(instance -> instance.group( + mainCodec.forGetter(SelectItemModel.Switch::property), codec.fieldOf("cases").forGetter(SelectItemModel.Switch::cases) + ).apply(instance, SelectItemModel.Switch::new) + ); + } + } + +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/TrimMaterialProperty.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/TrimMaterialProperty.java new file mode 100644 index 00000000..db95b578 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/property/select/TrimMaterialProperty.java @@ -0,0 +1,17 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.property.select; + +import com.mojang.serialization.MapCodec; +import net.minecraft.item.equipment.trim.ArmorTrimMaterial; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; + +public record TrimMaterialProperty() implements SelectProperty> { + public static final Type> TYPE = new Type<>( + MapCodec.unit(new TrimMaterialProperty()), RegistryKey.createCodec(RegistryKeys.TRIM_MATERIAL) + ); + + @Override + public Type> type() { + return TYPE; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/BannerSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/BannerSpecialModel.java new file mode 100644 index 00000000..d62b7dda --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/BannerSpecialModel.java @@ -0,0 +1,19 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.DyeColor; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; + +public record BannerSpecialModel(DyeColor color) implements SpecialModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + DyeColor.CODEC.fieldOf("color").forGetter(BannerSpecialModel::color) + ).apply(instance, BannerSpecialModel::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/BedSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/BedSpecialModel.java new file mode 100644 index 00000000..7de8276d --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/BedSpecialModel.java @@ -0,0 +1,18 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; + +public record BedSpecialModel(Identifier texture) implements SpecialModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Identifier.CODEC.fieldOf("texture").forGetter(BedSpecialModel::texture) + ).apply(instance, BedSpecialModel::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ChestSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ChestSpecialModel.java new file mode 100644 index 00000000..6bc7f0d2 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ChestSpecialModel.java @@ -0,0 +1,20 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; + +public record ChestSpecialModel(Identifier texture, float openness) implements SpecialModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Identifier.CODEC.fieldOf("texture").forGetter(ChestSpecialModel::texture), + Codec.FLOAT.optionalFieldOf("openness", 0f).forGetter(ChestSpecialModel::openness) + ).apply(instance, ChestSpecialModel::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ConduitSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ConduitSpecialModel.java new file mode 100644 index 00000000..30193e4e --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ConduitSpecialModel.java @@ -0,0 +1,15 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.DyeColor; +import org.jetbrains.annotations.Nullable; + +public record ConduitSpecialModel() implements SpecialModel { + public static final MapCodec CODEC = MapCodec.unit(new ConduitSpecialModel()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/DecoratedPotSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/DecoratedPotSpecialModel.java new file mode 100644 index 00000000..c4ba87fb --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/DecoratedPotSpecialModel.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.MapCodec; + +public record DecoratedPotSpecialModel() implements SpecialModel { + public static final MapCodec CODEC = MapCodec.unit(new DecoratedPotSpecialModel()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/HangingSignSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/HangingSignSpecialModel.java new file mode 100644 index 00000000..4c71e805 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/HangingSignSpecialModel.java @@ -0,0 +1,21 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.block.WoodType; +import net.minecraft.util.Identifier; + +import java.util.Optional; + +public record HangingSignSpecialModel(WoodType woodType, Optional texture) implements SpecialModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + WoodType.CODEC.fieldOf("wood_type").forGetter(HangingSignSpecialModel::woodType), + Identifier.CODEC.optionalFieldOf("texture").forGetter(HangingSignSpecialModel::texture) + ).apply(instance, HangingSignSpecialModel::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/HeadSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/HeadSpecialModel.java new file mode 100644 index 00000000..0f07e8c7 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/HeadSpecialModel.java @@ -0,0 +1,24 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.block.SkullBlock; +import net.minecraft.util.Identifier; + +import java.util.Optional; + +public record HeadSpecialModel(SkullBlock.SkullType kind, Optional textureOverride, + float animation) implements SpecialModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + SkullBlock.SkullType.CODEC.fieldOf("kind").forGetter(HeadSpecialModel::kind), + Identifier.CODEC.optionalFieldOf("texture").forGetter(HeadSpecialModel::textureOverride), + Codec.FLOAT.optionalFieldOf("animation", 0f).forGetter(HeadSpecialModel::animation) + ).apply(instance, HeadSpecialModel::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ShieldSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ShieldSpecialModel.java new file mode 100644 index 00000000..eaa3e0a2 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ShieldSpecialModel.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.MapCodec; + +public record ShieldSpecialModel() implements SpecialModel { + public static final MapCodec CODEC = MapCodec.unit(new ShieldSpecialModel()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ShulkerBoxSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ShulkerBoxSpecialModel.java new file mode 100644 index 00000000..b8dc8055 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/ShulkerBoxSpecialModel.java @@ -0,0 +1,22 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.Direction; + +public record ShulkerBoxSpecialModel(Identifier texture, float openness, Direction facing) implements SpecialModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Identifier.CODEC.fieldOf("texture").forGetter(ShulkerBoxSpecialModel::texture), + Codec.FLOAT.optionalFieldOf("openness", 0f).forGetter(ShulkerBoxSpecialModel::openness), + Direction.CODEC.optionalFieldOf("orientation", Direction.UP).forGetter(ShulkerBoxSpecialModel::facing) + + ).apply(instance, ShulkerBoxSpecialModel::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/SignSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/SignSpecialModel.java new file mode 100644 index 00000000..a5de7986 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/SignSpecialModel.java @@ -0,0 +1,21 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.block.WoodType; +import net.minecraft.util.Identifier; + +import java.util.Optional; + +public record SignSpecialModel(WoodType woodType, Optional texture) implements SpecialModel { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + WoodType.CODEC.fieldOf("wood_type").forGetter(SignSpecialModel::woodType), + Identifier.CODEC.optionalFieldOf("texture").forGetter(SignSpecialModel::texture) + ).apply(instance, SignSpecialModel::new) + ); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/SpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/SpecialModel.java new file mode 100644 index 00000000..e00eaa9a --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/SpecialModel.java @@ -0,0 +1,29 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import net.minecraft.client.render.item.model.special.*; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; +import net.minecraft.util.dynamic.Codecs; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Function; + +public interface SpecialModel { + Codecs.IdMapper> TYPES = Util.make(new Codecs.IdMapper<>(), m -> { + m.put(Identifier.ofVanilla("bed"), BedSpecialModel.CODEC); + m.put(Identifier.ofVanilla("banner"), BannerSpecialModel.CODEC); + m.put(Identifier.ofVanilla("conduit"), ConduitSpecialModel.CODEC); + m.put(Identifier.ofVanilla("chest"), ChestSpecialModel.CODEC); + m.put(Identifier.ofVanilla("head"), HeadSpecialModel.CODEC); + m.put(Identifier.ofVanilla("shulker_box"), ShulkerBoxSpecialModel.CODEC); + m.put(Identifier.ofVanilla("shield"), ShieldSpecialModel.CODEC); + m.put(Identifier.ofVanilla("trident"), TridentSpecialModel.CODEC); + m.put(Identifier.ofVanilla("decorated_pot"), DecoratedPotSpecialModel.CODEC); + m.put(Identifier.ofVanilla("standing_sign"), SignSpecialModel.CODEC); + m.put(Identifier.ofVanilla("hanging_sign"), HangingSignSpecialModel.CODEC); + }); + Codec CODEC = TYPES.getCodec(Identifier.CODEC).dispatch(SpecialModel::codec, Function.identity()); + MapCodec codec(); +} \ No newline at end of file diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/TridentSpecialModel.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/TridentSpecialModel.java new file mode 100644 index 00000000..689678a7 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/special/TridentSpecialModel.java @@ -0,0 +1,12 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.special; + +import com.mojang.serialization.MapCodec; + +public record TridentSpecialModel() implements SpecialModel { + public static final MapCodec CODEC = MapCodec.unit(new TridentSpecialModel()); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/ConstantTintSource.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/ConstantTintSource.java new file mode 100644 index 00000000..8ca7c8c9 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/ConstantTintSource.java @@ -0,0 +1,16 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.tint; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record ConstantTintSource(int value) implements ItemTintSource { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.RGB.fieldOf("value").forGetter(ConstantTintSource::value) + ).apply(instance, ConstantTintSource::new)); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/CustomModelDataTintSource.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/CustomModelDataTintSource.java new file mode 100644 index 00000000..07aa7920 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/CustomModelDataTintSource.java @@ -0,0 +1,17 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.tint; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record CustomModelDataTintSource(int index, int defaultColor) implements ItemTintSource { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.NON_NEGATIVE_INT.optionalFieldOf("index", 0).forGetter(CustomModelDataTintSource::index), + Codecs.RGB.fieldOf("default").forGetter(CustomModelDataTintSource::defaultColor) + ).apply(instance, CustomModelDataTintSource::new)); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/DyeTintSource.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/DyeTintSource.java new file mode 100644 index 00000000..932fba9d --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/DyeTintSource.java @@ -0,0 +1,16 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.tint; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record DyeTintSource(int defaultColor) implements ItemTintSource { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.RGB.fieldOf("default").forGetter(DyeTintSource::defaultColor) + ).apply(instance, DyeTintSource::new)); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/FireworkTintSource.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/FireworkTintSource.java new file mode 100644 index 00000000..f8ef1eee --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/FireworkTintSource.java @@ -0,0 +1,20 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.tint; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record FireworkTintSource(int defaultColor) implements ItemTintSource { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.RGB.fieldOf("default").forGetter(FireworkTintSource::defaultColor) + ).apply(instance, FireworkTintSource::new)); + + public FireworkTintSource() { + this(-7697782); + } + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/GrassTintSource.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/GrassTintSource.java new file mode 100644 index 00000000..7b417032 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/GrassTintSource.java @@ -0,0 +1,21 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.tint; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record GrassTintSource(float temperature, float downfall) implements ItemTintSource { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.rangedInclusiveFloat(0.0F, 1.0F).fieldOf("temperature").forGetter(GrassTintSource::temperature), + Codecs.rangedInclusiveFloat(0.0F, 1.0F).fieldOf("downfall").forGetter(GrassTintSource::downfall) + ).apply(instance, GrassTintSource::new)); + + public GrassTintSource() { + this(0.5F, 1.0F); + } + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/ItemTintSource.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/ItemTintSource.java new file mode 100644 index 00000000..2edfc701 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/ItemTintSource.java @@ -0,0 +1,26 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.tint; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; +import net.minecraft.util.dynamic.Codecs; + +import java.util.function.Function; + +public interface ItemTintSource { + Codecs.IdMapper> TYPES = Util.make(new Codecs.IdMapper<>(), m -> { + m.put(Identifier.ofVanilla("custom_model_data"), CustomModelDataTintSource.CODEC); + m.put(Identifier.ofVanilla("constant"), ConstantTintSource.CODEC); + m.put(Identifier.ofVanilla("dye"), DyeTintSource.CODEC); + m.put(Identifier.ofVanilla("grass"), GrassTintSource.CODEC); + m.put(Identifier.ofVanilla("firework"), FireworkTintSource.CODEC); + m.put(Identifier.ofVanilla("potion"), PotionTintSource.CODEC); + m.put(Identifier.ofVanilla("map_color"), MapColorTintSource.CODEC); + m.put(Identifier.ofVanilla("team"), TeamTintSource.CODEC); + }); + Codec CODEC = TYPES.getCodec(Identifier.CODEC).dispatch(ItemTintSource::codec, Function.identity()); + + + MapCodec codec(); +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/MapColorTintSource.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/MapColorTintSource.java new file mode 100644 index 00000000..7c17b4db --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/MapColorTintSource.java @@ -0,0 +1,21 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.tint; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.component.type.MapColorComponent; +import net.minecraft.util.dynamic.Codecs; + +public record MapColorTintSource(int defaultColor) implements ItemTintSource { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.RGB.fieldOf("default").forGetter(MapColorTintSource::defaultColor) + ).apply(instance, MapColorTintSource::new)); + + public MapColorTintSource() { + this(MapColorComponent.DEFAULT.rgb()); + } + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/PotionTintSource.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/PotionTintSource.java new file mode 100644 index 00000000..1698d696 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/PotionTintSource.java @@ -0,0 +1,20 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.tint; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record PotionTintSource(int defaultColor) implements ItemTintSource { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.RGB.fieldOf("default").forGetter(PotionTintSource::defaultColor) + ).apply(instance, PotionTintSource::new)); + + public PotionTintSource() { + this(-13083194); + } + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/TeamTintSource.java b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/TeamTintSource.java new file mode 100644 index 00000000..83735eff --- /dev/null +++ b/polymer-resource-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/format/item/tint/TeamTintSource.java @@ -0,0 +1,16 @@ +package eu.pb4.polymer.resourcepack.extras.api.format.item.tint; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.dynamic.Codecs; + +public record TeamTintSource(int defaultColor) implements ItemTintSource { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.RGB.fieldOf("default").forGetter(TeamTintSource::defaultColor) + ).apply(instance, TeamTintSource::new)); + + @Override + public MapCodec codec() { + return CODEC; + } +} diff --git a/polymer-resource-pack-extras/src/main/resources/assets/icon.png b/polymer-resource-pack-extras/src/main/resources/assets/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..dce8bdbdd03fc4ee75e2989e99d1fa66c1c0053f GIT binary patch literal 583 zcmV-N0=WH&P)EX>4Tx04R}tkv&MmKpe$iTcx5E2P4=GxZDATpEOYyZOKQ|TPOhUXY@@uVDJ{`U2}SC?c?+T$WT|yH^9Lm zFj1uJb(eSdboTb|nO1*4*llvpU7Bxe0000UP)t-sNj4Q&SXd8ol!<32|9yi{(*FOi zvQYkL*x1i7 literal 0 HcmV?d00001 diff --git a/polymer-resource-pack-extras/src/main/resources/fabric.mod.json b/polymer-resource-pack-extras/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..ae1bc4a0 --- /dev/null +++ b/polymer-resource-pack-extras/src/main/resources/fabric.mod.json @@ -0,0 +1,41 @@ +{ + "schemaVersion": 1, + "id": "polymer-resource-pack-extras", + "version": "${version}", + "name": "Polymer (Resource Pack Extras)", + "description": "Extra functionality and format support for Polymer's server resource pack generation API", + "authors": [ + "Patbox" + ], + "contributors": [ + "aws404" + ], + "contact": { + "homepage": "https://pb4.eu", + "sources": "https://github.com/Patbox/polymer", + "issues": "https://github.com/Patbox/polymer/issues" + }, + + "license": "LGPLv3", + "icon": "assets/icon.png", + "environment": "*", + "entrypoints": { + + }, + "mixins": [ + ], + + "depends": { + "polymer-common": ">=${version}", + "polymer-resource-pack": ">=${version}", + "fabricloader": ">=0.15.0" + }, + "custom": { + "modmenu": { + "badges": [ "library" ], + "links": { "modmenu.discord": "https://pb4.eu/discord" }, + "parent": "polymer-bundled", + "update_checker": false + } + } +} diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/AssetPaths.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/AssetPaths.java index 7e5a9ba4..d3b50224 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/AssetPaths.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/AssetPaths.java @@ -48,15 +48,15 @@ public static String itemTextureMetadata(Identifier id) { return texture(id.getNamespace(), "item/" + id.getPath() + ".png.mcmeta"); } - public static String armorTexture(Identifier id, int layer) { - return texture(id.getNamespace(), "models/armor/" + id.getPath() + "_layer_" + layer + ".png"); + public static String itemAsset(Identifier identifier) { + return "assets/" + identifier.getNamespace() + "/items/" + identifier.getPath() + ".json"; } - public static String armorOverlayTexture(Identifier id, int layer) { - return texture(id.getNamespace(), "models/armor/" + id.getPath() + "_layer_" + layer + "_overlay.png"); - } + //public static String armorTexture(Identifier id, int layer) { + // return texture(id.getNamespace(), "models/armor/" + id.getPath() + "_layer_" + layer + ".png"); + //} - public static String armorTexturePolymerMetadata(Identifier id, int layer) { - return texture(id.getNamespace(), "models/armor/" + id.getPath() + "_layer_" + layer + ".polymer.json"); - } + //public static String armorOverlayTexture(Identifier id, int layer) { + // return texture(id.getNamespace(), "models/armor/" + id.getPath() + "_layer_" + layer + "_overlay.png"); + //} } diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java index ab981cf3..b225d81f 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java @@ -8,7 +8,6 @@ import eu.pb4.polymer.resourcepack.impl.generation.DefaultRPBuilder; import eu.pb4.polymer.resourcepack.api.metadata.PackMcMeta; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.item.Item; import net.minecraft.server.network.ServerCommonNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; @@ -18,7 +17,6 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; -import java.util.List; import java.util.UUID; import java.util.function.Consumer; @@ -29,7 +27,7 @@ public final class PolymerResourcePackUtils { private PolymerResourcePackUtils() { } - private static final ResourcePackCreator INSTANCE = new ResourcePackCreator(PolymerResourcePackImpl.USE_OFFSET ? PolymerResourcePackImpl.OFFSET_VALUES : 1); + private static final ResourcePackCreator INSTANCE = new ResourcePackCreator(); public static final SimpleEvent> RESOURCE_PACK_CREATION_EVENT = INSTANCE.creationEvent; public static final SimpleEvent> RESOURCE_PACK_AFTER_INITIAL_CREATION_EVENT = INSTANCE.afterInitialCreationEvent; @@ -76,27 +74,6 @@ public static boolean isRequired() { return REQUIRED; } - - public static boolean addBridgedModelsFolder(Identifier modelFolderId) { - return INSTANCE.addBridgedModelsFolder(modelFolderId); - } - - public static boolean addBridgedModelsFolder(Identifier... modelFolderId) { - return INSTANCE.addBridgedModelsFolder(modelFolderId); - } - - public static Identifier getBridgedModelId(Identifier model) { - if (model.getPath().startsWith("item/")) { - return model.withPath(model.getPath().substring("item/".length())); - } - - return model.withPrefixedPath("-/"); - } - - public static Identifier bridgeModel(Identifier model) { - return getBridgedModelId(model); - } - /** * Allows to check if player has selected server side resoucepack installed * However it's impossible to check if it's polymer one or not diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackBuilder.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackBuilder.java index 78e935ee..cf052c51 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackBuilder.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackBuilder.java @@ -91,7 +91,7 @@ default boolean copyResourcePackFromPath(Path root, String field) { boolean addAssetsSource(String modId); - void addWriteConverter(BiFunction converter); + void addWriteConverter(BiFunction converter); void addPreFinishTask(Consumer consumer); diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackCreator.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackCreator.java index 50f15578..168a7f8a 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackCreator.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/ResourcePackCreator.java @@ -2,9 +2,7 @@ import eu.pb4.polymer.common.api.events.SimpleEvent; import eu.pb4.polymer.common.impl.CommonImpl; -import eu.pb4.polymer.resourcepack.api.model.ItemOverride; import eu.pb4.polymer.resourcepack.impl.generation.DefaultRPBuilder; -import it.unimi.dsi.fastutil.objects.*; import net.minecraft.SharedConstants; import net.minecraft.resource.ResourceType; import net.minecraft.resource.metadata.PackResourceMetadata; @@ -25,92 +23,39 @@ public final class ResourcePackCreator { public final SimpleEvent> creationEvent = new SimpleEvent<>(); public final SimpleEvent finishedEvent = new SimpleEvent<>(); public final SimpleEvent> afterInitialCreationEvent = new SimpleEvent<>(); - private final Object2IntMap currentCustomModelDataValue = new Object2IntOpenHashMap<>(); - private final Map> modelOverrides = new HashMap<>(); private final Set modIds = new HashSet<>(); private final Set modIdsNoCopy = new HashSet<>(); - private final Set bridgedModels = new HashSet<>(); + private final Set sourcePaths = new HashSet<>(); private Text packDescription = null; private byte[] packIcon = null; - private final Set sourcePaths = new HashSet<>(); + + ResourcePackCreator() { + } + + public static ResourcePackCreator forDefault() { + return PolymerResourcePackUtils.getInstance(); + } public static ResourcePackCreator create() { - return new ResourcePackCreator(0); + return new ResourcePackCreator(); } + public static ResourcePackCreator createCopy(ResourcePackCreator source, boolean copyEvents) { - var creator = new ResourcePackCreator(source.currentCustomModelDataValue.defaultReturnValue()); + var creator = new ResourcePackCreator(); if (copyEvents) { source.creationEvent.invokers().forEach(creator.creationEvent::register); source.afterInitialCreationEvent.invokers().forEach(creator.afterInitialCreationEvent::register); source.finishedEvent.invokers().forEach(creator.finishedEvent::register); } - - creator.currentCustomModelDataValue.putAll(source.currentCustomModelDataValue); - source.modelOverrides.forEach((a, b) -> creator.modelOverrides.put(a, new ArrayList<>(b))); creator.modIds.addAll(source.modIds); creator.modIdsNoCopy.addAll(source.modIdsNoCopy); creator.packDescription = source.packDescription; creator.packIcon = source.packIcon; creator.sourcePaths.addAll(source.sourcePaths); - return creator; } - ResourcePackCreator(int cmdOffset) { - this.currentCustomModelDataValue.defaultReturnValue(cmdOffset); - } - - /** - * This method can be used to register custom model data for models - * - * @param model Target model. Requires full path. - * @param override Override that needs to be added - * @return Custom model data id. - */ - public int defineCustomModelData(Identifier model, Identifier override) { - var id = requestCustomModelDataValue(model); - defineOverride(model, ItemOverride.of(override, ItemOverride.CUSTOM_MODEL_DATA, id)); - return id; - } - - /** - * This method can be used to define custom overrides items - * - * @param model Target model. Requires full path. - * @param override Override that needs to be added - */ - public void defineOverride(Identifier model, ItemOverride override) { - this.modelOverrides.computeIfAbsent(model, (x) -> new ArrayList<>()).add(override); - } - - public int requestCustomModelDataValue(Identifier model) { - var val = this.currentCustomModelDataValue.getInt(model); - this.currentCustomModelDataValue.put(model, val + 1); - return val; - } - - /** - * Adds a bridge, allowing you to access any model from selected folder as `namespace:-/modelpath`. - * - * @param modelFolderId Model folder to bridge. For example "mod:block" will bridge all models from "assets/mod/models/block" - * @return Success of addition. - */ - public boolean addBridgedModelsFolder(Identifier modelFolderId) { - if (modelFolderId.getPath().equals("item") || modelFolderId.getPath().startsWith("item/")) { - return false; - } - return this.bridgedModels.add(modelFolderId.getPath().endsWith("/") ? modelFolderId.withPath(x -> x.substring(0, x.length() - 1)) : modelFolderId); - } - - public boolean addBridgedModelsFolder(Identifier... modelFolderId) { - var b = true; - for (var model : modelFolderId) { - b &= addBridgedModelsFolder(model); - } - return b; - } - /** * Adds mod with provided mod id as a source of assets * @@ -143,6 +88,11 @@ public boolean addAssetSource(Path sourcePath) { return this.sourcePaths.add(sourcePath); } + @Nullable + public Text getPackDescription() { + return this.packDescription; + } + /** * Sets pack description * @@ -162,8 +112,8 @@ public void setPackDescription(Text description) { } @Nullable - public Text getPackDescription() { - return this.packDescription; + public byte[] getPackIcon() { + return packIcon; } /** @@ -175,17 +125,13 @@ public void setPackIcon(byte[] packIcon) { this.packIcon = packIcon; } - @Nullable - public byte[] getPackIcon() { - return packIcon; - } - public boolean isEmpty() { - return this.currentCustomModelDataValue.isEmpty() && this.modIds.isEmpty() && this.creationEvent.isEmpty(); + return this.modIds.isEmpty() && this.creationEvent.isEmpty(); } public boolean build(Path output) throws ExecutionException, InterruptedException { - return build(output, (s) -> {}); + return build(output, (s) -> { + }); } public boolean build(Path output, Consumer status) throws ExecutionException, InterruptedException { @@ -227,42 +173,10 @@ public boolean build(Path output, Consumer status) throws ExecutionExcep status.accept("action:copy_mod_end/" + modId); } - status.accept("action:copy_overrides_start"); - for (var entry : this.modelOverrides.entrySet()) { - var ext = builder.getCustomModels(entry.getKey(), DefaultRPBuilder.OverridePlace.EXISTING); - var cmd = builder.getCustomModels(entry.getKey(), DefaultRPBuilder.OverridePlace.WITH_CUSTOM_MODEL_DATA); - entry.getValue().forEach(a -> (a.containsPredicate(ItemOverride.CUSTOM_MODEL_DATA) ? cmd : ext).add(a.toJson())); - } - status.accept("action:copy_overrides_finish"); - status.accept("action:late_creation_event_start"); this.afterInitialCreationEvent.invoke((x) -> x.accept(builder)); status.accept("action:late_creation_event_finish"); - if (!this.bridgedModels.isEmpty()) { - builder.addPreFinishTask((b) -> { - b.forEachFile((path, out) -> { - if (!path.startsWith("assets/")) { - return; - } - path = path.substring("assets/".length()); - - for (var x : this.bridgedModels) { - var y = x.getNamespace() + "/models/" + x.getPath() + "/"; - if (path.startsWith(y)) { - if (!path.endsWith(".json")) { - return; - } - path = path.substring(x.getNamespace().length() + "/models/".length(), path.length() - ".json".length()); - b.addData("assets/" + x.getNamespace() + "/models/item/-/" + path + ".json", - ("{\"parent\":\"" + x.getNamespace() + ":" + path + "\"}").getBytes(StandardCharsets.UTF_8)); - return; - } - } - }); - }); - } - status.accept("action:build"); successful = builder.buildResourcePack().get() && successful; diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/model/ItemOverride.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/model/ItemOverride.java deleted file mode 100644 index 3d6a4c77..00000000 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/model/ItemOverride.java +++ /dev/null @@ -1,98 +0,0 @@ -package eu.pb4.polymer.resourcepack.api.model; - -import com.google.gson.JsonObject; -import eu.pb4.polymer.common.impl.CommonImplUtils; -import it.unimi.dsi.fastutil.objects.Object2FloatMap; -import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap; -import net.minecraft.util.Identifier; - -import java.util.ArrayList; -import java.util.Comparator; - -public record ItemOverride(Object2FloatMap predicate, Identifier model) { - /** - * All Items - */ - public static Identifier CUSTOM_MODEL_DATA = Identifier.of("custom_model_data"); - public static Identifier LEFT_HANDED = Identifier.of("lefthanded"); - public static Identifier COOLDOWN = Identifier.of("cooldown"); - public static Identifier DAMAGED = Identifier.of("damaged"); - public static Identifier DAMAGE = Identifier.of("damage"); - - /** - * Bows and crossbows - */ - public static Identifier PULL = Identifier.of("pull"); - public static Identifier PULLING = Identifier.of("pulling"); - /** - * Crossbows - */ - public static Identifier CHARGED = Identifier.of("charged"); - public static Identifier FIREWORK = Identifier.of("firework"); - /** - * Bundle - */ - public static Identifier FILLED = Identifier.of("filled"); - /** - * Clock - */ - public static Identifier TIME = Identifier.of("time"); - /** - * Compass - */ - public static Identifier ANGLE = Identifier.of("angle"); - /** - * Elytra - */ - public static Identifier BROKEN = Identifier.of("broken"); - /** - * Fishing rod - */ - public static Identifier CAST = Identifier.of("cast"); - /** - * Shield - */ - public static Identifier BLOCKING = Identifier.of("blocking"); - /** - * Trident - */ - public static Identifier THROWING = Identifier.of("throwing"); - /** - * Light - */ - public static Identifier LEVEL = Identifier.of("level"); - /** - * Goat Horn - */ - public static Identifier TOOTING = Identifier.of("tooting"); - - public static ItemOverride of(Identifier model) { - return new ItemOverride(new Object2FloatOpenHashMap<>(), model); - } - - public static ItemOverride of(Identifier model, Identifier key, float value) { - return of(model).set(key, value); - } - - public ItemOverride set(Identifier key, float value) { - this.predicate.put(key, value); - return this; - } - - public JsonObject toJson() { - var object = new JsonObject(); - object.addProperty("model", CommonImplUtils.shortId(this.model)); - var pred = new JsonObject(); - var entries = new ArrayList<>(predicate.keySet()); - entries.sort(Comparator.comparing(x -> x)); - for (var key : entries) { - pred.addProperty(CommonImplUtils.shortId(key), predicate.getFloat(key)); - } - object.add("predicate", pred); - return object; - } - - public boolean containsPredicate(Identifier key) { - return this.predicate.containsKey(key); - } -} diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackImpl.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackImpl.java index dfafcdab..478d9570 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackImpl.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackImpl.java @@ -12,8 +12,6 @@ public class PolymerResourcePackImpl { public static final boolean FORCE_REQUIRE; - public static final boolean USE_OFFSET; - public static final int OFFSET_VALUES; public static final List INCLUDE_MOD_IDS; public static final List INCLUDE_ZIPS; public static final UUID MAIN_UUID; @@ -32,10 +30,6 @@ public class PolymerResourcePackImpl { FORCE_REQUIRE = config.markResourcePackAsRequiredByDefault || CompatStatus.POLYMC; - USE_OFFSET = config.forcePackOffset || CompatStatus.POLYMC; - - OFFSET_VALUES = config.offsetValue; - INCLUDE_MOD_IDS = config.includeModAssets; INCLUDE_ZIPS = config.includeZips; @@ -47,19 +41,8 @@ public static class Config { public String _c0 = "UUID of default/main resource pack."; @SerializedName("main_uuid") public UUID mainUuid = UUID.randomUUID(); - public String _c1 = "Marks resource pack as required, only effects clients and mods using api to check it"; public boolean markResourcePackAsRequiredByDefault = false; - - public String _c2 = "Force-enables offset of CustomModelData"; - public boolean forcePackOffset = false; - - public String _c3 = "Value of CustomModelData offset when enabled"; - public int offsetValue = 100000; - public String _c4 = "Enables usage of alternative armor rendering for increased mod compatibility. (Always on with Iris or Canvas present)"; - @SerializedName("use_alternative_armor_rendering") - public boolean useAlternativeArmorHandler; - public String _c5 = "Included resource packs from mods!"; @SerializedName("include_mod_assets") public List includeModAssets = new ArrayList<>(); diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/DefaultRPBuilder.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/DefaultRPBuilder.java index 46617d7a..1b2ac0fd 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/DefaultRPBuilder.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/DefaultRPBuilder.java @@ -4,15 +4,12 @@ import eu.pb4.polymer.common.api.PolymerCommonUtils; import eu.pb4.polymer.common.api.events.SimpleEvent; import eu.pb4.polymer.common.impl.CommonImpl; -import eu.pb4.polymer.common.impl.CommonImplUtils; import eu.pb4.polymer.resourcepack.api.AssetPaths; import eu.pb4.polymer.resourcepack.api.ResourcePackBuilder; import eu.pb4.polymer.resourcepack.api.metadata.PackMcMeta; import eu.pb4.polymer.resourcepack.mixin.accessors.ResourceFilterAccessor; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; -import net.minecraft.item.Item; -import net.minecraft.registry.Registries; import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -44,7 +41,6 @@ public class DefaultRPBuilder implements InternalRPBuilder { }); public final SimpleEvent>> buildEvent = new SimpleEvent<>(); - private final Map customModels = new HashMap<>(); private final TreeMap fileMap = new TreeMap<>(); private final Path outputPath; private final List modsList = new ArrayList<>(); @@ -254,21 +250,6 @@ public boolean copyAssets(String modId) { return false; } - public JsonArray getCustomModels(Identifier model, OverridePlace place) { - if (!this.customModels.containsKey(model)) { - var places = new JsonArray[OverridePlace.values().length]; - this.customModels.put(model, places); - } - - var json = this.customModels.get(model)[place.ordinal()]; - - if (json == null) { - json = new JsonArray(); - this.customModels.get(model)[place.ordinal()] = json; - } - return json; - } - @Override public byte[] getData(String path) { return this.fileMap.get(path); @@ -391,50 +372,6 @@ public CompletableFuture buildResourcePack() { this.buildEvent.invoke((c) -> c.accept(credits)); boolean bool = true; - for (var id : this.customModels.keySet()) { - try { - JsonObject modelObject; - - String baseModelPath; - { - baseModelPath = "assets/" + id.getNamespace() + "/models/" + id.getPath() + ".json"; - } - - modelObject = JsonParser.parseString(new String(this.getDataOrSource(baseModelPath), StandardCharsets.UTF_8)).getAsJsonObject(); - - - if (modelObject.has("overrides")) { - var x = modelObject.getAsJsonArray("overrides"); - var existing = this.getCustomModels(id, OverridePlace.EXISTING); - var withCmd = this.getCustomModels(id, OverridePlace.WITH_CUSTOM_MODEL_DATA); - for (var element : x) { - var obj = element.getAsJsonObject(); - if (obj.has("predicate") && obj.getAsJsonObject("predicate").has("custom_model_data")) { - withCmd.add(obj); - } else { - existing.add(obj); - } - } - } - for (var place : OverridePlace.values()) { - this.getCustomModels(id, place).asList().sort(CMD_COMPARATOR); - } - var jsonArray = new JsonArray(); - - for (var models : this.customModels.get(id)) { - if (models != null) { - jsonArray.addAll(models); - } - } - - modelObject.add("overrides", jsonArray); - - this.fileMap.put(baseModelPath, modelObject.toString().getBytes(StandardCharsets.UTF_8)); - } catch (Exception e) { - CommonImpl.LOGGER.error("Something went wrong while saving model of " + id, e); - bool = false; - } - } for (var entry : this.atlasDefinitions.entrySet()) { var obj = new JsonObject(); @@ -486,13 +423,12 @@ private boolean writeSingleZip() { for (var path : this.fileMap.keySet().toArray(new String[0])) { var split = new ArrayList<>(List.of(path.split("/"))); while (split.size() > 1) { - split.remove(split.size() - 1); + split.removeLast(); this.fileMap.put(String.join("/", split) + "/", null); } } - var sorted = new ArrayList<>(this.fileMap.entrySet()); sorted.sort(Map.Entry.comparingByKey()); for (var entry : sorted) { diff --git a/settings.gradle b/settings.gradle index bb3c191f..adfdb315 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,6 +13,7 @@ rootProject.name = 'polymer-bundled' include 'polymer-common' include 'polymer-core' include 'polymer-resource-pack' +include 'polymer-resource-pack-extras' include 'polymer-blocks' include 'polymer-reg-sync-manipulator' include 'polymer-autohost'