diff --git a/changelog.md b/changelog.md index a5298b6d..8176ff29 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,3 @@ -- added compatibility with Aquaculture 2 for fishing related features (reported by @JinKhya, @Ladocterus) -- added compatibility with MC Dungeons Weapons for damage related features (reported by @mochalit) -- fixed crash `Accessing LegacyRandomSource from multiple threads` (reported by @Luigi delle Bicocche, @davey) -- fixed compatibility crash `java.lang.IndexOutOfBoundsException` (reported by @GermanArtur, @memphismc) -- fixed long game loading time when GitHub cannot be accessed without proxy (reported by @SettingDust) \ No newline at end of file +- added missing compatibility for Aquaculture 2 (reported by @LilChromie) +- added Aquaculture 2 compatibility for NeoForge (reported by @LilChromie) +- fixed random server crash `Accessing LegacyRandomSource from multiple threads` (reported by @AVeryLittleGhost, @memphismc) \ No newline at end of file diff --git a/common/src/main/java/com/majruszlibrary/math/Random.java b/common/src/main/java/com/majruszlibrary/math/Random.java index e68f7f66..a4dddb66 100644 --- a/common/src/main/java/com/majruszlibrary/math/Random.java +++ b/common/src/main/java/com/majruszlibrary/math/Random.java @@ -11,6 +11,7 @@ import java.util.stream.IntStream; public class Random { + static final RandomSource LOGICAL_CLIENT = RandomSource.create(); static final RandomSource CLIENT = RandomSource.create(); static final RandomSource SERVER = RandomSource.create(); @@ -19,7 +20,13 @@ public class Random { thread safe and can be accessed on both server and client at the same time. */ public static RandomSource getThreadSafe() { - return Side.isClient() ? CLIENT : SERVER; + if( Side.isLogicalClient() ) { + return LOGICAL_CLIENT; + } else if( Side.isClient() ) { + return CLIENT; + } else { + return SERVER; + } } public static float nextFloat() { diff --git a/common/src/main/java/com/majruszlibrary/mixin/MixinFishingHook.java b/common/src/main/java/com/majruszlibrary/mixin/MixinFishingHook.java index af9bce90..3ca3242a 100644 --- a/common/src/main/java/com/majruszlibrary/mixin/MixinFishingHook.java +++ b/common/src/main/java/com/majruszlibrary/mixin/MixinFishingHook.java @@ -10,7 +10,7 @@ @Mixin( FishingHook.class ) public abstract class MixinFishingHook { - private @Shadow int timeUntilLured; + protected @Shadow int timeUntilLured; @Redirect( at = @At( diff --git a/forge/build.gradle b/forge/build.gradle index f8973e25..ee27830d 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -94,6 +94,7 @@ java { dependencies { minecraft "net.minecraftforge:forge:${forge_version}" compileOnly project(':common') + implementation fg.deobf('curse.maven:aquaculture-60028:4608454') annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' } diff --git a/forge/src/main/java/com/majruszlibrary/mixin/forge/MixinAquaFishingBobberEntity.java b/forge/src/main/java/com/majruszlibrary/mixin/forge/MixinAquaFishingBobberEntity.java new file mode 100644 index 00000000..5c4968f4 --- /dev/null +++ b/forge/src/main/java/com/majruszlibrary/mixin/forge/MixinAquaFishingBobberEntity.java @@ -0,0 +1,29 @@ +package com.majruszlibrary.mixin.forge; + +import com.majruszlibrary.events.OnFishingTimeGet; +import com.majruszlibrary.events.base.Events; +import com.majruszlibrary.mixin.MixinFishingHook; +import com.teammetallurgy.aquaculture.entity.AquaFishingBobberEntity; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Pseudo +@Mixin( targets = "com.teammetallurgy.aquaculture.entity.AquaFishingBobberEntity" ) +public abstract class MixinAquaFishingBobberEntity extends MixinFishingHook { + @Dynamic( "Aquaculture 2 compatibility" ) + @Redirect( + at = @At( + opcode = 181, // putfield + ordinal = 3, + target = "Lcom/teammetallurgy/aquaculture/entity/AquaFishingBobberEntity;timeUntilLured:I", + value = "FIELD" + ), + method = "catchingFish (Lnet/minecraft/core/BlockPos;)V" + ) + private void catchingFish( AquaFishingBobberEntity hook, int timeUntilLured ) { + this.timeUntilLured = Events.dispatch( new OnFishingTimeGet( hook, timeUntilLured ) ).getTicks(); + } +} diff --git a/forge/src/main/resources/majruszlibrary-forge.mixins.json b/forge/src/main/resources/majruszlibrary-forge.mixins.json index bb89032f..c7d0057d 100644 --- a/forge/src/main/resources/majruszlibrary-forge.mixins.json +++ b/forge/src/main/resources/majruszlibrary-forge.mixins.json @@ -8,6 +8,7 @@ "MixinAbstractContainerScreen" ], "mixins": [ + "MixinAquaFishingBobberEntity", "MixinEnchantment", "MixinLootTable" ], diff --git a/gradle.properties b/gradle.properties index 7fcb4612..426a9632 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ minecraft_version=1.20.1 # Mod mod_id=majruszlibrary mod_archives_name=majrusz-library -mod_version=7.0.6 +mod_version=7.0.7 mod_display_name=Majrusz Library mod_description=Library with common code for my other modifications. mod_authors=Majrusz diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 83de499e..385563cc 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -94,6 +94,7 @@ java { dependencies { minecraft "net.neoforged:forge:${neoforge_version}" compileOnly project(':common') + implementation fg.deobf('curse.maven:aquaculture-60028:4921323') annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' } diff --git a/neoforge/src/main/java/com/majruszlibrary/events/OnItemFishedNeoForge.java b/neoforge/src/main/java/com/majruszlibrary/events/OnItemFishedNeoForge.java new file mode 100644 index 00000000..60e4458b --- /dev/null +++ b/neoforge/src/main/java/com/majruszlibrary/events/OnItemFishedNeoForge.java @@ -0,0 +1,17 @@ +package com.majruszlibrary.events; + +import com.majruszlibrary.events.base.Events; +import net.minecraft.world.entity.player.Player; +import net.minecraftforge.event.entity.player.ItemFishedEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +@Mod.EventBusSubscriber +public class OnItemFishedNeoForge { + @SubscribeEvent + public static void onItemFished( ItemFishedEvent event ) { + Player player = event.getEntity(); + + Events.dispatch( new OnItemFished( player, event.getHookEntity(), player.getItemInHand( player.getUsedItemHand() ), event.getDrops() ) ); + } +} diff --git a/neoforge/src/main/java/com/majruszlibrary/mixin/neoforge/MixinAquaFishingBobberEntity.java b/neoforge/src/main/java/com/majruszlibrary/mixin/neoforge/MixinAquaFishingBobberEntity.java new file mode 100644 index 00000000..1ed20545 --- /dev/null +++ b/neoforge/src/main/java/com/majruszlibrary/mixin/neoforge/MixinAquaFishingBobberEntity.java @@ -0,0 +1,29 @@ +package com.majruszlibrary.mixin.neoforge; + +import com.majruszlibrary.events.OnFishingTimeGet; +import com.majruszlibrary.events.base.Events; +import com.majruszlibrary.mixin.MixinFishingHook; +import com.teammetallurgy.aquaculture.entity.AquaFishingBobberEntity; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Pseudo +@Mixin( targets = "com.teammetallurgy.aquaculture.entity.AquaFishingBobberEntity" ) +public abstract class MixinAquaFishingBobberEntity extends MixinFishingHook { + @Dynamic( "Aquaculture 2 compatibility" ) + @Redirect( + at = @At( + opcode = 181, // putfield + ordinal = 3, + target = "Lcom/teammetallurgy/aquaculture/entity/AquaFishingBobberEntity;timeUntilLured:I", + value = "FIELD" + ), + method = "catchingFish (Lnet/minecraft/core/BlockPos;)V" + ) + private void catchingFish( AquaFishingBobberEntity hook, int timeUntilLured ) { + this.timeUntilLured = Events.dispatch( new OnFishingTimeGet( hook, timeUntilLured ) ).getTicks(); + } +} diff --git a/neoforge/src/main/java/com/majruszlibrary/mixin/neoforge/MixinFishingHook.java b/neoforge/src/main/java/com/majruszlibrary/mixin/neoforge/MixinFishingHook.java deleted file mode 100644 index ae956002..00000000 --- a/neoforge/src/main/java/com/majruszlibrary/mixin/neoforge/MixinFishingHook.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.majruszlibrary.mixin.neoforge; - -import com.majruszlibrary.events.OnItemFished; -import com.majruszlibrary.events.base.Events; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.FishingHook; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootParams; -import net.minecraft.world.level.storage.loot.LootTable; -import net.minecraftforge.event.entity.player.ItemFishedEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.List; - -@Mixin( FishingHook.class ) -public abstract class MixinFishingHook { - @Inject( - at = @At( - ordinal = 1, - target = "Lnet/minecraft/advancements/critereon/FishingRodHookedTrigger;trigger (Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/projectile/FishingHook;Ljava/util/Collection;)V", - value = "INVOKE" - ), - locals = LocalCapture.CAPTURE_FAILHARD, - method = "retrieve (Lnet/minecraft/world/item/ItemStack;)I" - ) - private void retrieve( ItemStack itemStack, CallbackInfoReturnable< Integer > callback, Player player, int damage, ItemFishedEvent event, - LootParams lootParams, LootTable lootTable, List< ItemStack > items - ) { - Events.dispatch( new OnItemFished( player, ( FishingHook )( Object )this, itemStack, items ) ); - } -} diff --git a/neoforge/src/main/resources/majruszlibrary-neoforge.mixins.json b/neoforge/src/main/resources/majruszlibrary-neoforge.mixins.json index a9a2bade..96c0481e 100644 --- a/neoforge/src/main/resources/majruszlibrary-neoforge.mixins.json +++ b/neoforge/src/main/resources/majruszlibrary-neoforge.mixins.json @@ -8,8 +8,8 @@ "MixinAbstractContainerScreen" ], "mixins": [ + "MixinAquaFishingBobberEntity", "MixinEnchantment", - "MixinFishingHook", "MixinLootTable" ], "injectors": {