Skip to content

Commit

Permalink
Wooden and Stone Shields are now compatible with Soul fire'd !
Browse files Browse the repository at this point in the history
  • Loading branch information
Starexify committed Feb 11, 2025
1 parent d483dd8 commit 0be8e22
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 46 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ neo_version=21.4.88-beta
neo_version_range=[21.4,)
loader_version_range=[4,)

## Mod Properties
# Mod Properties

mod_id=big_swords
mod_name=Big Swords R
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/net/nova/big_swords/BigSwordsR.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package net.nova.big_swords;

import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.ItemEnchantments;
import net.minecraft.world.level.Level;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
Expand Down Expand Up @@ -56,15 +51,6 @@ public static ResourceLocation rl(String path) {
return ResourceLocation.fromNamespaceAndPath(MODID, path);
}

public static int getItemEnchantmentLevel(ItemStack item, ResourceKey<Enchantment> enchantment) {
return item.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY)
.entrySet().stream()
.filter(entry -> entry.getKey().equals(enchantment))
.findAny()
.map(entry -> entry.getIntValue())
.orElse(0);
}

public static double getModifierValue(List<ItemAttributeModifiers.Entry> modifiers, ResourceLocation modifierId) {
return modifiers.stream()
.filter(entry -> entry.modifier().is(modifierId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.server.packs.repository.PackCompatibility;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModList;
import net.neoforged.fml.common.EventBusSubscriber;
Expand All @@ -23,7 +22,7 @@

import static net.nova.big_swords.BigSwordsR.MODID;

@EventBusSubscriber(modid = MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
@EventBusSubscriber(modid = MODID, bus = EventBusSubscriber.Bus.MOD)
public class BigSwordsRClient {
public static final String[] RESOURCE_PACKS = {"big_swords_r_16x", "big_swords_r_old"};
public static final String RP_16x = RESOURCE_PACKS[0];
Expand Down
54 changes: 30 additions & 24 deletions src/main/java/net/nova/big_swords/event/ShieldMechanics.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package net.nova.big_swords.event;

import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.RandomSource;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.effect.MobEffectInstance;
Expand Down Expand Up @@ -30,7 +34,6 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.living.LivingShieldBlockEvent;
import net.nova.big_swords.BigSwordsR;
import net.nova.big_swords.init.BSItems;

import java.util.Random;
Expand All @@ -52,8 +55,16 @@ public static void onShieldBlock(LivingShieldBlockEvent event) {
float shieldDamage = event.shieldDamage();
double randomChance = Math.random();
double randomChanceE = Math.random();
Random random = new Random();
Level level = player.level();
RandomSource random = level.getRandom();
int fireAspectLevel = attacker instanceof LivingEntity livingEntity ? livingEntity.getMainHandItem().getEnchantmentLevel(player.level().registryAccess().lookupOrThrow(Registries.ENCHANTMENT).getOrThrow(Enchantments.FIRE_ASPECT)) : 0;
int soulFireAspectLevel = attacker instanceof LivingEntity livingEntity ?
player.level().registryAccess()
.lookupOrThrow(Registries.ENCHANTMENT)
.get(ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.withDefaultNamespace("soul_fire_aspect")))
.map(enchantment -> livingEntity.getMainHandItem().getEnchantmentLevel(enchantment))
.orElse(0)
: 0;

// Wooden Shields
boolean isWoodenShield = shield.is(BSItems.WOODEN_SHIELD);
Expand All @@ -77,33 +88,28 @@ public static void onShieldBlock(LivingShieldBlockEvent event) {
}
}

// Weakness
if (attacker instanceof LivingEntity livingAttacker) {
ItemStack attackerWeapon = livingAttacker.getMainHandItem();
int fireAspectLevel = BigSwordsR.getItemEnchantmentLevel(attackerWeapon, Enchantments.FIRE_ASPECT);
switch (fireAspectLevel) {
case 1:
event.setShieldDamage(shieldDamage * 3);
break;
case 2:
event.setShieldDamage(shieldDamage * 5);
break;
}
}
// Weakness (Comp with Soul fire'd)
if (fireAspectLevel > 0) event.setShieldDamage(shieldDamage * switch (fireAspectLevel) {
case 1 -> 3;
case 2 -> 5;
default -> 1;
});

if (soulFireAspectLevel > 0) event.setShieldDamage(shieldDamage * switch (soulFireAspectLevel) {
case 1 -> 6;
case 2 -> 10;
default -> 1;
});
}

// Stone Shields
boolean isStoneShield = shield.is(BSItems.STONE_SHIELD);
boolean isGildedStoneShield = shield.is(BSItems.GILDED_STONE_SHIELD);
if ((isStoneShield || isGildedStoneShield)) {
// Perk
if (attacker instanceof LivingEntity livingAttacker) {
ItemStack attackerWeapon = livingAttacker.getMainHandItem();
int fireAspectLevel = BigSwordsR.getItemEnchantmentLevel(attackerWeapon, Enchantments.FIRE_ASPECT);
if (fireAspectLevel > 0) {
event.setShieldDamage(0);
playSound(level, player, SoundEvents.FIRE_EXTINGUISH);
}
if (fireAspectLevel > 0 || soulFireAspectLevel > 0) {
event.setShieldDamage(0);
playSound(level, player, SoundEvents.FIRE_EXTINGUISH);
}
if (sourceEntity instanceof Fireball || (sourceEntity instanceof Projectile projectile && projectile.isOnFire())) {
event.setShieldDamage(0);
Expand All @@ -124,7 +130,7 @@ public static void onShieldBlock(LivingShieldBlockEvent event) {
boolean isGildedIronShield = shield.is(BSItems.GILDED_IRON_SHIELD);
if ((isIronShield || isGildedIronShield) && (damageSource.is(DamageTypes.EXPLOSION) || damageSource.is(DamageTypes.PLAYER_EXPLOSION))) {
// Perk
float newShieldDamage = isGildedIronShield ? 0 : (isIronShield ? shieldDamage / 2 : shieldDamage);
float newShieldDamage = isGildedIronShield ? 0 : shieldDamage / 2;
event.setShieldDamage(newShieldDamage);
}

Expand Down Expand Up @@ -318,7 +324,7 @@ public static void onShieldBlock(LivingShieldBlockEvent event) {
}
}

private static void setNearestTarget(Mob mob, Player blockingPlayer) {
public static void setNearestTarget(Mob mob, Player blockingPlayer) {
double SEARCH_RANGE = 16.0;
Level level = mob.level();
AABB boundingBox = new AABB(
Expand Down
5 changes: 0 additions & 5 deletions src/main/templates/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ sources="https://github.com/Starexify/BigSwordsR"
[[mixins]]
config="big_swords.mixins.json"

# The [[accessTransformers]] block allows you to declare where your AT file is.
# If this block is omitted, a fallback attempt will be made to load an AT from META-INF/accesstransformer.cfg
#[[accessTransformers]]
#file="META-INF/accesstransformer.cfg"

[[dependencies.${mod_id}]]
modId="neoforge"
type="required"
Expand Down

0 comments on commit 0be8e22

Please sign in to comment.