From 66aa593d22fdfe7c2e8ab328ff27d9d90a2887ac Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 14 Jan 2024 14:24:23 -0500 Subject: [PATCH] Steel stops fall damage if you fall on metal --- .../modules/powers/CommonEventHandler.java | 40 +++++++++----- .../modules/powers/PowersConfig.java | 13 ++--- .../powers/client/gui/MetalOverlay.java | 53 ++++++++++--------- 3 files changed, 58 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java b/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java index 19dbd5eb..9fa8adcc 100644 --- a/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java +++ b/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java @@ -11,12 +11,14 @@ import com.legobmw99.allomancy.modules.powers.network.EnhanceTimePayload; import com.legobmw99.allomancy.network.Network; import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtAccounter; import net.minecraft.nbt.NbtIo; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.LivingEntity; @@ -34,6 +36,7 @@ import net.minecraft.world.phys.Vec3; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.neoforge.event.TickEvent; +import net.neoforged.neoforge.event.entity.living.LivingAttackEvent; import net.neoforged.neoforge.event.entity.living.LivingDeathEvent; import net.neoforged.neoforge.event.entity.living.LivingHurtEvent; import net.neoforged.neoforge.event.entity.player.PlayerEvent; @@ -169,7 +172,7 @@ public static void onLivingDeath(final LivingDeathEvent event) { } @SubscribeEvent - public static void onDamage(final LivingHurtEvent event) { + public static void onEntityHurt(final LivingHurtEvent event) { // Increase outgoing damage for pewter burners if (event.getSource().getEntity() instanceof ServerPlayer source) { var data = source.getData(AllomancerAttachment.ALLOMANCY_DATA); @@ -201,19 +204,32 @@ public static void onDamage(final LivingHurtEvent event) { // Reduce incoming damage for pewter burners if (event.getEntity() instanceof ServerPlayer player) { var data = player.getData(AllomancerAttachment.ALLOMANCY_DATA); - if (data.isBurning(Metal.PEWTER)) { - if (data.isEnhanced()) { // Duralumin invulnerability - Allomancy.LOGGER.debug("Canceling Damage"); - event.setAmount(0); - event.setCanceled(true); - } else { - Allomancy.LOGGER.debug("Reducing Damage"); + Allomancy.LOGGER.debug("Reducing Damage"); + event.setAmount(event.getAmount() - 2); + // Note that they took damage, will come in to play if they stop burning + data.setDamageStored(data.getDamageStored() + 2); + Network.syncAllomancerData(player); + } + } + } + + @SubscribeEvent + public static void onPlayerAttacked(final LivingAttackEvent event) { + if (event.getEntity() instanceof ServerPlayer player) { + var data = player.getData(AllomancerAttachment.ALLOMANCY_DATA); - event.setAmount(event.getAmount() - 2); - // Note that they took damage, will come in to play if they stop burning - data.setDamageStored(data.getDamageStored() + 1); - Network.syncAllomancerData(player); + if (data.isBurning(Metal.PEWTER) && data.isEnhanced()) { // Duralumin invulnerability + Allomancy.LOGGER.debug("Canceling Damage"); + event.setCanceled(true); + } + + if (data.isBurning(Metal.STEEL)) { + if (event.getSource().type().equals(player.level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(DamageTypes.FALL).value())) { + BlockPos on = player.getOnPos(); + if (PowerUtils.isBlockStateMetal(player.level().getBlockState(on)) || PowerUtils.isBlockStateMetal(player.level().getBlockState(on.above()))) { + event.setCanceled(true); + } } } } diff --git a/src/main/java/com/legobmw99/allomancy/modules/powers/PowersConfig.java b/src/main/java/com/legobmw99/allomancy/modules/powers/PowersConfig.java index 8f126a19..f9d6e413 100644 --- a/src/main/java/com/legobmw99/allomancy/modules/powers/PowersConfig.java +++ b/src/main/java/com/legobmw99/allomancy/modules/powers/PowersConfig.java @@ -3,6 +3,7 @@ import com.legobmw99.allomancy.Allomancy; import com.legobmw99.allomancy.modules.combat.CombatSetup; import com.legobmw99.allomancy.modules.consumables.ConsumeSetup; +import com.legobmw99.allomancy.modules.powers.client.gui.MetalOverlay; import com.legobmw99.allomancy.util.AllomancyConfig; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; @@ -23,7 +24,7 @@ public class PowersConfig { public static ModConfigSpec.IntValue max_metal_detection; public static ModConfigSpec.BooleanValue animate_selection; public static ModConfigSpec.BooleanValue enable_overlay; - public static ModConfigSpec.EnumValue overlay_position; + public static ModConfigSpec.EnumValue overlay_position; public static ModConfigSpec.BooleanValue random_mistings; public static ModConfigSpec.BooleanValue generate_whitelist; public static ModConfigSpec.BooleanValue respect_player_UUID; @@ -49,7 +50,7 @@ public static void init(ModConfigSpec.Builder server_builder, ModConfigSpec.Buil max_metal_detection = client_builder.comment("Maximum iron/steelsight distance. Can have a HUGE impact on performance").defineInRange("max_metal_distance", 15, 3, 30); animate_selection = client_builder.comment("Animate the selection wheel").define("animate_selection", true); enable_overlay = client_builder.comment("Enable the screen overlay").define("overlay_enabled", true); - overlay_position = client_builder.comment("Screen Overlay Position").defineEnum("overlay_position", SCREEN_LOC.TOP_LEFT); + overlay_position = client_builder.comment("Screen Overlay Position").defineEnum("overlay_position", MetalOverlay.SCREEN_LOC.TOP_LEFT); client_builder.pop(); } @@ -192,12 +193,4 @@ private static void add(Block block) { private static void add(Item item) { add(BuiltInRegistries.ITEM.getKey(item)); } - - public enum SCREEN_LOC { - TOP_RIGHT, - BOTTOM_RIGHT, - TOP_LEFT, - BOTTOM_LEFT - } - } diff --git a/src/main/java/com/legobmw99/allomancy/modules/powers/client/gui/MetalOverlay.java b/src/main/java/com/legobmw99/allomancy/modules/powers/client/gui/MetalOverlay.java index d4465047..424e475f 100644 --- a/src/main/java/com/legobmw99/allomancy/modules/powers/client/gui/MetalOverlay.java +++ b/src/main/java/com/legobmw99/allomancy/modules/powers/client/gui/MetalOverlay.java @@ -56,38 +56,19 @@ public void render(ExtendedGui gui, GuiGraphics guiGraphics, float partialTick, return; } + var data = player.getData(AllomancerAttachment.ALLOMANCY_DATA); - int renderX, renderY; - - // Set the offsets of the overlay based on config - switch (PowersConfig.overlay_position.get()) { - case TOP_RIGHT -> { - renderX = screenWidth - 145; - renderY = 10; - } - case BOTTOM_RIGHT -> { - renderX = screenWidth - 145; - renderY = screenHeight - 50; - } - case BOTTOM_LEFT -> { - renderX = 5; - renderY = screenHeight - 50; - } - default -> { // TOP_LEFT - renderX = 5; - renderY = 10; - } + if (data.isUninvested()) { + return; } - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, meterLoc); - var data = player.getData(AllomancerAttachment.ALLOMANCY_DATA); + int renderX = PowersConfig.overlay_position.get().getX(screenWidth); + int renderY = PowersConfig.overlay_position.get().getY(screenHeight); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShaderTexture(0, meterLoc); - if (data.isUninvested()) { - return; - } /* * The rendering for the overlay @@ -121,4 +102,24 @@ public void render(ExtendedGui gui, GuiGraphics guiGraphics, float partialTick, } } + public enum SCREEN_LOC { + TOP_RIGHT, + BOTTOM_RIGHT, + TOP_LEFT, + BOTTOM_LEFT; + + public int getX(int screenWidth) { + return switch (this) { + case TOP_RIGHT, BOTTOM_RIGHT -> screenWidth - 145; + default -> 5; + }; + } + + public int getY(int screenHeight) { + return switch (this) { + case BOTTOM_RIGHT, BOTTOM_LEFT -> screenHeight - 50; + default -> 10; + }; + } + } }