From 918ca8315e49b548f2434628d936645ddf915e06 Mon Sep 17 00:00:00 2001 From: Choonster TheMage Date: Sun, 8 Dec 2024 04:40:36 +1100 Subject: [PATCH] Update to 1.21.4 -- Item models aren't working yet --- build.gradle | 2 +- gradle.properties | 12 ++-- .../client/init/ModItemModelProperties.java | 71 ++++++++++++++++--- ...evealHiddenBlocksItemPropertyFunction.java | 4 +- ...TicksSinceLastUseItemPropertyFunction.java | 50 ------------- .../client/model/ModColourManager.java | 6 +- .../properties/numeric/TicksSinceLastUse.java | 54 ++++++++++++++ .../properties/numeric}/package-info.java | 2 +- .../data/TestMod3EquipmentAssetProvider.java | 55 ++++++++++++++ .../data/TestMod3EquipmentModelsProvider.java | 51 ------------- .../data/TestMod3ItemModelProvider.java | 10 +-- .../data/TestMod3LanguageProvider.java | 10 +-- .../ConditionalIngredientBuilder.java | 2 +- .../testmod3/init/ModArmorMaterials.java | 2 +- .../testmod3/init/ModDataProviders.java | 2 +- .../testmod3/init/ModEquipmentAssets.java | 20 ++++++ .../testmod3/init/ModEquipmentModels.java | 13 ---- .../choonster/testmod3/init/ModItems.java | 5 +- .../ingredient/FluidContainerIngredient.java | 6 +- .../level/levelgen/feature/BannerFeature.java | 2 +- 20 files changed, 225 insertions(+), 154 deletions(-) delete mode 100644 src/main/java/choonster/testmod3/client/item/TicksSinceLastUseItemPropertyFunction.java create mode 100644 src/main/java/choonster/testmod3/client/renderer/item/properties/numeric/TicksSinceLastUse.java rename src/main/java/choonster/testmod3/client/{item => renderer/item/properties/numeric}/package-info.java (78%) create mode 100644 src/main/java/choonster/testmod3/data/TestMod3EquipmentAssetProvider.java delete mode 100644 src/main/java/choonster/testmod3/data/TestMod3EquipmentModelsProvider.java create mode 100644 src/main/java/choonster/testmod3/init/ModEquipmentAssets.java delete mode 100644 src/main/java/choonster/testmod3/init/ModEquipmentModels.java diff --git a/build.gradle b/build.gradle index 3ebbb91e..a213e733 100644 --- a/build.gradle +++ b/build.gradle @@ -180,7 +180,7 @@ dependencies { // TODO: Jade doesn't support Forge any more // implementation fg.deobf("curse.maven:jade-324717:${jade_file_id}") - implementation "com.github.glitchfiend:TerraBlender-forge:1.21.3-${terrablender_version}" + implementation "com.github.glitchfiend:TerraBlender-forge:1.21.4-${terrablender_version}" // Example mod dependency using a mod jar from ./libs with a flat dir repository // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar diff --git a/gradle.properties b/gradle.properties index bc67798b..eb7f75d3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,15 +6,15 @@ org.gradle.daemon=false ## Environment Properties # The Minecraft version must agree with the Forge version to get a valid artifact -minecraft_version=1.21.3 +minecraft_version=1.21.4 # The Minecraft version range can use any release version of Minecraft as bounds. # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly # as they do not follow standard versioning conventions. -minecraft_version_range=[1.21.3,1.22) +minecraft_version_range=[1.21.4,1.22) # The Forge version must agree with the Minecraft version to get a valid artifact -forge_version=53.0.25 +forge_version=54.0.6 # The Forge version range can use any version of Forge as bounds or match the loader version range forge_version_range=[0,) @@ -40,11 +40,11 @@ mapping_channel=official # The mapping version to query from the mapping channel. # This must match the format required by the mapping channel. -mapping_version=1.21.3 +mapping_version=1.21.4 jei_version=19.21.0.247 -terrablender_version=4.2.0.1 +terrablender_version=4.3.0.0 # Minecraft uses Apache HTTP Client 4.5.13, so we have to use the same version of the Fluent API httpclient_version=4.5.13 @@ -62,7 +62,7 @@ mod_name=TestMod3 mod_license=MIT # The mod version. See https://semver.org/ -mod_version=21.0.0 +mod_version=22.0.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. diff --git a/src/main/java/choonster/testmod3/client/init/ModItemModelProperties.java b/src/main/java/choonster/testmod3/client/init/ModItemModelProperties.java index fc43ca44..7ace4e35 100644 --- a/src/main/java/choonster/testmod3/client/init/ModItemModelProperties.java +++ b/src/main/java/choonster/testmod3/client/init/ModItemModelProperties.java @@ -1,29 +1,84 @@ package choonster.testmod3.client.init; import choonster.testmod3.TestMod3; -import choonster.testmod3.client.item.RevealHiddenBlocksItemPropertyFunction; -import choonster.testmod3.client.item.TicksSinceLastUseItemPropertyFunction; -import choonster.testmod3.init.ModItems; -import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; +import choonster.testmod3.client.renderer.item.properties.numeric.TicksSinceLastUse; +import com.mojang.serialization.MapCodec; +import net.minecraft.client.renderer.item.properties.conditional.ConditionalItemModelProperties; +import net.minecraft.client.renderer.item.properties.conditional.ConditionalItemModelProperty; +import net.minecraft.client.renderer.item.properties.numeric.RangeSelectItemModelProperties; +import net.minecraft.client.renderer.item.properties.numeric.RangeSelectItemModelProperty; +import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperties; +import net.minecraft.client.renderer.item.properties.select.SelectItemModelProperty; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.ExtraCodecs; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; +import net.minecraftforge.fml.util.ObfuscationReflectionHelper; /** - * Registers this mod's {@link ClampedItemPropertyFunction}s. + * Registers this mod's {@link ConditionalItemModelProperty}, {@link RangeSelectItemModelProperty} and + * {@link SelectItemModelProperty} implementations. * * @author Choonster */ @Mod.EventBusSubscriber(modid = TestMod3.MODID, bus = Bus.MOD, value = Dist.CLIENT) public class ModItemModelProperties { + private static final ExtraCodecs.LateBoundIdMapper>> SELECT_ID_MAPPER; + private static final ExtraCodecs.LateBoundIdMapper> CONDITIONAL_ID_MAPPER; + private static final ExtraCodecs.LateBoundIdMapper> RANGE_SELECT_ID_MAPPER; + + // TODO: Refactor if/when Forge adds a proper event for this @SubscribeEvent public static void registerItemModelProperties(final FMLClientSetupEvent event) { event.enqueueWork(() -> { - RevealHiddenBlocksItemPropertyFunction.registerForItem(ModItems.HIDDEN_BLOCK_REVEALER.get()); - TicksSinceLastUseItemPropertyFunction.registerForItem(ModItems.MODEL_TEST.get()); - TicksSinceLastUseItemPropertyFunction.registerForItem(ModItems.SLINGSHOT.get()); +// RevealHiddenBlocksItemPropertyFunction.registerForItem(ModItems.HIDDEN_BLOCK_REVEALER.get()); + registerRangeSelect("ticks_since_last_use", TicksSinceLastUse.MAP_CODEC); + +// TicksSinceLastUse.registerForItem(ModItems.MODEL_TEST.get()); +// TicksSinceLastUse.registerForItem(ModItems.SLINGSHOT.get()); }); } + + private static void registerRangeSelect( + final String name, + final MapCodec mapCodec + ) { + RANGE_SELECT_ID_MAPPER.put(ResourceLocation.fromNamespaceAndPath(TestMod3.MODID, name), mapCodec); + } + + static { + try { + @SuppressWarnings("unchecked") final var selectIdMapper = + (ExtraCodecs.LateBoundIdMapper>>) + ObfuscationReflectionHelper.findField( + SelectItemModelProperties.class, + "ID_MAPPER" + ).get(null); + + SELECT_ID_MAPPER = selectIdMapper; + + @SuppressWarnings("unchecked") final var conditionalIdMapper = + (ExtraCodecs.LateBoundIdMapper>) + ObfuscationReflectionHelper.findField( + ConditionalItemModelProperties.class, + "ID_MAPPER" + ).get(null); + + CONDITIONAL_ID_MAPPER = conditionalIdMapper; + + @SuppressWarnings("unchecked") final var rangeSelectIdMapper = + (ExtraCodecs.LateBoundIdMapper>) + ObfuscationReflectionHelper.findField( + RangeSelectItemModelProperties.class, + "ID_MAPPER" + ).get(null); + + RANGE_SELECT_ID_MAPPER = rangeSelectIdMapper; + } catch (final IllegalAccessException e) { + throw new RuntimeException("Failed to initialise Item Property ID Mappers", e); + } + } } diff --git a/src/main/java/choonster/testmod3/client/item/RevealHiddenBlocksItemPropertyFunction.java b/src/main/java/choonster/testmod3/client/item/RevealHiddenBlocksItemPropertyFunction.java index 2a1308a2..780f2005 100644 --- a/src/main/java/choonster/testmod3/client/item/RevealHiddenBlocksItemPropertyFunction.java +++ b/src/main/java/choonster/testmod3/client/item/RevealHiddenBlocksItemPropertyFunction.java @@ -10,7 +10,9 @@ /** * {@link ClampedItemPropertyFunction} to get whether hidden blocks are being revealed by an item's {@link ModDataComponents#REVEAL_HIDDEN_BLOCKS} component. */ -public class RevealHiddenBlocksItemPropertyFunction { +// TODO: Replace with HasComponent +@Deprecated(forRemoval = true) +public record RevealHiddenBlocksItemPropertyFunction() { /** * The ID of this function. */ diff --git a/src/main/java/choonster/testmod3/client/item/TicksSinceLastUseItemPropertyFunction.java b/src/main/java/choonster/testmod3/client/item/TicksSinceLastUseItemPropertyFunction.java deleted file mode 100644 index 70229e91..00000000 --- a/src/main/java/choonster/testmod3/client/item/TicksSinceLastUseItemPropertyFunction.java +++ /dev/null @@ -1,50 +0,0 @@ -package choonster.testmod3.client.item; - -import choonster.testmod3.TestMod3; -import choonster.testmod3.init.ModDataComponents; -import choonster.testmod3.world.item.component.lastusetime.LastUseTimeProperties; -import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; -import net.minecraft.client.renderer.item.ItemProperties; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.Level; - -import java.util.Optional; - -/** - * {@link ClampedItemPropertyFunction} to get the ticks since the last use of the item, as recorded by the item's {@link LastUseTimeProperties} component. - *

