From 7f9d8974070c96485ac2feee574d850de4855cb9 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Wed, 18 Dec 2024 02:10:03 -0500 Subject: [PATCH 01/14] possibly fix tundra colors sometimes not working --- .../biome/mixin/BiomeManagerMixin.java | 2 +- .../biome/mixin/RegistryDataLoaderMixin.java | 64 +++++++++++++++++++ .../frozenlib.worldgen.biome.mixins.json | 3 +- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java diff --git a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeManagerMixin.java b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeManagerMixin.java index 1e89f0d3..68e3f5ed 100644 --- a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeManagerMixin.java +++ b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeManagerMixin.java @@ -31,7 +31,7 @@ public class BiomeManagerMixin { @ModifyReturnValue(method = "getBiome", at = @At("RETURN")) public Holder frozenLib$appendBiomeID(Holder original) { if ((Object) original.value() instanceof BiomeInterface biomeInterface) { - original.unwrap().left().ifPresent(biomeResourceKey -> biomeInterface.frozenLib$setBiomeID(biomeResourceKey.location())); + original.unwrapKey().ifPresent(biomeResourceKey -> biomeInterface.frozenLib$setBiomeID(biomeResourceKey.location())); } return original; } diff --git a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java new file mode 100644 index 00000000..d45968c2 --- /dev/null +++ b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 FrozenBlock + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.frozenblock.lib.worldgen.biome.mixin; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.sugar.Local; +import net.frozenblock.lib.worldgen.biome.impl.BiomeInterface; +import net.minecraft.resources.RegistryDataLoader; +import net.minecraft.resources.ResourceKey; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(RegistryDataLoader.class) +public class RegistryDataLoaderMixin { + + @ModifyReturnValue( + method = "loadContentsFromNetwork", + at = @At( + value = "INVOKE", + target = "Lcom/mojang/serialization/DataResult;getOrThrow()Ljava/lang/Object;" + ) + ) + private static Object frozenLib$appendBiomeIDFromNetwork( + Object original, + @Local ResourceKey resourceKey + ) { + if (original instanceof BiomeInterface biomeInterface) { + biomeInterface.frozenLib$setBiomeID(resourceKey.location()); + } + return original; + } + + @ModifyReturnValue( + method = "loadElementFromResource", + at = @At( + value = "INVOKE", + target = "Lcom/mojang/serialization/DataResult;getOrThrow()Ljava/lang/Object;" + ) + ) + private static Object frozenLib$appendBiomeIDFromResource( + Object original, + ResourceKey resourceKey + ) { + if (original instanceof BiomeInterface biomeInterface) { + biomeInterface.frozenLib$setBiomeID(resourceKey.location()); + } + return original; + } +} diff --git a/src/main/resources/mixin/frozenlib.worldgen.biome.mixins.json b/src/main/resources/mixin/frozenlib.worldgen.biome.mixins.json index 04afcc22..954e89fc 100644 --- a/src/main/resources/mixin/frozenlib.worldgen.biome.mixins.json +++ b/src/main/resources/mixin/frozenlib.worldgen.biome.mixins.json @@ -11,6 +11,7 @@ "BiomeMixin", "MultiNoiseBiomeSourceMixin", "OverworldBiomeBuilderMixin", - "OverworldBiomePresetMixin" + "OverworldBiomePresetMixin", + "RegistryDataLoaderMixin" ] } From 964212f43b9887922149544c3c2eab8150bc18aa Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Wed, 18 Dec 2024 02:20:20 -0500 Subject: [PATCH 02/14] fix --- .../biome/mixin/RegistryDataLoaderMixin.java | 44 +++++++------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java index d45968c2..666fc857 100644 --- a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java +++ b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java @@ -17,48 +17,34 @@ package net.frozenblock.lib.worldgen.biome.mixin; -import com.llamalad7.mixinextras.injector.ModifyReturnValue; -import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.frozenblock.lib.worldgen.biome.impl.BiomeInterface; +import net.minecraft.core.Holder; +import net.minecraft.core.RegistrationInfo; +import net.minecraft.core.WritableRegistry; import net.minecraft.resources.RegistryDataLoader; import net.minecraft.resources.ResourceKey; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -@Mixin(RegistryDataLoader.class) +@Mixin(value = RegistryDataLoader.class, priority = 50) public class RegistryDataLoaderMixin { - @ModifyReturnValue( - method = "loadContentsFromNetwork", + @WrapOperation( + method = {"loadContentsFromNetwork", "loadElementFromResource"}, at = @At( value = "INVOKE", - target = "Lcom/mojang/serialization/DataResult;getOrThrow()Ljava/lang/Object;" - ) + target = "Lnet/minecraft/core/WritableRegistry;register(Lnet/minecraft/resources/ResourceKey;Ljava/lang/Object;Lnet/minecraft/core/RegistrationInfo;)Lnet/minecraft/core/Holder$Reference;" + ), + require = 2 ) - private static Object frozenLib$appendBiomeIDFromNetwork( - Object original, - @Local ResourceKey resourceKey + private static Holder.Reference frozenLib$appendBiomeIDFromNetwork( + WritableRegistry instance, ResourceKey resourceKey, Object object, RegistrationInfo registrationInfo, Operation original ) { - if (original instanceof BiomeInterface biomeInterface) { + if (object instanceof BiomeInterface biomeInterface) { biomeInterface.frozenLib$setBiomeID(resourceKey.location()); } - return original; - } - - @ModifyReturnValue( - method = "loadElementFromResource", - at = @At( - value = "INVOKE", - target = "Lcom/mojang/serialization/DataResult;getOrThrow()Ljava/lang/Object;" - ) - ) - private static Object frozenLib$appendBiomeIDFromResource( - Object original, - ResourceKey resourceKey - ) { - if (original instanceof BiomeInterface biomeInterface) { - biomeInterface.frozenLib$setBiomeID(resourceKey.location()); - } - return original; + return original.call(instance, resourceKey, object, registrationInfo); } } From b22805580cc93a8b70d6bcf71366ff65aa15a428 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Wed, 18 Dec 2024 02:24:05 -0500 Subject: [PATCH 03/14] performance moment --- .../biome/mixin/BiomeManagerMixin.java | 38 ------------------- .../frozenlib.worldgen.biome.mixins.json | 1 - 2 files changed, 39 deletions(-) delete mode 100644 src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeManagerMixin.java diff --git a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeManagerMixin.java b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeManagerMixin.java deleted file mode 100644 index 68e3f5ed..00000000 --- a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeManagerMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2024 FrozenBlock - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.frozenblock.lib.worldgen.biome.mixin; - -import com.llamalad7.mixinextras.injector.ModifyReturnValue; -import net.frozenblock.lib.worldgen.biome.impl.BiomeInterface; -import net.minecraft.core.Holder; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeManager; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(BiomeManager.class) -public class BiomeManagerMixin { - - @ModifyReturnValue(method = "getBiome", at = @At("RETURN")) - public Holder frozenLib$appendBiomeID(Holder original) { - if ((Object) original.value() instanceof BiomeInterface biomeInterface) { - original.unwrapKey().ifPresent(biomeResourceKey -> biomeInterface.frozenLib$setBiomeID(biomeResourceKey.location())); - } - return original; - } -} diff --git a/src/main/resources/mixin/frozenlib.worldgen.biome.mixins.json b/src/main/resources/mixin/frozenlib.worldgen.biome.mixins.json index 954e89fc..5cb90abc 100644 --- a/src/main/resources/mixin/frozenlib.worldgen.biome.mixins.json +++ b/src/main/resources/mixin/frozenlib.worldgen.biome.mixins.json @@ -7,7 +7,6 @@ "defaultRequire": 1 }, "mixins": [ - "BiomeManagerMixin", "BiomeMixin", "MultiNoiseBiomeSourceMixin", "OverworldBiomeBuilderMixin", From 0b0da9a184b127274782135c7d0bb84d77ede306 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Wed, 18 Dec 2024 02:36:53 -0500 Subject: [PATCH 04/14] performance moment --- .../worldgen/biome/impl/BiomeInterface.java | 6 ++---- .../lib/worldgen/biome/mixin/BiomeMixin.java | 20 +++++++------------ .../biome/mixin/RegistryDataLoaderMixin.java | 6 +++++- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/frozenblock/lib/worldgen/biome/impl/BiomeInterface.java b/src/main/java/net/frozenblock/lib/worldgen/biome/impl/BiomeInterface.java index 768962d1..75102118 100644 --- a/src/main/java/net/frozenblock/lib/worldgen/biome/impl/BiomeInterface.java +++ b/src/main/java/net/frozenblock/lib/worldgen/biome/impl/BiomeInterface.java @@ -17,12 +17,10 @@ package net.frozenblock.lib.worldgen.biome.impl; -import net.minecraft.resources.ResourceLocation; - public interface BiomeInterface { - void frozenLib$setBiomeID(ResourceLocation biomeID); + void frozenLib$setFrozenGrassColorModifier(FrozenGrassColorModifier frozenGrassColorModifier); - ResourceLocation frozenLib$getBiomeID(); + FrozenGrassColorModifier frozenLib$getFrozenGrassColorModifier(); } diff --git a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeMixin.java b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeMixin.java index 56be137b..68968578 100644 --- a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeMixin.java +++ b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/BiomeMixin.java @@ -17,12 +17,9 @@ package net.frozenblock.lib.worldgen.biome.mixin; -import java.util.Optional; import com.llamalad7.mixinextras.injector.ModifyReturnValue; -import net.frozenblock.lib.worldgen.biome.api.FrozenGrassColorModifiers; import net.frozenblock.lib.worldgen.biome.impl.BiomeInterface; import net.frozenblock.lib.worldgen.biome.impl.FrozenGrassColorModifier; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -31,7 +28,7 @@ @Mixin(Biome.class) public class BiomeMixin implements BiomeInterface { @Unique - private ResourceLocation frozenLib$biomeID; + private FrozenGrassColorModifier frozenLib$frozenGrassColorModifier; @ModifyReturnValue( method = "getGrassColor", @@ -40,22 +37,19 @@ public class BiomeMixin implements BiomeInterface { ) ) public int frozenLib$modifyGrassColor(int original, double x, double y) { - if (this.frozenLib$biomeID != null) { - Optional optionalFrozenGrassColorModifier = FrozenGrassColorModifiers.getGrassColorModifier(this.frozenLib$biomeID); - if (optionalFrozenGrassColorModifier.isPresent()) { - return optionalFrozenGrassColorModifier.get().modifyGrassColor(x, y, original); - } + if (this.frozenLib$frozenGrassColorModifier != null) { + return this.frozenLib$frozenGrassColorModifier.modifyGrassColor(x, y, original); } return original; } @Override - public void frozenLib$setBiomeID(ResourceLocation biomeID) { - this.frozenLib$biomeID = biomeID; + public void frozenLib$setFrozenGrassColorModifier(FrozenGrassColorModifier frozenGrassColorModifier) { + this.frozenLib$frozenGrassColorModifier = frozenGrassColorModifier; } @Override - public ResourceLocation frozenLib$getBiomeID() { - return this.frozenLib$biomeID; + public FrozenGrassColorModifier frozenLib$getFrozenGrassColorModifier() { + return this.frozenLib$frozenGrassColorModifier; } } diff --git a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java index 666fc857..c50fc7f1 100644 --- a/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java +++ b/src/main/java/net/frozenblock/lib/worldgen/biome/mixin/RegistryDataLoaderMixin.java @@ -19,7 +19,9 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.frozenblock.lib.worldgen.biome.api.FrozenGrassColorModifiers; import net.frozenblock.lib.worldgen.biome.impl.BiomeInterface; +import net.frozenblock.lib.worldgen.biome.impl.FrozenGrassColorModifier; import net.minecraft.core.Holder; import net.minecraft.core.RegistrationInfo; import net.minecraft.core.WritableRegistry; @@ -27,6 +29,7 @@ import net.minecraft.resources.ResourceKey; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import java.util.Optional; @Mixin(value = RegistryDataLoader.class, priority = 50) public class RegistryDataLoaderMixin { @@ -43,7 +46,8 @@ public class RegistryDataLoaderMixin { WritableRegistry instance, ResourceKey resourceKey, Object object, RegistrationInfo registrationInfo, Operation original ) { if (object instanceof BiomeInterface biomeInterface) { - biomeInterface.frozenLib$setBiomeID(resourceKey.location()); + Optional optionalFrozenGrassColorModifier = FrozenGrassColorModifiers.getGrassColorModifier(resourceKey.location()); + optionalFrozenGrassColorModifier.ifPresent(biomeInterface::frozenLib$setFrozenGrassColorModifier); } return original.call(instance, resourceKey, object, registrationInfo); } From 02e65b6138748d60774efa0573a3d587876ec801 Mon Sep 17 00:00:00 2001 From: Treetrain1 Date: Thu, 19 Dec 2024 03:20:34 -0600 Subject: [PATCH 05/14] Kotlin 2.1 --- CHANGELOG.md | 2 +- build.gradle.kts | 32 ++++++++++---------------------- gradle.properties | 8 ++++---- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1db2abe2..29dfa398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,4 +5,4 @@ Make sure to clear this after each release Put changelog here: ----------------- -- Fixed a crash with VMP. +- Updated to Kotlin 2.1 diff --git a/build.gradle.kts b/build.gradle.kts index 8d63de72..0e8f7c87 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,13 +24,13 @@ plugins { id("org.ajoberstar.grgit") version("+") id("org.quiltmc.gradle.licenser") version("+") id("com.modrinth.minotaur") version("+") - id("com.github.johnrengelman.shadow") version("+") + id("com.gradleup.shadow") version("+") `maven-publish` eclipse idea `java-library` java - kotlin("jvm") version("2.0.21") + kotlin("jvm") version("2.1.0") } val minecraft_version: String by project @@ -190,42 +190,30 @@ repositories { // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - maven { - url = uri("https://jitpack.io") - } - maven { + maven("https://api.modrinth.com/maven") { name = "Modrinth" - url = uri("https://api.modrinth.com/maven") content { includeGroup("maven.modrinth") } } - maven { - url = uri("https://maven.terraformersmc.com") - + maven("https://maven.terraformersmc.com") { content { includeGroup("com.terraformersmc") } } - maven { - setUrl("https://maven.shedaniel.me/") - } - maven { - setUrl("https://maven.minecraftforge.net") - } - maven { - setUrl("https://maven.parchmentmc.org") - } - maven { + maven("https://maven.shedaniel.me/") + maven("https://maven.minecraftforge.net") + maven("https://maven.parchmentmc.org") + maven("https://maven.quiltmc.org/repository/release") { name = "Quilt" - setUrl("https://maven.quiltmc.org/repository/release") } flatDir { dirs("libs") } mavenCentral() + maven("https://jitpack.io") } dependencies { @@ -309,7 +297,7 @@ tasks { shadowJar { configurations = listOf(relocModApi) - isEnableRelocation = true + enableRelocation = true relocationPrefix = "net.frozenblock.lib.shadow" dependencies { exclude { diff --git a/gradle.properties b/gradle.properties index 96343251..cfb513f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ # Dependencies fabric_api_version=0.107.0+1.21.1 - fabric_kotlin_version=1.12.3+kotlin.2.0.21 + fabric_kotlin_version=1.13.0+kotlin.2.1.0 toml4j_version=0.7.2 jankson_version=1.2.3 xjs_data_version=0.6 @@ -29,6 +29,6 @@ fresult_version=3.1 # External Mods - modmenu_version=11.0.0-beta.1 - cloth_config_version=14.0.126 - terrablender_version=1.20.2-3.2.0.14 + modmenu_version=11.0.3 + cloth_config_version=15.0.140 + terrablender_version=1.21.1-4.1.0.3 From 08191a14cb008dad7138536e95bf840869c96024 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Sun, 22 Dec 2024 00:52:44 -0500 Subject: [PATCH 06/14] place in air item by qzimyion --- CHANGELOG.md | 2 + .../lib/item/api/PlaceInAirBlockItem.java | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 29dfa398..93854c99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,4 +5,6 @@ Make sure to clear this after each release Put changelog here: ----------------- +- Fixed custom Grass Color Modifiers to work 100% of the time. +- Added `PlaceInAirBlockItem,` thanks to Qzimyion! - Updated to Kotlin 2.1 diff --git a/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java b/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java new file mode 100644 index 00000000..b1e89c5a --- /dev/null +++ b/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java @@ -0,0 +1,47 @@ +package net.frozenblock.lib.item.api; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; + +public class PlaceInAirBlockItem extends BlockItem { + + public PlaceInAirBlockItem(Block block, Item.Properties properties) { + super(block, properties); + } + + @Override + @NotNull + public InteractionResultHolder use(@NotNull Level level, @NotNull Player player, InteractionHand hand) { + ItemStack itemStack = player.getItemInHand(hand); + + Vec3 lookAngle = player.getLookAngle(); + Vec3 placementPos = player.getEyePosition().add( + lookAngle.scale(player.getAttributeValue(Attributes.BLOCK_INTERACTION_RANGE)) + ); + BlockPos pos = BlockPos.containing(placementPos); + + if (level.isInWorldBounds(pos) && level.getWorldBorder().isWithinBounds(pos) && level.getBlockState(pos).canBeReplaced()) { + Direction reflectedFacingDirection = Direction.getNearest(lookAngle); + BlockPlaceContext context = new BlockPlaceContext(level, player, hand, itemStack, new BlockHitResult(pos.getCenter(), reflectedFacingDirection, pos, false)); + InteractionResult result = this.useOn(context); + if (result.consumesAction()) { + return InteractionResultHolder.sidedSuccess(itemStack, !level.isClientSide()); + } + } + return super.use(level, player, hand); + } +} From 47a54469f55a001d65e5bc378907b8688d06c3e6 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Sun, 22 Dec 2024 00:53:36 -0500 Subject: [PATCH 07/14] Update PlaceInAirBlockItem.java --- .../java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java b/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java index b1e89c5a..969c436e 100644 --- a/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java +++ b/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java @@ -36,7 +36,7 @@ public InteractionResultHolder use(@NotNull Level level, @NotNull Pla if (level.isInWorldBounds(pos) && level.getWorldBorder().isWithinBounds(pos) && level.getBlockState(pos).canBeReplaced()) { Direction reflectedFacingDirection = Direction.getNearest(lookAngle); - BlockPlaceContext context = new BlockPlaceContext(level, player, hand, itemStack, new BlockHitResult(pos.getCenter(), reflectedFacingDirection, pos, false)); + BlockPlaceContext context = new BlockPlaceContext(player, hand, itemStack, new BlockHitResult(pos.getCenter(), reflectedFacingDirection, pos, false)); InteractionResult result = this.useOn(context); if (result.consumesAction()) { return InteractionResultHolder.sidedSuccess(itemStack, !level.isClientSide()); From 30e2634fd27ae2a69b3ce8f19c9a278a7107c439 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop Date: Sun, 22 Dec 2024 05:57:23 +0000 Subject: [PATCH 08/14] Apply automatic changes --- .../lib/item/api/PlaceInAirBlockItem.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java b/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java index 969c436e..f60f9c05 100644 --- a/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java +++ b/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2024 FrozenBlock + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.frozenblock.lib.item.api; import net.minecraft.core.BlockPos; From cabcf66a50555f00786e6197ba8d919a15738b59 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Sun, 22 Dec 2024 01:53:02 -0500 Subject: [PATCH 09/14] Render block outlines if placeable in air --- .../item/mixin/client/LevelRendererMixin.java | 85 +++++++++++++++++++ .../mixin/frozenlib.item.mixins.json | 3 + 2 files changed, 88 insertions(+) create mode 100644 src/main/java/net/frozenblock/lib/item/mixin/client/LevelRendererMixin.java diff --git a/src/main/java/net/frozenblock/lib/item/mixin/client/LevelRendererMixin.java b/src/main/java/net/frozenblock/lib/item/mixin/client/LevelRendererMixin.java new file mode 100644 index 00000000..4669b8e0 --- /dev/null +++ b/src/main/java/net/frozenblock/lib/item/mixin/client/LevelRendererMixin.java @@ -0,0 +1,85 @@ +package net.frozenblock.lib.item.mixin.client; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.frozenblock.lib.item.api.PlaceInAirBlockItem; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; + +@Environment(EnvType.CLIENT) +@Mixin(LevelRenderer.class) +public abstract class LevelRendererMixin { + + @Shadow + @Final + private Minecraft minecraft; + + @ModifyExpressionValue( + method = "renderLevel", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/phys/HitResult;getType()Lnet/minecraft/world/phys/HitResult$Type;" + ) + ) + public HitResult.Type frozenLib$useBlockTypeIfPlaceableInAir( + HitResult.Type original, + @Share("frozenLib$canPlaceInAir") LocalBooleanRef canPlaceInAir + ) { + if (this.minecraft.player != null && original == HitResult.Type.MISS) { + if (this.minecraft.player.getMainHandItem().getItem() instanceof PlaceInAirBlockItem || this.minecraft.player.getOffhandItem().getItem() instanceof PlaceInAirBlockItem) { + canPlaceInAir.set(true); + return HitResult.Type.BLOCK; + } + } + + canPlaceInAir.set(false); + return original; + } + + @ModifyExpressionValue( + method = "renderLevel", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/block/state/BlockState;isAir()Z" + ) + ) + public boolean frozenLib$overrideAirCheck( + boolean original, + @Share("frozenLib$canPlaceInAir") LocalBooleanRef canPlaceInAir + ) { + return original && !canPlaceInAir.get(); + } + + @WrapOperation( + method = "renderHitOutline", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/LevelRenderer;renderShape(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/minecraft/world/phys/shapes/VoxelShape;DDDFFFF)V" + ) + ) + private void frozenLib$renderOutlineForAir( + PoseStack poseStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j, Operation original, + @Local(argsOnly = true) BlockState blockState + ) { + if (blockState.isAir()) voxelShape = Shapes.block(); + + original.call(poseStack, vertexConsumer, voxelShape, d, e, f, g, h, i, j); + } + +} diff --git a/src/main/resources/mixin/frozenlib.item.mixins.json b/src/main/resources/mixin/frozenlib.item.mixins.json index 96b8e581..67de19de 100644 --- a/src/main/resources/mixin/frozenlib.item.mixins.json +++ b/src/main/resources/mixin/frozenlib.item.mixins.json @@ -17,5 +17,8 @@ "bonemeal.BoneMealItemMixin", "sherd.DecoratedPotPatternsMixin", "shovel.ShovelItemMixin" + ], + "client": [ + "client.LevelRendererMixin" ] } From 767eda80e9d158101ca08b243d223de9ef3ad476 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop Date: Sun, 22 Dec 2024 06:56:55 +0000 Subject: [PATCH 10/14] Apply automatic changes --- .../item/mixin/client/LevelRendererMixin.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/net/frozenblock/lib/item/mixin/client/LevelRendererMixin.java b/src/main/java/net/frozenblock/lib/item/mixin/client/LevelRendererMixin.java index 4669b8e0..67d07b39 100644 --- a/src/main/java/net/frozenblock/lib/item/mixin/client/LevelRendererMixin.java +++ b/src/main/java/net/frozenblock/lib/item/mixin/client/LevelRendererMixin.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2024 FrozenBlock + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package net.frozenblock.lib.item.mixin.client; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; From 179b73b5d51f8691acc53423a5de91ab0ca2729c Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Sun, 22 Dec 2024 02:40:59 -0500 Subject: [PATCH 11/14] Don't place through entities --- .../lib/item/api/PlaceInAirBlockItem.java | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java b/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java index f60f9c05..dd433789 100644 --- a/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java +++ b/src/main/java/net/frozenblock/lib/item/api/PlaceInAirBlockItem.java @@ -19,18 +19,21 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; -import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; @@ -45,18 +48,34 @@ public PlaceInAirBlockItem(Block block, Item.Properties properties) { public InteractionResultHolder use(@NotNull Level level, @NotNull Player player, InteractionHand hand) { ItemStack itemStack = player.getItemInHand(hand); + double blockInteractionRange = player.blockInteractionRange(); + Vec3 lookAngle = player.getLookAngle(); - Vec3 placementPos = player.getEyePosition().add( - lookAngle.scale(player.getAttributeValue(Attributes.BLOCK_INTERACTION_RANGE)) + Vec3 playerPos = player.getEyePosition(); + Vec3 placementPos = playerPos.add( + lookAngle.scale(blockInteractionRange) + ); + + AABB entityPickBox = player.getBoundingBox().expandTowards(lookAngle.scale(blockInteractionRange)).inflate(1D, 1D, 1D); + EntityHitResult entityHitResult = ProjectileUtil.getEntityHitResult( + player, + playerPos, + placementPos, + entityPickBox, + entityx -> !entityx.isSpectator() && entityx.isPickable(), + Mth.square(blockInteractionRange) ); - BlockPos pos = BlockPos.containing(placementPos); - if (level.isInWorldBounds(pos) && level.getWorldBorder().isWithinBounds(pos) && level.getBlockState(pos).canBeReplaced()) { - Direction reflectedFacingDirection = Direction.getNearest(lookAngle); - BlockPlaceContext context = new BlockPlaceContext(player, hand, itemStack, new BlockHitResult(pos.getCenter(), reflectedFacingDirection, pos, false)); - InteractionResult result = this.useOn(context); - if (result.consumesAction()) { - return InteractionResultHolder.sidedSuccess(itemStack, !level.isClientSide()); + if (entityHitResult == null) { + BlockPos pos = BlockPos.containing(placementPos); + + if (level.isInWorldBounds(pos) && level.getWorldBorder().isWithinBounds(pos) && level.getBlockState(pos).canBeReplaced()) { + Direction reflectedFacingDirection = Direction.getNearest(lookAngle); + BlockPlaceContext context = new BlockPlaceContext(player, hand, itemStack, new BlockHitResult(pos.getCenter(), reflectedFacingDirection, pos, false)); + InteractionResult result = this.useOn(context); + if (result.consumesAction()) { + return InteractionResultHolder.sidedSuccess(itemStack, !level.isClientSide()); + } } } return super.use(level, player, hand); From 6a7bef107b66e6cf51e274bbe752ef61306a2004 Mon Sep 17 00:00:00 2001 From: Soro335 Date: Tue, 24 Dec 2024 02:24:45 +0300 Subject: [PATCH 12/14] Overworld gen part 2(sometimes its trash and needs to be fixed --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 94113f20..cea7a793 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From 6044fa9e4dd825ea148fdb2b413dc39d200a28fe Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Tue, 24 Dec 2024 18:07:29 -0500 Subject: [PATCH 13/14] based commit --- CHANGELOG.md | 1 + .../api/ShapedRecipeBuilderExtension.java | 1 - .../api/ShapelessRecipeBuilderExtension.java | 27 ++++++++ .../mixin/ShapedRecipeBuilderMixin.java | 26 -------- .../lib/recipe/mixin/ShapedRecipeMixin.java | 3 +- .../mixin/ShapelessRecipeBuilderMixin.java | 61 +++++++++++++++++++ .../recipe/mixin/ShapelessRecipeMixin.java | 42 +++++++++++++ .../mixin/frozenlib.recipe.mixins.json | 4 +- 8 files changed, 135 insertions(+), 30 deletions(-) create mode 100644 src/main/java/net/frozenblock/lib/recipe/api/ShapelessRecipeBuilderExtension.java create mode 100644 src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeBuilderMixin.java create mode 100644 src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeMixin.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 93854c99..5f7689bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,4 @@ Put changelog here: - Fixed custom Grass Color Modifiers to work 100% of the time. - Added `PlaceInAirBlockItem,` thanks to Qzimyion! - Updated to Kotlin 2.1 +- Added `ShapelessRecipeBuilderExtension` diff --git a/src/main/java/net/frozenblock/lib/recipe/api/ShapedRecipeBuilderExtension.java b/src/main/java/net/frozenblock/lib/recipe/api/ShapedRecipeBuilderExtension.java index df6f6778..e17f2b5f 100644 --- a/src/main/java/net/frozenblock/lib/recipe/api/ShapedRecipeBuilderExtension.java +++ b/src/main/java/net/frozenblock/lib/recipe/api/ShapedRecipeBuilderExtension.java @@ -22,6 +22,5 @@ import org.jetbrains.annotations.Nullable; public interface ShapedRecipeBuilderExtension { - ShapedRecipeBuilder frozenLib$patch(@Nullable DataComponentPatch tag); } diff --git a/src/main/java/net/frozenblock/lib/recipe/api/ShapelessRecipeBuilderExtension.java b/src/main/java/net/frozenblock/lib/recipe/api/ShapelessRecipeBuilderExtension.java new file mode 100644 index 00000000..e5de382b --- /dev/null +++ b/src/main/java/net/frozenblock/lib/recipe/api/ShapelessRecipeBuilderExtension.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 FrozenBlock + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.frozenblock.lib.recipe.api; + +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.data.recipes.ShapedRecipeBuilder; +import net.minecraft.data.recipes.ShapelessRecipeBuilder; +import org.jetbrains.annotations.Nullable; + +public interface ShapelessRecipeBuilderExtension { + ShapelessRecipeBuilder frozenLib$patch(@Nullable DataComponentPatch tag); +} diff --git a/src/main/java/net/frozenblock/lib/recipe/mixin/ShapedRecipeBuilderMixin.java b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapedRecipeBuilderMixin.java index c38bb45a..276e92df 100644 --- a/src/main/java/net/frozenblock/lib/recipe/mixin/ShapedRecipeBuilderMixin.java +++ b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapedRecipeBuilderMixin.java @@ -57,30 +57,4 @@ private void modifySave(RecipeOutput instance, ResourceLocation recipeId, Recipe ((ShapedRecipeBuilderExtension) recipe).frozenLib$patch(this.patch); operation.call(instance, recipeId, recipe, holder); } - - /*@Mixin(ShapedRecipeBuilder.Result.class) - private static class ResultMixin implements ShapedRecipeBuilderExtension { - - @Unique - @Nullable - private CompoundTag tag; - - @Override - public ShapedRecipeBuilder frozenLib$tag(CompoundTag tag) { - this.tag = tag; - return null; - } - - @Override - public @Nullable CompoundTag frozenLib$getTag() { - return this.tag; - } - - @Inject(method = "serializeRecipeData", at = @At(value = "INVOKE", target = "Lcom/google/gson/JsonObject;add(Ljava/lang/String;Lcom/google/gson/JsonElement;)V", ordinal = 3), locals = LocalCapture.CAPTURE_FAILHARD) - private void addTagData(JsonObject json, CallbackInfo ci, JsonArray jsonArray, JsonObject jsonObject, JsonObject jsonObject2) { - if (this.tag != null) { - jsonObject2.add("tag", CompoundTag.CODEC.encodeStart(JsonOps.INSTANCE, this.tag).getOrThrow(false, str -> {})); - } - } - }*/ } diff --git a/src/main/java/net/frozenblock/lib/recipe/mixin/ShapedRecipeMixin.java b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapedRecipeMixin.java index 7bfd19ae..f3ea8aa8 100644 --- a/src/main/java/net/frozenblock/lib/recipe/mixin/ShapedRecipeMixin.java +++ b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapedRecipeMixin.java @@ -36,8 +36,7 @@ public class ShapedRecipeMixin implements ShapedRecipeBuilderExtension { @Override public ShapedRecipeBuilder frozenLib$patch(@Nullable DataComponentPatch patch) { - if (patch != null) - this.result.applyComponents(patch); + if (patch != null) this.result.applyComponents(patch); return null; } } diff --git a/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeBuilderMixin.java b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeBuilderMixin.java new file mode 100644 index 00000000..6c155bc4 --- /dev/null +++ b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeBuilderMixin.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2024 FrozenBlock + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.frozenblock.lib.recipe.mixin; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.frozenblock.lib.recipe.api.ShapedRecipeBuilderExtension; +import net.frozenblock.lib.recipe.api.ShapelessRecipeBuilderExtension; +import net.minecraft.advancements.AdvancementHolder; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.data.recipes.RecipeOutput; +import net.minecraft.data.recipes.ShapelessRecipeBuilder; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.ShapedRecipe; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ShapelessRecipeBuilder.class) +public class ShapelessRecipeBuilderMixin implements ShapelessRecipeBuilderExtension { + + @Unique + @Nullable + private DataComponentPatch patch; + + @Unique + @Override + public ShapelessRecipeBuilder frozenLib$patch(@Nullable DataComponentPatch patch) { + this.patch = patch; + return (ShapelessRecipeBuilder) (Object) this; + } + + @WrapOperation( + method = "save", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/data/recipes/RecipeOutput;accept(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/world/item/crafting/Recipe;Lnet/minecraft/advancements/AdvancementHolder;)V" + ) + ) + private void modifySave(RecipeOutput instance, ResourceLocation recipeId, Recipe recipe, AdvancementHolder holder, Operation operation) { + ((ShapedRecipeBuilderExtension) recipe).frozenLib$patch(this.patch); + operation.call(instance, recipeId, recipe, holder); + } +} diff --git a/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeMixin.java b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeMixin.java new file mode 100644 index 00000000..b8b72cf1 --- /dev/null +++ b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeMixin.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 FrozenBlock + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.frozenblock.lib.recipe.mixin; + +import net.frozenblock.lib.recipe.api.ShapelessRecipeBuilderExtension; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.data.recipes.ShapelessRecipeBuilder; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.ShapelessRecipe; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(ShapelessRecipe.class) +public class ShapelessRecipeMixin implements ShapelessRecipeBuilderExtension { + + @Shadow + @Final + ItemStack result; + + @Override + public ShapelessRecipeBuilder frozenLib$patch(@Nullable DataComponentPatch patch) { + if (patch != null) this.result.applyComponents(patch); + return null; + } +} diff --git a/src/main/resources/mixin/frozenlib.recipe.mixins.json b/src/main/resources/mixin/frozenlib.recipe.mixins.json index 6ae2d10a..ddcd47fb 100644 --- a/src/main/resources/mixin/frozenlib.recipe.mixins.json +++ b/src/main/resources/mixin/frozenlib.recipe.mixins.json @@ -9,6 +9,8 @@ "mixins": [ "ItemValueMixin", "ShapedRecipeBuilderMixin", - "ShapedRecipeMixin" + "ShapedRecipeMixin", + "ShapelessRecipeBuilderMixin", + "ShapelessRecipeMixin" ] } From 9df20ebca69ddf891900536d392417092afdfee3 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Tue, 24 Dec 2024 18:11:23 -0500 Subject: [PATCH 14/14] Update ShapelessRecipeBuilderMixin.java --- .../lib/recipe/mixin/ShapelessRecipeBuilderMixin.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeBuilderMixin.java b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeBuilderMixin.java index 6c155bc4..d360c5fe 100644 --- a/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeBuilderMixin.java +++ b/src/main/java/net/frozenblock/lib/recipe/mixin/ShapelessRecipeBuilderMixin.java @@ -19,7 +19,6 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import net.frozenblock.lib.recipe.api.ShapedRecipeBuilderExtension; import net.frozenblock.lib.recipe.api.ShapelessRecipeBuilderExtension; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.core.component.DataComponentPatch; @@ -55,7 +54,7 @@ public class ShapelessRecipeBuilderMixin implements ShapelessRecipeBuilderExtens ) ) private void modifySave(RecipeOutput instance, ResourceLocation recipeId, Recipe recipe, AdvancementHolder holder, Operation operation) { - ((ShapedRecipeBuilderExtension) recipe).frozenLib$patch(this.patch); + ((ShapelessRecipeBuilderExtension) recipe).frozenLib$patch(this.patch); operation.call(instance, recipeId, recipe, holder); } }