From 5b1ed89d9cb935631f5ff7c6cb20c85334a1fbc6 Mon Sep 17 00:00:00 2001 From: Majrusz Date: Fri, 26 Apr 2024 23:26:10 +0200 Subject: [PATCH 1/5] Updated version name --- changelog.md | 5 ----- gradle.properties | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index a5298b6d..e69de29b 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +0,0 @@ -- 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 diff --git a/gradle.properties b/gradle.properties index 7fcb4612..e65f5521 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-unfinished mod_display_name=Majrusz Library mod_description=Library with common code for my other modifications. mod_authors=Majrusz From 14aae394b38f69032c9e74a4f3b7c46c03eb7a27 Mon Sep 17 00:00:00 2001 From: Majrusz Date: Fri, 26 Apr 2024 23:27:34 +0200 Subject: [PATCH 2/5] Added missing compatibility with Aquaculture 2 for NeoForge (reported by @LilChromie) --- changelog.md | 1 + .../events/OnItemFishedNeoForge.java | 17 +++++++++ .../mixin/neoforge/MixinFishingHook.java | 35 ------------------- .../majruszlibrary-neoforge.mixins.json | 1 - 4 files changed, 18 insertions(+), 36 deletions(-) create mode 100644 neoforge/src/main/java/com/majruszlibrary/events/OnItemFishedNeoForge.java delete mode 100644 neoforge/src/main/java/com/majruszlibrary/mixin/neoforge/MixinFishingHook.java diff --git a/changelog.md b/changelog.md index e69de29b..0832cd00 100644 --- a/changelog.md +++ b/changelog.md @@ -0,0 +1 @@ +- added missing compatibility with Aquaculture 2 for NeoForge (reported by @LilChromie) \ No newline at end of file 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/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..ea7d4781 100644 --- a/neoforge/src/main/resources/majruszlibrary-neoforge.mixins.json +++ b/neoforge/src/main/resources/majruszlibrary-neoforge.mixins.json @@ -9,7 +9,6 @@ ], "mixins": [ "MixinEnchantment", - "MixinFishingHook", "MixinLootTable" ], "injectors": { From 72f97cca73b0e3f1866d7f45f022a7ff5e0d73ec Mon Sep 17 00:00:00 2001 From: Majrusz Date: Sat, 27 Apr 2024 09:29:52 +0200 Subject: [PATCH 3/5] Fixed random server crash `Accessing LegacyRandomSource from multiple threads` (reported by @AVeryLittleGhost) --- changelog.md | 3 ++- common/src/main/java/com/majruszlibrary/math/Random.java | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 0832cd00..a33bb1fd 100644 --- a/changelog.md +++ b/changelog.md @@ -1 +1,2 @@ -- added missing compatibility with Aquaculture 2 for NeoForge (reported by @LilChromie) \ No newline at end of file +- added missing compatibility with Aquaculture 2 for NeoForge (reported by @LilChromie) +- fixed random server crash `Accessing LegacyRandomSource from multiple threads` (reported by @AVeryLittleGhost) \ 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() { From 80206e17bc89dbb6564f7b46da5d084c51c5fc9c Mon Sep 17 00:00:00 2001 From: Majrusz Date: Sat, 27 Apr 2024 18:59:15 +0200 Subject: [PATCH 4/5] Added missing compatibility for Aquaculture 2 (reported by @LilChromie) --- changelog.md | 3 +- .../mixin/MixinFishingHook.java | 2 +- forge/build.gradle | 1 + .../forge/MixinAquaFishingBobberEntity.java | 29 +++++++++++++++++++ .../majruszlibrary-forge.mixins.json | 1 + neoforge/build.gradle | 1 + .../MixinAquaFishingBobberEntity.java | 29 +++++++++++++++++++ .../majruszlibrary-neoforge.mixins.json | 1 + 8 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 forge/src/main/java/com/majruszlibrary/mixin/forge/MixinAquaFishingBobberEntity.java create mode 100644 neoforge/src/main/java/com/majruszlibrary/mixin/neoforge/MixinAquaFishingBobberEntity.java diff --git a/changelog.md b/changelog.md index a33bb1fd..4a725dd1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,2 +1,3 @@ -- added missing compatibility with Aquaculture 2 for NeoForge (reported by @LilChromie) +- 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) \ No newline at end of file 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/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/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/resources/majruszlibrary-neoforge.mixins.json b/neoforge/src/main/resources/majruszlibrary-neoforge.mixins.json index ea7d4781..96c0481e 100644 --- a/neoforge/src/main/resources/majruszlibrary-neoforge.mixins.json +++ b/neoforge/src/main/resources/majruszlibrary-neoforge.mixins.json @@ -8,6 +8,7 @@ "MixinAbstractContainerScreen" ], "mixins": [ + "MixinAquaFishingBobberEntity", "MixinEnchantment", "MixinLootTable" ], From 2cb7264d74c12893ed024abc6ebf8e525c0852ce Mon Sep 17 00:00:00 2001 From: Majrusz Date: Sat, 27 Apr 2024 19:02:43 +0200 Subject: [PATCH 5/5] Updated changelog --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 4a725dd1..8176ff29 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,3 @@ - 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) \ No newline at end of file +- fixed random server crash `Accessing LegacyRandomSource from multiple threads` (reported by @AVeryLittleGhost, @memphismc) \ No newline at end of file