- * Returns 0.0 if the item was last used 0 ticks ago and 1.0 if the item was last used 20 or more ticks ago. - * Returns 1.0 if the required information isn't available. - */ -public class TicksSinceLastUseItemPropertyFunction { - /** - * The ID of this function. - */ - public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(TestMod3.MODID, "ticks_since_last_use"); - - /** - * The function. - */ - private static final ClampedItemPropertyFunction GETTER = (stack, level, entity, seed) -> - { - final Level world = level != null ? level : entity != null ? entity.getCommandSenderWorld() : null; - - if (world == null) { - return 1.0f; - } - - return Optional.ofNullable(stack.get(ModDataComponents.LAST_USE_TIME_PROPERTIES.get())) - .map(properties -> (world.getGameTime() - properties.lastUseTime()) / 20.0f) - .orElse(1.0f); - }; - - /** - * Add this getter to an {@link Item}. - * - * @param item The item - */ - public static void registerForItem(final Item item) { - ItemProperties.register(item, ID, GETTER); - } -} diff --git a/src/main/java/choonster/testmod3/client/model/ModColourManager.java b/src/main/java/choonster/testmod3/client/model/ModColourManager.java index 9a90ab24..b7302bca 100644 --- a/src/main/java/choonster/testmod3/client/model/ModColourManager.java +++ b/src/main/java/choonster/testmod3/client/model/ModColourManager.java @@ -16,7 +16,7 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; /** - * Registers {@link BlockColor}/{@link ItemColor} handlers for this mod's blocks/items. + * Registers {@link BlockColor} handlers for this mod's blocks. * * @author Choonster */ @@ -36,7 +36,7 @@ public static void registerBlockColourHandlers(final RegisterColorHandlersEvent. return BiomeColors.getAverageGrassColor(blockAccess, pos); } - return GrassColor.get(0.5d, 1.0d); + return GrassColor.getDefaultColor(); }; event.register(grassColourHandler, ModBlocks.WATER_GRASS.get()); @@ -51,12 +51,14 @@ public static void registerBlockColourHandlers(final RegisterColorHandlersEvent. public static void registerItemColourHandlers(final RegisterColorHandlersEvent.Item event) { final BlockColors blockColors = event.getBlockColors(); + // Use the Block's colour handler for an ItemBlock final ItemColor itemBlockColourHandler = (stack, tintIndex) -> { final BlockState state = ((BlockItem) stack.getItem()).getBlock().defaultBlockState(); return blockColors.getColor(state, null, null, tintIndex); }; + // TODO: Replace with GrassColorSource event.register(itemBlockColourHandler, ModBlocks.WATER_GRASS.get()); } } diff --git a/src/main/java/choonster/testmod3/client/renderer/item/properties/numeric/TicksSinceLastUse.java b/src/main/java/choonster/testmod3/client/renderer/item/properties/numeric/TicksSinceLastUse.java new file mode 100644 index 00000000..6520681d --- /dev/null +++ b/src/main/java/choonster/testmod3/client/renderer/item/properties/numeric/TicksSinceLastUse.java @@ -0,0 +1,54 @@ +package choonster.testmod3.client.renderer.item.properties.numeric; + +import choonster.testmod3.TestMod3; +import choonster.testmod3.init.ModDataComponents; +import choonster.testmod3.world.item.component.lastusetime.LastUseTimeProperties; +import com.mojang.serialization.MapCodec; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.item.properties.numeric.RangeSelectItemModelProperty; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +/** + * {@link RangeSelectItemModelProperty} to get the ticks since the last use of the item, + * as recorded by the item's {@link LastUseTimeProperties} component. + *

