Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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}"}
}
}
25 changes: 12 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> 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<ItemStack> 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;
Expand All @@ -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;
Expand Down
35 changes: 26 additions & 9 deletions src/main/java/cursedflames/stackablepotions/mixin/ItemsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@

@Mixin(Items.class)
public abstract class ItemsMixin {
@ModifyArg(method = "<clinit>",
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 = "<clinit>",
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 = "<clinit>",
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 = "<clinit>",
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 = "<clinit>",
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 = "<clinit>",
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypedActionResult<ItemStack>> info) {
@Inject(method = "use", at = @At("RETURN"))
private void onUse(
World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> info)
{
// Add a cooldown so that splash damage/health doesn't become absurdly overpowered when stackable
user.getItemCooldownManager().set(this, 20);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"stackablepotions.mixins.json"
],
"depends": {
"fabricloader": ">=0.7.4",
"minecraft": "1.17.x"
"fabricloader": "*",
"minecraft": "~1.20"
}
}
2 changes: 1 addition & 1 deletion src/main/resources/stackablepotions.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "cursedflames.stackablepotions.mixin",
"compatibilityLevel": "JAVA_16",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ItemsMixin",
"ThrowablePotionItemMixin",
Expand Down