Skip to content

Commit

Permalink
Fix fire protection fire time reduction not working on shields (#5169)
Browse files Browse the repository at this point in the history
This fix is a bit more hacky, to tie it to a config option just in case it breaks something.
Code analysis suggests that this will make fire protection work better on items you cheat it onto in creative, but should have no survival impact.
  • Loading branch information
KnightMiner committed Dec 13, 2023
1 parent dca2f19 commit 5e36f3e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/main/java/slimeknights/tconstruct/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.common.collect.ImmutableList;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
Expand Down Expand Up @@ -29,7 +31,7 @@ public class Config {
public static class Common {

public final BooleanValue shouldSpawnWithTinkersBook;
public final List<ConfigurableAction> damageSourceTweaks;
public final List<ConfigurableAction> toolTweaks;

// recipes
public final BooleanValue addGravelToFlintRecipe;
Expand Down Expand Up @@ -81,8 +83,12 @@ public enum LogInvalidToolStack { STACKTRACE, WARNING, IGNORED };
.worldRestart()
.define("shouldSpawnWithTinkersBook", true);

builder.comment("Tweaks to vanilla damage sources to better work with armor").push("damageTweaks");
ImmutableList.Builder<ConfigurableAction> actions = ImmutableList.builder();
actions.add(new ConfigurableAction(builder, "extendFireProtectionSlots", true,
"If true, extends the applicable slots for the fire protection enchantment to work better with shields. Will not impact gameplay with the vanilla enchantment.\nIf false, fire protection on a shield will not reduce fire tick time.",
() -> Enchantments.FIRE_PROTECTION.slots = EquipmentSlot.values()));

builder.comment("Tweaks to vanilla damage sources to better work with armor").push("damageTweaks");
actions.add(new ConfigurableAction(builder, "wither", true, "Makes withering damage count as magic", DamageSource.WITHER::setMagic));
actions.add(new ConfigurableAction(builder, "dragon_breath", true, "Makes dragons breath count as magic", DamageSource.DRAGON_BREATH::setMagic));
actions.add(new ConfigurableAction(builder, "falling_block", false, "Makes falling blocks count as projectile", () -> {
Expand All @@ -91,7 +97,7 @@ public enum LogInvalidToolStack { STACKTRACE, WARNING, IGNORED };
DamageSource.FALLING_STALACTITE.setProjectile();
}));
actions.add(new ConfigurableAction(builder, "lightning", true, "Makes lightning count as fire damage", DamageSource.LIGHTNING_BOLT::setIsFire));
damageSourceTweaks = actions.build();
toolTweaks = actions.build();

this.repairKitAmount = builder
.comment("Amount of durability restored by a repair kit in terms of ingots. Does not affect the cost to create the kit, that is controlled by JSON.")
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/slimeknights/tconstruct/library/utils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,14 @@ public static BlockHitResult createTraceResult(BlockPos pos, Direction sideHit,
public static <B extends BlockEntity> ClientboundBlockEntityDataPacket createBEPacket(B be, Function<? super B,CompoundTag> tagFunction) {
return new ClientboundBlockEntityDataPacket(be.getBlockPos(), be.getType(), tagFunction.apply(be));
}

/** Quick helper to search an array for a given value by reference equality, designed mainly for enums. */
public static <T> boolean isInList(T[] slots, T predicate) {
for (T slot : slots) {
if (slot == predicate) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void commonSetup(FMLCommonSetupEvent event) {
EquipmentChangeWatcher.register();
ToolCapabilityProvider.register(ToolFluidCapability.Provider::new);
ToolCapabilityProvider.register(ToolInventoryCapability.Provider::new);
for (ConfigurableAction action : Config.COMMON.damageSourceTweaks) {
for (ConfigurableAction action : Config.COMMON.toolTweaks) {
event.enqueueWork(action);
}
TinkerHooks.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlot.Type;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.enchantment.Enchantments;
Expand All @@ -13,6 +12,7 @@
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import slimeknights.tconstruct.library.utils.RestrictedCompoundTag;
import slimeknights.tconstruct.library.utils.TooltipKey;
import slimeknights.tconstruct.library.utils.Util;

import javax.annotation.Nullable;
import java.util.List;
Expand All @@ -34,7 +34,7 @@ public float getProtectionModifier(IToolStackView tool, int level, EquipmentCont
if (!source.isBypassMagic() && !source.isBypassInvul() && source.isFire()) {
// we already got floored level * 2 boost from the vanilla enchantment on armor, so cancel that out
float scaledLevel = getEffectiveLevel(tool, level);
if (slotType.getType() == Type.ARMOR) {
if (Util.isInList(Enchantments.FIRE_PROTECTION.slots, slotType)) {
modifierValue += scaledLevel * 2.5f - Math.floor(scaledLevel) * 2f;
} else {
modifierValue += scaledLevel * 2.5f;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,6 @@ public net.minecraft.world.item.alchemy.PotionBrewing f_43495_ # CONTAINER_MIXES

# Mojang added a private getter for text fields private variable
public net.minecraft.client.gui.components.EditBox m_94222_()Z # isEditable

# Allow seeing the applicable slots for an enchantment for some fallback logic, just in case some mod changes it
public-f net.minecraft.world.item.enchantment.Enchantment f_44671_ # slots

0 comments on commit 5e36f3e

Please sign in to comment.