Skip to content

Commit

Permalink
Some refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
ExDrill committed Apr 24, 2024
1 parent c757493 commit f18f22c
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 81 deletions.
7 changes: 0 additions & 7 deletions src/main/java/com/teamabode/guarding/Guarding.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ public class Guarding implements ModInitializer {
builder.addFloatProperty("additional_knockback_strength_per_level", 0.15f);
return builder;
})
/*
.addGroup("retribution", builder -> {
builder.addIntProperty("slowness_amplifier", 1);
builder.addBooleanProperty("is_treasure", true);
return builder;
})
*/
.build();

public void onInitialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

import net.minecraft.world.item.enchantment.Enchantment;

public class BarbedEnchantment extends GuardingEnchantment {

public class BarbedEnchantment extends ShieldEnchantment {
public BarbedEnchantment() {
super(2, 1, Enchantment.constantCost(20), Enchantment.constantCost(50), 2);
}

protected boolean checkCompatibility(Enchantment other) {
return !(other instanceof RetributionEnchantment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.minecraft.world.item.enchantment.Enchantment;

public class PummelingEnchantment extends GuardingEnchantment {
public class PummelingEnchantment extends ShieldEnchantment {

public PummelingEnchantment() {
super(5, 3, Enchantment.dynamicCost(10, 10), Enchantment.dynamicCost(60, 10), 4);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.teamabode.guarding.common.enchantment;

import com.teamabode.guarding.Guarding;
import net.fabricmc.fabric.api.tag.convention.v2.ConventionalItemTags;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShieldItem;
import net.minecraft.world.item.enchantment.Enchantment;

public class GuardingEnchantment extends Enchantment {

public GuardingEnchantment(int weight, int maxLevel, Cost minCost, Cost maxCost, int anvilCost) {
public class ShieldEnchantment extends Enchantment {
public ShieldEnchantment(int weight, int maxLevel, Cost minCost, Cost maxCost, int anvilCost) {
super(Enchantment.definition(Guarding.SHIELD_ENCHANTABLE, weight, maxLevel, minCost, maxCost, anvilCost, EquipmentSlot.MAINHAND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
public class GuardingCallbacks {

public static void init() {
ShieldEvents.BLOCKED.register(GuardingCallbacks::onShieldBlock);
//ShieldEvents.DISABLED.register(GuardingCallbacks::onShieldDisabled);
ShieldEvents.BLOCKED.register(GuardingCallbacks::onBlocked);
}

// Logic for blocking
private static void onShieldBlock(Player user, DamageSource source, float amount) {
private static void onBlocked(Player user, DamageSource source, float amount) {
Entity sourceEntity = source.getDirectEntity();
boolean isParry = (user.getUseItem().getUseDuration() - user.getUseItemRemainingTicks()) <= 3;
if (sourceEntity instanceof LivingEntity attacker) blockLivingEntity(user, attacker, isParry);
if (sourceEntity instanceof Projectile projectile) blockProjectile(user, source.getEntity(), projectile, isParry);
tryParryEffects(user, sourceEntity, isParry);

if (isParry) {
parryEffects(user, sourceEntity);
}
}

// Logic for blocking a living entity
Expand Down Expand Up @@ -82,39 +84,13 @@ private static float getKnockbackStrength(ItemStack stack) {
}

// Parry visual effects (Sound and particles)
private static void tryParryEffects(Player user, Entity sourceEntity, boolean isParry) {
if (!isParry) return;

private static void parryEffects(Player user, Entity sourceEntity) {
Level level = user.level();
SoundEvent breakSound = user.getUseItem().is(GuardingItems.NETHERITE_SHIELD) ? GuardingSounds.ITEM_NETHERITE_SHIELD_PARRY : GuardingSounds.ITEM_SHIELD_PARRY;
SoundEvent breakSound = GuardingSounds.ITEM_SHIELD_PARRY;
level.playSound(null, user.blockPosition(), breakSound, SoundSource.PLAYERS);

if (level instanceof ServerLevel server && sourceEntity != null) {
server.sendParticles(GuardingParticles.PARRY, sourceEntity.getX(), sourceEntity.getEyeY(), sourceEntity.getZ(), 1, 0.0d, 0.0d, 0.0d, 0.0d);
}
}

// Handles the code for the Retribution Enchantment
private static void onShieldDisabled(Player user, LivingEntity attacker) {
/*
ItemStack useItem = user.getUseItem();
int retributionLevel = EnchantmentHelper.getItemEnchantmentLevel(GuardingEnchantments.RETRIBUTION, useItem);
int amplifier = Guarding.CONFIG.getGroup("retribution").getIntProperty("slowness_amplifier");
if (retributionLevel > 0) {
List<LivingEntity> list = attacker.level().getEntitiesOfClass(LivingEntity.class, user.getBoundingBox().inflate(3.0d, 0.0d, 3.0d), livingEntity -> isEnemy(user, livingEntity));
for (LivingEntity livingEntity : list) {
livingEntity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, retributionLevel * 50, amplifier, true, true));
}
}
*/
}

// The condition for retribution to apply
private static boolean isEnemy(Player user, LivingEntity other) {
if (other == user) return false;
if (other instanceof Player otherPlayer) return user.canHarmPlayer(otherPlayer);
return other.canBeSeenAsEnemy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.teamabode.guarding.Guarding;
import com.teamabode.guarding.common.enchantment.BarbedEnchantment;
import com.teamabode.guarding.common.enchantment.PummelingEnchantment;
import com.teamabode.guarding.common.enchantment.RetributionEnchantment;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class GuardingSounds {

public static final SoundEvent ITEM_NETHERITE_SHIELD_BLOCK = register("item.netherite_shield.block");
public static final SoundEvent ITEM_NETHERITE_SHIELD_BREAK = register("item.netherite_shield.break");
public static final SoundEvent ITEM_NETHERITE_SHIELD_PARRY = register("item.netherite_shield.parry");
public static final Holder<SoundEvent> ITEM_NETHERITE_SHIELD_EQUIP = registerHolder("item.netherite_shield.equip");

private static SoundEvent register(String name) {
Expand Down
8 changes: 0 additions & 8 deletions src/main/resources/assets/guarding/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
],
"subtitle": "subtitle.guarding.item.netherite_shield.break"
},
"item.netherite_shield.parry": {
"sounds": [
"mob/zombie/metal1",
"mob/zombie/metal2",
"mob/zombie/metal3"
],
"subtitle": "subtitle.guarding.item.netherite_shield.parry"
},
"item.netherite_shield.equip": {
"sounds": [
"guarding:item/netherite_shield/equip1",
Expand Down

0 comments on commit f18f22c

Please sign in to comment.