Skip to content

Commit

Permalink
Steel stops fall damage if you fall on metal
Browse files Browse the repository at this point in the history
  • Loading branch information
legobmw99 committed Jan 14, 2024
1 parent 1d52fe3 commit 66aa593
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<SCREEN_LOC> overlay_position;
public static ModConfigSpec.EnumValue<MetalOverlay.SCREEN_LOC> overlay_position;
public static ModConfigSpec.BooleanValue random_mistings;
public static ModConfigSpec.BooleanValue generate_whitelist;
public static ModConfigSpec.BooleanValue respect_player_UUID;
Expand All @@ -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();

}
Expand Down Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
}
}
}

0 comments on commit 66aa593

Please sign in to comment.