Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Starexify committed Nov 20, 2024
1 parent 0e75e67 commit 91ee15a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"big_swords_addon:gilded_lonsdaleite_shield.perk": "Special Perk: ",
"big_swords_addon:gilded_lonsdaleite_shield.weakness": "Weakness: ",
"big_swords_addon:gilded_lonsdaleite_shield.perk": "Special Perk: Shatterproof",
"big_swords_addon:gilded_lonsdaleite_shield.weakness": "Weakness: Defensive Overload",
"big_swords_addon:gilded_titanium_shield.perk": "Special Perk: Titanic Slam",
"big_swords_addon:gilded_titanium_shield.weakness": "Weakness: Heavy",
"big_swords_addon:lonsdaleite_shield.perk": "Special Perk: ",
"big_swords_addon:lonsdaleite_shield.weakness": "Weakness: ",
"big_swords_addon:lonsdaleite_shield.perk": "Special Perk: Shatterproof",
"big_swords_addon:lonsdaleite_shield.weakness": "Weakness: Defensive Overload",
"big_swords_addon:titanium_shield.perk": "Special Perk: Titanic Slam",
"big_swords_addon:titanium_shield.weakness": "Weakness: Heavy",
"item.big_swords_addon.gilded_lonsdaleite_shield": "Gilded Lonsdaleite Shield",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected void addTranslations() {
// Shields
addShield(BCItems.TITANIUM_SHIELD, "Titanium Shield", "Special Perk: Titanic Slam", "Weakness: Heavy");
addShield(BCItems.GILDED_TITANIUM_SHIELD, "Gilded Titanium Shield", "Special Perk: Titanic Slam", "Weakness: Heavy");
addShield(BCItems.LONSDALEITE_SHIELD, "Lonsdaleite Shield", "Special Perk: ", "Weakness: ");
addShield(BCItems.GILDED_LONSDALEITE_SHIELD, "Gilded Lonsdaleite Shield", "Special Perk: ", "Weakness: ");
addShield(BCItems.LONSDALEITE_SHIELD, "Lonsdaleite Shield", "Special Perk: Shatterproof", "Weakness: Defensive Overload");
addShield(BCItems.GILDED_LONSDALEITE_SHIELD, "Gilded Lonsdaleite Shield", "Special Perk: Shatterproof", "Weakness: Defensive Overload");
}

public void addShield(Supplier<? extends Item> key, String name, String perk, String weakness) {
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/net/nova/big_swords_addon/event/ShieldMechanics.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.nova.big_swords_addon.event;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
Expand All @@ -21,40 +23,46 @@

import java.util.List;
import java.util.Random;
import java.util.UUID;

import static net.nova.big_swords_addon.BigSwordsRAddon.MODID;

@EventBusSubscriber(modid = MODID)
public class ShieldMechanics {
public static final ResourceLocation MOVEMENT_SPEED_ID = ResourceLocation.withDefaultNamespace("movement_speed");
private static int consecutiveBlockCount = 0;

@SubscribeEvent
public static void onShieldBlock(LivingShieldBlockEvent event) {
if (event.getEntity() instanceof Player player && event.getBlocked()) {
ItemStack shield = player.getUseItem();
Entity attacker = event.getDamageSource().getEntity();
DamageSource damageSource = event.getDamageSource();
Level level = player.level();
Entity sourceEntity = event.getDamageSource().getDirectEntity();
float blockedDamage = event.getBlockedDamage();
float shieldDamage = event.shieldDamage();
double randomChance = Math.random();
Random random = new Random();


// Lonsdaleite Shields
boolean isLonsdaleiteShield = shield.is(BCItems.LONSDALEITE_SHIELD);
boolean isGildedLonsdaleiteShield = shield.is(BCItems.GILDED_LONSDALEITE_SHIELD);
if ((isLonsdaleiteShield || isGildedLonsdaleiteShield)) {
// Perk
if (attacker instanceof LivingEntity && (damageSource.is(DamageTypes.PLAYER_ATTACK) || damageSource.is(DamageTypes.MOB_ATTACK))) {
event.setShieldDamage(0);

// Prevent axes from putting the shield on cooldown
if (attacker instanceof LivingEntity living) {
ItemStack weapon = living.getMainHandItem();
if (weapon.getItem() instanceof AxeItem) {
event.setCanceled(true);
player.getCooldowns().removeCooldown(shield.getItem());
}
}

// Weakness
consecutiveBlockCount++;
int stunThreshold = isGildedLonsdaleiteShield ? 10 : 5;
if (consecutiveBlockCount >= stunThreshold) {
player.setNoActionTime(400);
player.setDeltaMovement(0, player.getDeltaMovement().y, 0);
player.displayClientMessage(Component.literal("You are stunned!").withStyle(ChatFormatting.RED), true);
consecutiveBlockCount = 0;
}
}
}
}
Expand Down

0 comments on commit 91ee15a

Please sign in to comment.