+ * Returns 0.0 if the item was last used 0 ticks ago and 1.0 if the item was last used 20 or more ticks ago. + * Returns 1.0 if the required information isn't available. + */ +public record TicksSinceLastUse() implements RangeSelectItemModelProperty { + public static final MapCodec MAP_CODEC = MapCodec.unit(new TicksSinceLastUse()); + + /** + * The ID of this function. + */ + @Deprecated(forRemoval = true) + public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(TestMod3.MODID, "ticks_since_last_use"); + + @Override + public float get( + final ItemStack stack, + @Nullable final ClientLevel clientLevel, + @Nullable final LivingEntity entity, + final int seed + ) { + final var level = clientLevel != null ? clientLevel : entity != null ? entity.level() : null; + + if (level == null) { + return 1.0f; + } + + return Optional.ofNullable(stack.get(ModDataComponents.LAST_USE_TIME_PROPERTIES.get())) + .map(properties -> (level.getGameTime() - properties.lastUseTime()) / 20.0f) + .orElse(1.0f); + } + + @Override + public MapCodec type() { + return MAP_CODEC; + } +} diff --git a/src/main/java/choonster/testmod3/client/item/package-info.java b/src/main/java/choonster/testmod3/client/renderer/item/properties/numeric/package-info.java similarity index 78% rename from src/main/java/choonster/testmod3/client/item/package-info.java rename to src/main/java/choonster/testmod3/client/renderer/item/properties/numeric/package-info.java index efb6cd55..b4f512a5 100644 --- a/src/main/java/choonster/testmod3/client/item/package-info.java +++ b/src/main/java/choonster/testmod3/client/renderer/item/properties/numeric/package-info.java @@ -1,7 +1,7 @@ @FieldsAreNonnullByDefault @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault -package choonster.testmod3.client.item; +package choonster.testmod3.client.renderer.item.properties.numeric; import net.minecraft.FieldsAreNonnullByDefault; import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/java/choonster/testmod3/data/TestMod3EquipmentAssetProvider.java b/src/main/java/choonster/testmod3/data/TestMod3EquipmentAssetProvider.java new file mode 100644 index 00000000..cbe32251 --- /dev/null +++ b/src/main/java/choonster/testmod3/data/TestMod3EquipmentAssetProvider.java @@ -0,0 +1,55 @@ +package choonster.testmod3.data; + +import choonster.testmod3.init.ModEquipmentAssets; +import net.minecraft.client.resources.model.EquipmentClientInfo; +import net.minecraft.data.CachedOutput; +import net.minecraft.data.DataProvider; +import net.minecraft.data.PackOutput; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.equipment.EquipmentAsset; + +import java.util.HashMap; +import java.util.concurrent.CompletableFuture; +import java.util.function.BiConsumer; + +/** + * Generates this mod's equipment assets. + * + * @author Choonster + */ +public class TestMod3EquipmentAssetProvider implements DataProvider { + private final PackOutput.PathProvider pathProvider; + + public TestMod3EquipmentAssetProvider(final PackOutput output) { + pathProvider = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, "equipment"); + } + + @Override + public CompletableFuture run(final CachedOutput output) { + final var map = new HashMap, EquipmentClientInfo>(); + + bootstrap((id, equipmentClientInfo) -> { + if (map.putIfAbsent(id, equipmentClientInfo) != null) { + throw new IllegalStateException("Tried to register equipment asset twice for id: " + id); + } + }); + + return DataProvider.saveAll(output, EquipmentClientInfo.CODEC, pathProvider::json, map); + } + + @Override + public String getName() { + return "TestMod3 Equipment Asset Definitions"; + } + + private static void bootstrap(final BiConsumer, EquipmentClientInfo> consumer) { + consumer.accept(ModEquipmentAssets.REPLACEMENT, onlyHumanoid("chainmail")); + } + + private static EquipmentClientInfo onlyHumanoid(final String textureName) { + return EquipmentClientInfo.builder() + .addHumanoidLayers(ResourceLocation.withDefaultNamespace(textureName)) + .build(); + } +} diff --git a/src/main/java/choonster/testmod3/data/TestMod3EquipmentModelsProvider.java b/src/main/java/choonster/testmod3/data/TestMod3EquipmentModelsProvider.java deleted file mode 100644 index 8526ab65..00000000 --- a/src/main/java/choonster/testmod3/data/TestMod3EquipmentModelsProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -package choonster.testmod3.data; - -import choonster.testmod3.init.ModEquipmentModels; -import net.minecraft.data.CachedOutput; -import net.minecraft.data.DataProvider; -import net.minecraft.data.PackOutput; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.equipment.EquipmentModel; - -import java.util.HashMap; -import java.util.concurrent.CompletableFuture; -import java.util.function.BiConsumer; - -/** - * Generates this mod's equipment models. - * - * @author Choonster - */ -public class TestMod3EquipmentModelsProvider implements DataProvider { - private final PackOutput.PathProvider pathProvider; - - public TestMod3EquipmentModelsProvider(final PackOutput output) { - pathProvider = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, "models/equipment"); - } - - @Override - public CompletableFuture run(final CachedOutput output) { - final var map = new HashMap(); - - bootstrap((id, equipmentModel) -> { - if (map.putIfAbsent(id, equipmentModel) != null) { - throw new IllegalStateException("Tried to register equipment model twice for id: " + id); - } - }); - - return DataProvider.saveAll(output, EquipmentModel.CODEC, pathProvider, map); - } - - @Override - public String getName() { - return "TestMod3 Equipment Model Definitions"; - } - - private static void bootstrap(final BiConsumer p_360870_) { - p_360870_.accept(ModEquipmentModels.REPLACEMENT, onlyHumanoid("chainmail")); - } - - private static EquipmentModel onlyHumanoid(final String textureName) { - return EquipmentModel.builder().addHumanoidLayers(ResourceLocation.withDefaultNamespace(textureName)).build(); - } -} diff --git a/src/main/java/choonster/testmod3/data/TestMod3ItemModelProvider.java b/src/main/java/choonster/testmod3/data/TestMod3ItemModelProvider.java index 6fa17808..eae61a0f 100644 --- a/src/main/java/choonster/testmod3/data/TestMod3ItemModelProvider.java +++ b/src/main/java/choonster/testmod3/data/TestMod3ItemModelProvider.java @@ -2,7 +2,7 @@ import choonster.testmod3.TestMod3; import choonster.testmod3.client.item.RevealHiddenBlocksItemPropertyFunction; -import choonster.testmod3.client.item.TicksSinceLastUseItemPropertyFunction; +import choonster.testmod3.client.renderer.item.properties.numeric.TicksSinceLastUse; import choonster.testmod3.fluid.group.FluidGroup; import choonster.testmod3.init.ModFluids; import choonster.testmod3.init.ModItems; @@ -113,7 +113,7 @@ protected void registerModels() { .forEachOrdered(child -> modelTest .override() - .predicate(TicksSinceLastUseItemPropertyFunction.ID, child.getKey() * 20) + .predicate(TicksSinceLastUse.ID, child.getKey() * 20) .model(child.getValue()) .end() ); @@ -121,7 +121,7 @@ protected void registerModels() { // Add the parent as a fallback that displays when the ticks since last use is >= 60 modelTest .override() - .predicate(TicksSinceLastUseItemPropertyFunction.ID, 60) + .predicate(TicksSinceLastUse.ID, 60) .model(modelTest) .end(); @@ -140,14 +140,14 @@ protected void registerModels() { // Add the child as an override that displays when the ticks since last use is >= 0 and < 20 slingshot .override() - .predicate(TicksSinceLastUseItemPropertyFunction.ID, 0) + .predicate(TicksSinceLastUse.ID, 0) .model(slingshotPulled) .end(); // Add the parent as a fallback that displays when the ticks since last use is >= 20 slingshot .override() - .predicate(TicksSinceLastUseItemPropertyFunction.ID, 1) + .predicate(TicksSinceLastUse.ID, 1) .model(slingshot) .end(); diff --git a/src/main/java/choonster/testmod3/data/TestMod3LanguageProvider.java b/src/main/java/choonster/testmod3/data/TestMod3LanguageProvider.java index 959239cd..c49bb0b4 100644 --- a/src/main/java/choonster/testmod3/data/TestMod3LanguageProvider.java +++ b/src/main/java/choonster/testmod3/data/TestMod3LanguageProvider.java @@ -15,15 +15,11 @@ import net.minecraft.network.chat.contents.TranslatableContents; import net.minecraft.util.StringRepresentable; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.DyeColor; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; +import net.minecraft.world.item.*; import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.item.alchemy.PotionContents; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.material.Fluid; -import net.minecraftforge.common.ForgeSpawnEggItem; import net.minecraftforge.common.data.LanguageProvider; import net.minecraftforge.fluids.FluidType; import org.apache.commons.lang3.StringUtils; @@ -370,9 +366,9 @@ public void addEntityType(final Supplier> key, final Str ENTITY_TYPE_NAMES.put(key.get(), name); } - private void addSpawnEgg(final Supplier spawnEggItem) { + private void addSpawnEgg(final Supplier spawnEggItem) { final var item = spawnEggItem.get(); - final var entityType = item.getType(item.getDefaultInstance()); + final var entityType = item.getDefaultType(); add(item, String.format("%s Spawn Egg", ENTITY_TYPE_NAMES.get(entityType))); } diff --git a/src/main/java/choonster/testmod3/data/crafting/ingredient/ConditionalIngredientBuilder.java b/src/main/java/choonster/testmod3/data/crafting/ingredient/ConditionalIngredientBuilder.java index c507aa1b..13b76e0c 100644 --- a/src/main/java/choonster/testmod3/data/crafting/ingredient/ConditionalIngredientBuilder.java +++ b/src/main/java/choonster/testmod3/data/crafting/ingredient/ConditionalIngredientBuilder.java @@ -66,7 +66,7 @@ public ConditionalIngredientBuilder condition(final ICondition condition) { */ public ConditionalIngredient build() { if (condition == null) { - final var stacks = ingredient.items().stream() + @SuppressWarnings("deprecation") final var stacks = ingredient.items() .map(Holder::get) .map(Item::toString) .collect(Collectors.joining(",")); diff --git a/src/main/java/choonster/testmod3/init/ModArmorMaterials.java b/src/main/java/choonster/testmod3/init/ModArmorMaterials.java index 9191022b..165d4b8b 100644 --- a/src/main/java/choonster/testmod3/init/ModArmorMaterials.java +++ b/src/main/java/choonster/testmod3/init/ModArmorMaterials.java @@ -26,6 +26,6 @@ public class ModArmorMaterials { 0, 0, ModTags.Items.REPAIRS_REPLACEMENT_ARMOR, - ModEquipmentModels.REPLACEMENT + ModEquipmentAssets.REPLACEMENT ); } diff --git a/src/main/java/choonster/testmod3/init/ModDataProviders.java b/src/main/java/choonster/testmod3/init/ModDataProviders.java index d111a289..c695b630 100644 --- a/src/main/java/choonster/testmod3/init/ModDataProviders.java +++ b/src/main/java/choonster/testmod3/init/ModDataProviders.java @@ -48,7 +48,7 @@ public static void registerDataProviders(final GatherDataEvent event) { dataGenerator.addProvider(event.includeClient(), new TestMod3SoundDefinitionsProvider(output, existingFileHelper)); - dataGenerator.addProvider(event.includeClient(), new TestMod3EquipmentModelsProvider(output)); + dataGenerator.addProvider(event.includeClient(), new TestMod3EquipmentAssetProvider(output)); dataGenerator.addProvider(event.includeServer(), new TestMod3RecipeProvider.Runner(output, lookupProvider)); dataGenerator.addProvider(event.includeServer(), TestMod3LootTableProvider.create(output, lookupProvider)); diff --git a/src/main/java/choonster/testmod3/init/ModEquipmentAssets.java b/src/main/java/choonster/testmod3/init/ModEquipmentAssets.java new file mode 100644 index 00000000..6777a64e --- /dev/null +++ b/src/main/java/choonster/testmod3/init/ModEquipmentAssets.java @@ -0,0 +1,20 @@ +package choonster.testmod3.init; + +import choonster.testmod3.TestMod3; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.equipment.EquipmentAsset; +import net.minecraft.world.item.equipment.EquipmentAssets; + +/** + * Stores the keys for this mod's {@link net.minecraft.world.item.equipment.EquipmentAsset EquipmentAssets}. + * + * @author Choonster + */ +public class ModEquipmentAssets { + public static ResourceKey REPLACEMENT = createId("replacement"); + + private static ResourceKey createId(final String name) { + return ResourceKey.create(EquipmentAssets.ROOT_ID, ResourceLocation.fromNamespaceAndPath(TestMod3.MODID, name)); + } +} diff --git a/src/main/java/choonster/testmod3/init/ModEquipmentModels.java b/src/main/java/choonster/testmod3/init/ModEquipmentModels.java deleted file mode 100644 index f2e4c601..00000000 --- a/src/main/java/choonster/testmod3/init/ModEquipmentModels.java +++ /dev/null @@ -1,13 +0,0 @@ -package choonster.testmod3.init; - -import choonster.testmod3.TestMod3; -import net.minecraft.resources.ResourceLocation; - -/** - * Stores the keys for this mod's {@link net.minecraft.world.item.equipment.EquipmentModel EquipmentModels}. - * - * @author Choonster - */ -public class ModEquipmentModels { - public static ResourceLocation REPLACEMENT = ResourceLocation.fromNamespaceAndPath(TestMod3.MODID, "replacement"); -} diff --git a/src/main/java/choonster/testmod3/init/ModItems.java b/src/main/java/choonster/testmod3/init/ModItems.java index ad98d7b8..056ee3af 100644 --- a/src/main/java/choonster/testmod3/init/ModItems.java +++ b/src/main/java/choonster/testmod3/init/ModItems.java @@ -21,7 +21,6 @@ import net.minecraft.world.item.equipment.ArmorType; import net.minecraft.world.level.dimension.BuiltinDimensionTypes; import net.minecraft.world.level.dimension.DimensionType; -import net.minecraftforge.common.ForgeSpawnEggItem; import net.minecraftforge.event.GatherComponentsEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -354,8 +353,8 @@ public class ModItems { defaultItemProperties() // Component registered in EventHandler ); - public static final RegistryObject PLAYER_AVOIDING_CREEPER_SPAWN_EGG = registerItem("player_avoiding_creeper_spawn_egg", - (properties) -> new ForgeSpawnEggItem(ModEntities.PLAYER_AVOIDING_CREEPER, 0xda70b, 0, properties), + public static final RegistryObject PLAYER_AVOIDING_CREEPER_SPAWN_EGG = registerItem("player_avoiding_creeper_spawn_egg", + (properties) -> new SpawnEggItem(ModEntities.PLAYER_AVOIDING_CREEPER.get(), properties), // TODO: Colours = 0xda70b, 0 defaultItemProperties() ); diff --git a/src/main/java/choonster/testmod3/world/item/crafting/ingredient/FluidContainerIngredient.java b/src/main/java/choonster/testmod3/world/item/crafting/ingredient/FluidContainerIngredient.java index 25ba0c57..87c5dc7f 100644 --- a/src/main/java/choonster/testmod3/world/item/crafting/ingredient/FluidContainerIngredient.java +++ b/src/main/java/choonster/testmod3/world/item/crafting/ingredient/FluidContainerIngredient.java @@ -20,6 +20,7 @@ import javax.annotation.Nullable; import java.util.List; +import java.util.stream.Stream; /** * An ingredient that matches any fluid container filled with the specified {@link FluidStack}. @@ -67,8 +68,9 @@ public IIngredientSerializer serializer() { return ModCrafting.Ingredients.FLUID_CONTAINER.get(); } + @SuppressWarnings("deprecation") @Override - public List> items() { + public Stream> items() { if (items == null) { items = RegistryUtil.stream(ForgeRegistries.ITEMS) .map(ItemStack::new) @@ -80,7 +82,7 @@ public List> items() { .toList(); } - return items; + return items.stream(); } @Override diff --git a/src/main/java/choonster/testmod3/world/level/levelgen/feature/BannerFeature.java b/src/main/java/choonster/testmod3/world/level/levelgen/feature/BannerFeature.java index 04aebf01..f9df6126 100644 --- a/src/main/java/choonster/testmod3/world/level/levelgen/feature/BannerFeature.java +++ b/src/main/java/choonster/testmod3/world/level/levelgen/feature/BannerFeature.java @@ -41,7 +41,7 @@ public boolean place(final FeaturePlaceContext context) { if (blockEntity instanceof final BannerBlockEntity bannerBlockEntity) { final var bannerItem = new ItemStack(bannerBlock); bannerItem.set(DataComponents.BANNER_PATTERNS, config.patterns()); - bannerBlockEntity.fromItem(bannerItem, color); + bannerBlockEntity.applyComponentsFromItemStack(bannerItem); } return true;