11package io .github .pylonmc .pylon .base .content .magic ;
22
33import com .destroystokyo .paper .ParticleBuilder ;
4- import io .github .pylonmc .pylon .base .BaseConfig ;
54import io .github .pylonmc .pylon .base .content .magic .base .Rune ;
5+ import io .github .pylonmc .pylon .core .item .builder .ItemStackBuilder ;
66import io .papermc .paper .datacomponent .DataComponentTypes ;
77import io .papermc .paper .datacomponent .item .DamageResistant ;
88import io .papermc .paper .registry .keys .tags .DamageTypeTagKeys ;
99import net .kyori .adventure .text .Component ;
10- import org . bukkit . FluidCollisionMode ;
10+ import net . kyori . adventure . translation . GlobalTranslator ;
1111import org .bukkit .Location ;
1212import org .bukkit .Particle ;
1313import org .bukkit .Sound ;
2020/**
2121 * @author balugaq
2222 */
23- @ SuppressWarnings ("UnstableApiUsage" )
2423public class FireproofRune extends Rune {
2524 public static final Component SUCCESS = Component .translatable ("pylon.pylonbase.message.fireproof_result.success" );
25+ public static final Component TOOLTIP = Component .translatable ("pylon.pylonbase.message.fireproof_result.tooltip" );
26+
2627
2728 public FireproofRune (@ NotNull ItemStack stack ) {
2829 super (stack );
2930 }
3031
32+ /**
33+ * Fixes #156 - Fireproof rune can be applied multiple times
34+ * <p>
35+ * Checks if the rune is applicable to the target item.
36+ *
37+ * @param event The event
38+ * @param rune The rune item, amount may be > 1
39+ * @param target The item to handle, amount may be > 1
40+ * @return true if applicable, false otherwise
41+ */
42+ public boolean isApplicableToTarget (@ NotNull PlayerDropItemEvent event , @ NotNull ItemStack rune , @ NotNull ItemStack target ) {
43+ DamageResistant data = target .getData (DataComponentTypes .DAMAGE_RESISTANT );
44+ if (data == null ) return true ;
45+ return !data .types ().equals (DamageTypeTagKeys .IS_FIRE );
46+ }
47+
3148 /**
3249 * Handles contacting between an item and a rune.
3350 *
@@ -40,28 +57,30 @@ public void onContactItem(@NotNull PlayerDropItemEvent event, @NotNull ItemStack
4057 // As many runes as possible to consume
4158 int consume = Math .min (rune .getAmount (), target .getAmount ());
4259
43- ItemStack handle = target .asQuantity (consume );
44- handle .setData (DataComponentTypes .DAMAGE_RESISTANT , DamageResistant .damageResistant (DamageTypeTagKeys .IS_FIRE ));
60+ Player player = event .getPlayer ();
61+ ItemStack handle = ItemStackBuilder .of (target .asQuantity (consume )) // Already cloned in `asQuantity`
62+ .set (DataComponentTypes .DAMAGE_RESISTANT , DamageResistant .damageResistant (DamageTypeTagKeys .IS_FIRE ))
63+ .lore (GlobalTranslator .render (TOOLTIP , player .locale ()))
64+ .build ();
4565
4666 // (N)Either left runes or targets
4767 int leftRunes = rune .getAmount () - consume ;
4868 int leftTargets = target .getAmount () - consume ;
4969
50- Player player = event .getPlayer ();
51- Location explodeLoc = player .getTargetBlockExact ((int ) Math .ceil (BaseConfig .RUNE_CHECK_RANGE ), FluidCollisionMode .NEVER ).getLocation ();
70+ Location explodeLoc = event .getItemDrop ().getLocation ();
5271 World world = explodeLoc .getWorld ();
5372 if (leftRunes > 0 ) {
54- world .dropItemNaturally (explodeLoc , rune .asQuantity (leftRunes ));
73+ world .dropItemNaturally (explodeLoc , rune .asQuantity (leftRunes )). setGlowing ( true ) ;
5574 }
5675 if (leftTargets > 0 ) {
57- world .dropItemNaturally (explodeLoc , target .asQuantity (leftTargets ));
76+ world .dropItemNaturally (explodeLoc , target .asQuantity (leftTargets )). setGlowing ( true ) ;
5877 }
59- world .dropItemNaturally (explodeLoc , handle );
78+ world .dropItemNaturally (explodeLoc , handle ). setGlowing ( true ) ;
6079
6180 // simple particles
6281 spawnParticle (Particle .EXPLOSION , explodeLoc , 1 );
63- spawnParticle (Particle .FLAME , explodeLoc , 20 );
64- spawnParticle (Particle .SMOKE , explodeLoc , 1 );
82+ spawnParticle (Particle .FLAME , explodeLoc , 50 );
83+ spawnParticle (Particle .SMOKE , explodeLoc , 40 );
6584 world .playSound (explodeLoc , Sound .ENTITY_GENERIC_EXPLODE , 1.0f , 1.0f );
6685
6786 target .setAmount (0 );
0 commit comments