Skip to content
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
4 changes: 4 additions & 0 deletions MODIFIERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ These effects are applied when hurting enemies.
**id:** `soulbound` | **crafting:** `minecraft:nether_star` ![nether_star](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/nether_star.png)

**Decription:** Grants 15% bonus damage and mining speed when wielded by the original owner.
### Synergy
**id:** `synergy` | **crafting:** `minecraft:echo_shard` ![echo_shard](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/echo_shard.png)

**Decription:** Gains 8% bonus damage for each other modifier on this tool.
### Withering
**id:** `wither` | **crafting:** `minecraft:wither_rose` ![wither_rose](https://raw.githubusercontent.com/anish-shanbhag/minecraft-api/master/public/images/items/wither_rose.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static Modifier getModifier(String name) {
public static Modifier PUMMELING = register(new Pummeling());
public static Modifier HAILEYS_WRATH = register(new HaileysWrath());
public static Modifier EARLY_BIRD = register(new EarlyBird());
public static Modifier SYNERGY = register(new Synergy());

// Biome-restricted modifiers
public static Modifier AQUATIC = register(new Aquatic());
Expand Down Expand Up @@ -103,7 +104,7 @@ public static Modifier getModifier(String name) {
public static final Set<Modifier> BREAKERS = Set.of(EXPLODE, LEARNING, ATTRACTING, VEINY, MELTING, EXCAVATOR, PROSPECTOR, MUNCHIES, FRAGILE, LUMBERING);
public static final Set<Modifier> USERS = Set.of(TORCH_PLACE, DIRT_PLACE, FIRE_PLACE, FIRE_BALL, VOID_TOUCHED);
public static final Set<Modifier> HURTERS = Set.of(CRITICAL, CHARGING, FLAMING, COMBO, DRAINING, POISONOUS,
WITHERING, BLINDING, BEZERK, NEMESIS, SOULBOUND, SCORCHED, FROZEN, OVERGROWN, FIERCE, FEASTING, EXECUTIONER, CROWD_PLEASER, PUMMELING, HAILEYS_WRATH, MUNCHIES, CHAOTIC, FRAGILE, CLUNKY, EARLY_BIRD);
WITHERING, BLINDING, BEZERK, NEMESIS, SOULBOUND, SCORCHED, FROZEN, OVERGROWN, FIERCE, FEASTING, EXECUTIONER, CROWD_PLEASER, PUMMELING, HAILEYS_WRATH, MUNCHIES, CHAOTIC, FRAGILE, CLUNKY, EARLY_BIRD, SYNERGY);
public static final Set<Modifier> HOLDERS = Set.of(HASTY, ABSORBTION, FILLING, RAINY, ORE_FINDER, SPAWNER_FINDER,
LIVING, REGENERATING, RESISTANT, FIRE_RESISTANT, AQUATIC, HUNTER, FEASTING, NATURALIST, CLUNKY);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package dev.marston.randomloot.loot.modifiers.hurter;

import dev.marston.randomloot.loot.LootItem;
import dev.marston.randomloot.loot.LootItem.ToolType;
import dev.marston.randomloot.loot.LootUtils;
import dev.marston.randomloot.loot.modifiers.EntityHurtModifier;
import dev.marston.randomloot.loot.modifiers.Modifier;
import net.minecraft.ChatFormatting;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import java.util.List;

public class Synergy implements EntityHurtModifier {

private String name;
private static final float BONUS_PER_MODIFIER = 0.08f; // 8% per other modifier

public Synergy() {
this("Synergy");
}

public Synergy(String name) {
this.name = name;
}

public Modifier clone() {
return new Synergy();
}

@Override
public CompoundTag toNBT() {
CompoundTag tag = new CompoundTag();
tag.putString(NAME, name);
return tag;
}

@Override
public Modifier fromNBT(CompoundTag tag) {
return new Synergy(tag.getStringOr(NAME, "Synergy"));
}

@Override
public String name() {
return name;
}

@Override
public String tagName() {
return "synergy";
}

@Override
public String color() {
return ChatFormatting.LIGHT_PURPLE.getName();
}

@Override
public String description() {
return "Gains 8% bonus damage for each other modifier on this tool.";
}

@Override
public void writeToLore(List<Component> list, boolean shift) {
MutableComponent comp = Modifier.makeComp(this.name(), this.color());
list.add(comp);
}

@Override
public Component writeDetailsToLore(Level level) {
return null; // Dynamic bonus calculated per hit
}

@Override
public boolean forTool(ToolType type) {
return type.equals(ToolType.SWORD) || type.equals(ToolType.AXE);
}

private float calculateBonus(ItemStack itemstack) {
// Count other modifiers on this tool (excluding self)
List<Modifier> modifiers = LootUtils.getModifiers(itemstack);
int otherModifiers = Math.max(0, modifiers.size() - 1); // -1 to exclude this modifier

return otherModifiers * BONUS_PER_MODIFIER;
}

@Override
public boolean hurtEnemy(ItemStack itemstack, LivingEntity hurtee, LivingEntity hurter) {
Level level = hurtee.level();

float bonusPercent = calculateBonus(itemstack);

if (bonusPercent > 0) {
float baseDamage = LootItem.getAttackDamage(itemstack, LootUtils.getToolType(itemstack));
float bonusDamage = baseDamage * bonusPercent;

if (hurter instanceof net.minecraft.world.entity.player.Player p) {
hurtee.hurt(hurter.damageSources().playerAttack(p), bonusDamage);
} else {
hurtee.hurt(hurter.damageSources().mobAttack(hurter), bonusDamage);
}

// Visual feedback - purple particles when synergy activates
if (!level.isClientSide()) {
Modifier.TrackEntityParticle(level, hurtee, ParticleTypes.ENCHANT);
}
}

return false;
}

@Override
public boolean compatible(Modifier mod) {
// Synergy works with everything!
return true;
}
}
8 changes: 8 additions & 0 deletions src/main/resources/data/randomloot/recipe/trait_synergy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "randomloot:trait_change",
"item": {
"count": 1,
"id": "minecraft:echo_shard"
},
"trait": "synergy"
}
Loading