diff --git a/build.gradle b/build.gradle index 962e5c2..d89bab0 100644 --- a/build.gradle +++ b/build.gradle @@ -146,7 +146,7 @@ dependencies { // Specify the version of Minecraft to use. If this is any group other than 'net.minecraft', it is assumed // that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. - minecraft 'net.minecraftforge:forge:1.18.2-40.0.2' + minecraft 'net.minecraftforge:forge:1.18.2-40.1.0' runtimeOnly fg.deobf("curse.maven:jei-238222:3670018") // runtimeOnly fg.deobf("curse.maven:top-245211:3586969") @@ -190,3 +190,7 @@ publishing { } } } + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation +} diff --git a/gradle.properties b/gradle.properties index f8924f7..a24fd66 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ org.gradle.daemon=false mc_version=1.18.2 group=net.permutated mod_id=pylons -version=2.0.8 +version=2.0.9 diff --git a/src/main/java/net/permutated/pylons/item/PotionFilterCard.java b/src/main/java/net/permutated/pylons/item/PotionFilterCard.java index 4125e12..c6b97b4 100644 --- a/src/main/java/net/permutated/pylons/item/PotionFilterCard.java +++ b/src/main/java/net/permutated/pylons/item/PotionFilterCard.java @@ -63,6 +63,35 @@ public InteractionResultHolder use(Level level, Player player, Intera return InteractionResultHolder.success(stack); } + // handle transferring effects between cards + if (hand == InteractionHand.MAIN_HAND) { // this should only run for cards held in the main hand + final ItemStack offhand = player.getItemInHand(InteractionHand.OFF_HAND); + if (offhand.getItem() instanceof PotionFilterCard) { // offhand is holding a potion filter card + MobEffect offhandEffect = PotionFilterCard.getEffect(offhand); + int offhandAmplifier = PotionFilterCard.getAmplifier(offhand); + int offhandDuration = PotionFilterCard.getDuration(offhand); + if (offhandEffect != null) { // offhand card has an effect + ItemStack copy; + if (effect == null) { + // main hand card is blank + // move effect from off hand card to main hand card + copy = withEffect(stack, offhandEffect, offhandAmplifier, offhandDuration); + // clear potion data from offhand card + player.setItemInHand(InteractionHand.OFF_HAND, clearEffect(offhand)); + return InteractionResultHolder.success(copy); + } else if(Objects.equals(effect, offhandEffect) && Objects.equals(amplifier, offhandAmplifier)) { + // main hand card has the same effect and amplifier + // merge effect from off hand card with main hand card + copy = addDuration(stack, offhandDuration); + // clear potion data from offhand card + player.setItemInHand(InteractionHand.OFF_HAND, clearEffect(offhand)); + return InteractionResultHolder.success(copy); + } + } + } + } + + Optional active; if (effect == null) { active = player.getActiveEffects().stream() @@ -213,6 +242,17 @@ public static ItemStack addDuration(final ItemStack stack, int duration) { return copy; } + /** + * Remove Pylons NBT from a potion filter card. + * @param stack the ItemStack containing NBT + * @return a copy of the ItemStack without the pylons tag + */ + public static ItemStack clearEffect(final ItemStack stack) { + ItemStack copy = stack.copy(); + copy.removeTagKey(Pylons.MODID); + return copy; + } + @Nullable public static MobEffect getEffect(ItemStack stack) { CompoundTag tag = stack.getTagElement(Pylons.MODID);