diff --git a/build.gradle b/build.gradle index ac4e618..683c5b3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ plugins { - id 'fabric-loom' version '0.8-SNAPSHOT' + id 'fabric-loom' version '1.2-SNAPSHOT' } -sourceCompatibility = JavaVersion.VERSION_16 -targetCompatibility = JavaVersion.VERSION_16 - -archivesBaseName = project.archives_base_name -version = project.mod_version +version = "${project.mod_version}+${project.minecraft_version}" group = project.maven_group +base { + archivesName = project.archives_base_name +} + dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -30,22 +30,23 @@ processResources { } } -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" +tasks.withType(JavaCompile).configureEach { + // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. + it.options.release = 17 } -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -java{ +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}" } + rename { "${it}_${archivesBaseName}"} } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 0783cad..25878b6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,16 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx1G +org.gradle.jvmargs = -Xmx1G +org.gradle.parallel = true -# Fabric Properties - # check these on https://fabricmc.net/use - minecraft_version=1.17 - yarn_mappings=1.17+build.5 - loader_version=0.11.3 +# Fabric properties +# check these on https://fabricmc.net/versions.html +minecraft_version = 1.20.1 +yarn_mappings = 1.20.1+build.2 +loader_version = 0.14.21 -# Mod Properties - mod_version = 1.0.0 - maven_group = cursedflames.stackablepotions - archives_base_name = Stackable Potions-FABRIC-1.17.x +# Mod properties +mod_name = Stackable Potions +mod_version = 1.7.8 +maven_group = cursedflames.stackablepotions +archives_base_name = stackablepotions -# Dependencies - # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.13.1+build.370-1.16 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f80bbf..59bc51a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/cursedflames/stackablepotions/mixin/BrewingStandScreenHandlerMixin.java b/src/main/java/cursedflames/stackablepotions/mixin/BrewingStandScreenHandlerMixin.java index a09e2b3..87458ee 100644 --- a/src/main/java/cursedflames/stackablepotions/mixin/BrewingStandScreenHandlerMixin.java +++ b/src/main/java/cursedflames/stackablepotions/mixin/BrewingStandScreenHandlerMixin.java @@ -22,13 +22,16 @@ private BrewingStandScreenHandlerMixin(ScreenHandlerType type, int syncId) { super(type, syncId); } - @Inject(method = "transferSlot", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/screen/BrewingStandScreenHandler$PotionSlot;matches(Lnet/minecraft/item/ItemStack;)Z"), - locals = LocalCapture.CAPTURE_FAILSOFT, - cancellable = true) - private void onTransferSlot(PlayerEntity player, int index, CallbackInfoReturnable info, - ItemStack itemStack, Slot slot, ItemStack itemStack2) { + @Inject(method = "quickMove", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/screen/BrewingStandScreenHandler$PotionSlot;matches(Lnet/minecraft/item/ItemStack;)Z"), + locals = LocalCapture.CAPTURE_FAILSOFT, + cancellable = true) + private void onTransferSlot( + PlayerEntity player, int slotIndex, CallbackInfoReturnable cir, ItemStack itemStack, Slot slot, + ItemStack itemStack2) + { // Replace vanilla shift-click behavior for potions with our own, to prevent getting more than one in a slot if (slot.canInsert(itemStack)) { boolean movedItems = false; @@ -49,17 +52,19 @@ private void onTransferSlot(PlayerEntity player, int index, CallbackInfoReturnab } // returned value sets current slot if (movedItems) { - info.setReturnValue(ItemStack.EMPTY); + cir.setReturnValue(ItemStack.EMPTY); } } } - @Redirect(method = "transferSlot", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/screen/BrewingStandScreenHandler$PotionSlot;matches(Lnet/minecraft/item/ItemStack;)Z")) + @Redirect( + method = "quickMove", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/screen/BrewingStandScreenHandler$PotionSlot;matches(Lnet/minecraft/item/ItemStack;)Z")) private boolean onTransferSlotRedirect(ItemStack stack, PlayerEntity player, int index) { - // Block the default shift-clicking into potion slots so we can do it ourselves. - // Unfortunately because we're cancelling the vanilla `if`, the else ifs run, meaning the player can + // Block the default shift-clicking into potion slots, so we can do it ourselves. + // Unfortunately, because we're cancelling the vanilla `if`, the else ifs run, meaning the player can // shift-click into potion slots with more than 3 potions and the rest of the stack will also get moved around // kinda annoying but whatever, don't know of a clean solution for it. return false; diff --git a/src/main/java/cursedflames/stackablepotions/mixin/ItemsMixin.java b/src/main/java/cursedflames/stackablepotions/mixin/ItemsMixin.java index 5e393d2..2c78ca8 100644 --- a/src/main/java/cursedflames/stackablepotions/mixin/ItemsMixin.java +++ b/src/main/java/cursedflames/stackablepotions/mixin/ItemsMixin.java @@ -8,21 +8,38 @@ @Mixin(Items.class) public abstract class ItemsMixin { - @ModifyArg(method = "", - at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item$Settings;maxCount(I)Lnet/minecraft/item/Item$Settings;", ordinal = 0), - slice = @Slice( from = @At(value = "NEW", target = "Lnet/minecraft/item/PotionItem;"))) + @ModifyArg( + method = "", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/item/Item$Settings;maxCount(I)Lnet/minecraft/item/Item$Settings;", + ordinal = 0), + slice = @Slice( + from = @At(value = "NEW", target = "Lnet/minecraft/item/PotionItem;"))) private static int onPotion(int old) { return 16; } - @ModifyArg(method = "", - at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item$Settings;maxCount(I)Lnet/minecraft/item/Item$Settings;", ordinal = 0), - slice = @Slice( from = @At(value = "NEW", target = "Lnet/minecraft/item/SplashPotionItem;"))) + + @ModifyArg( + method = "", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/item/Item$Settings;maxCount(I)Lnet/minecraft/item/Item$Settings;", + ordinal = 0), + slice = @Slice( + from = @At(value = "NEW", target = "Lnet/minecraft/item/SplashPotionItem;"))) private static int onSplashPotion(int old) { return 16; } - @ModifyArg(method = "", - at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item$Settings;maxCount(I)Lnet/minecraft/item/Item$Settings;", ordinal = 0), - slice = @Slice( from = @At(value = "NEW", target = "Lnet/minecraft/item/LingeringPotionItem;"))) + + @ModifyArg( + method = "", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/item/Item$Settings;maxCount(I)Lnet/minecraft/item/Item$Settings;", + ordinal = 0), + slice = @Slice( + from = @At(value = "NEW", target = "Lnet/minecraft/item/LingeringPotionItem;"))) private static int onLingeringPotion(int old) { return 16; } diff --git a/src/main/java/cursedflames/stackablepotions/mixin/PotionItemMixin.java b/src/main/java/cursedflames/stackablepotions/mixin/PotionItemMixin.java index 84e8a6a..16c26b4 100644 --- a/src/main/java/cursedflames/stackablepotions/mixin/PotionItemMixin.java +++ b/src/main/java/cursedflames/stackablepotions/mixin/PotionItemMixin.java @@ -13,10 +13,16 @@ @Mixin(PotionItem.class) public abstract class PotionItemMixin { - @Inject(method = "finishUsing(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;)Lnet/minecraft/item/ItemStack;", cancellable = true, - at = @At(value = "INVOKE",target = "Lnet/minecraft/entity/player/PlayerInventory;insertStack(Lnet/minecraft/item/ItemStack;)Z", shift = At.Shift.BEFORE)) + @Inject( + method = "finishUsing", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/player/PlayerInventory;insertStack(Lnet/minecraft/item/ItemStack;)Z", + shift = At.Shift.BEFORE), + cancellable = true) public void finishUsing(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable cir) { - if (user instanceof PlayerEntity) ((PlayerEntity)user).getInventory().offerOrDrop(Items.GLASS_BOTTLE.getDefaultStack()); + if (user instanceof PlayerEntity) + ((PlayerEntity) user).getInventory().offerOrDrop(Items.GLASS_BOTTLE.getDefaultStack()); cir.setReturnValue(stack); } } diff --git a/src/main/java/cursedflames/stackablepotions/mixin/ThrowablePotionItemMixin.java b/src/main/java/cursedflames/stackablepotions/mixin/ThrowablePotionItemMixin.java index 074fffd..4aaeb7d 100644 --- a/src/main/java/cursedflames/stackablepotions/mixin/ThrowablePotionItemMixin.java +++ b/src/main/java/cursedflames/stackablepotions/mixin/ThrowablePotionItemMixin.java @@ -19,9 +19,10 @@ private ThrowablePotionItemMixin(Settings settings) { super(settings); } - @Inject(method="use", at=@At("RETURN")) - private void onUse(World world, PlayerEntity user, Hand hand, - CallbackInfoReturnable> info) { + @Inject(method = "use", at = @At("RETURN")) + private void onUse( + World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> info) + { // Add a cooldown so that splash damage/health doesn't become absurdly overpowered when stackable user.getItemCooldownManager().set(this, 20); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4aa33eb..94b4915 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -23,7 +23,7 @@ "stackablepotions.mixins.json" ], "depends": { - "fabricloader": ">=0.7.4", - "minecraft": "1.17.x" + "fabricloader": "*", + "minecraft": "~1.20" } } diff --git a/src/main/resources/stackablepotions.mixins.json b/src/main/resources/stackablepotions.mixins.json index ae501b0..c0b76d8 100644 --- a/src/main/resources/stackablepotions.mixins.json +++ b/src/main/resources/stackablepotions.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "cursedflames.stackablepotions.mixin", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_17", "mixins": [ "ItemsMixin", "ThrowablePotionItemMixin",