Skip to content

Commit

Permalink
Added onyx and ruby bonus effects to weapons (wither and burn, respec…
Browse files Browse the repository at this point in the history
…tively)
  • Loading branch information
Leronus committed Mar 10, 2024
1 parent 054d6fe commit 4ad814d
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/main/java/mod/leronus/mores/item/custom/ModSwordItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -57,15 +57,35 @@ public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(
@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
if (stack.getItem() instanceof ModSwordItem){
// tooltip.add(Text.literal(""));
// if (stack.getItem() == ModItems.ONYX_SWORD || stack.getItem() == ModItems.ONYX_MACE || stack.getItem() == ModItems.ONYX_DAGGER) {
// tooltip.add(Text.translatable("mores.bonus").formatted(Formatting.GRAY).append(Text.translatable("mores.wither_effect").formatted(Formatting.DARK_GRAY)));
// }
tooltip.add(Text.literal(""));
if (stack.getItem() == ModItems.ONYX_SWORD || stack.getItem() == ModItems.ONYX_MACE || stack.getItem() == ModItems.ONYX_DAGGER) {
tooltip.add(Text.translatable("mores.bonus").formatted(Formatting.GRAY).append(Text.translatable("mores.wither_effect").formatted(Formatting.DARK_GRAY)));
}
tooltip.add(Text.literal(""));
tooltip.add(Text.translatable("mores.durability").formatted(Formatting.GRAY).append(Text.translatable(String.valueOf(stack.getItem().getMaxDamage())).formatted(Formatting.LIGHT_PURPLE)));
// if (stack.getItem() == ModItems.RUBY_SWORD || stack.getItem() == ModItems.RUBY_MACE || stack.getItem() == ModItems.RUBY_BATTLEAXE || stack.getItem() == ModItems.RUBY_DAGGER) {
// tooltip.add(Text.translatable(Formatting.GRAY + "mores.bonus" + Formatting.RED + "Burn Effect"));
// }
if (stack.getItem() == ModItems.RUBY_SWORD || stack.getItem() == ModItems.RUBY_MACE || stack.getItem() == ModItems.RUBY_BATTLEAXE || stack.getItem() == ModItems.RUBY_DAGGER) {
tooltip.add(Text.translatable(Formatting.GRAY + "mores.bonus" + Formatting.RED + "Burn Effect"));
}
}
}

/**
* Called when an enemy is attacked using the sword
* @param stack Itemstack used to attack with
* @param target Target entity that is being attacked
* @param attacker The entity attacking the enemy
* @return Hurt enemy
*/
@Override
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) {
//If the item is an onyx sword, apply wither effect on targetEntity
if(stack.getItem() == ModItems.ONYX_SWORD || stack.getItem() == ModItems.ONYX_MACE || stack.getItem() == ModItems.ONYX_DAGGER || stack.getItem() == ModItems.ONYX_BATTLEAXE) {
target.addStatusEffect(new StatusEffectInstance(StatusEffects.WITHER, 250, 1, false, false));
}
//If the item is a ruby sword, apply fire effect on targetEntity
if(stack.getItem() == ModItems.RUBY_SWORD || stack.getItem() == ModItems.RUBY_MACE || stack.getItem() == ModItems.RUBY_DAGGER || stack.getItem() == ModItems.RUBY_BATTLEAXE) {
target.setOnFireFor(5);
}
return super.postHit(stack, target, attacker);
}
}

0 comments on commit 4ad814d

Please sign in to comment.