Skip to content

Commit

Permalink
Add support for merging same effect durations
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiahwinsley committed Apr 21, 2022
1 parent 0603572 commit 1e76f0f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -190,3 +190,7 @@ publishing {
}
}
}

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 40 additions & 0 deletions src/main/java/net/permutated/pylons/item/PotionFilterCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ public InteractionResultHolder<ItemStack> 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<MobEffectInstance> active;
if (effect == null) {
active = player.getActiveEffects().stream()
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1e76f0f

Please sign in to comment.