Skip to content

Commit

Permalink
Added support for consumable cooling/warming items
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Jan 1, 2024
1 parent 3463aa6 commit 92b4087
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.4 2024-01-01T12:51:21.0396063 Tags for minecraft:item mod id toughasnails
// 1.20.4 2024-01-02T10:32:54.7659436 Tags for minecraft:item mod id toughasnails
f05342856fe99891fa5e94bbe8db82a4f75ac41e data/toughasnails/tags/items/cooling_armor.json
35133e95f1c8fdd7a1c21afcc231fc0bffefb9a8 data/toughasnails/tags/items/cooling_consumed_items.json
7c304628a9c17ca3ba6cd13e199fcf73ad9c974f data/toughasnails/tags/items/cooling_held_items.json
Expand Down
14 changes: 11 additions & 3 deletions common/src/main/java/toughasnails/config/TemperatureConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
import toughasnails.temperature.BuiltInTemperatureModifier;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class TemperatureConfig extends Config
{
Expand All @@ -23,10 +26,12 @@ public class TemperatureConfig extends Config
public int armorTemperatureChangeDelay;
public int handheldTemperatureChangeDelay;
public int playerTemperatureChangeDelay;
public int internalTemperatureChangeDelay;
public int extremityReboundTemperatureChangeDelay;
public int extremityDamageDelay;
public int climateClemencyDuration;
public boolean climateClemencyRespawning;
public int consumableEffectDuration;

public int temperatureDropAltitude;
public int temperatureRiseAltitude;
Expand All @@ -50,12 +55,13 @@ public TemperatureConfig()
super(Environment.getConfigPath().resolve(TANAPI.MOD_ID + "/temperature.toml"));
}

private static final List<String> DEFAULT_TEMPERATURE_MODIFIER_ORDER = ImmutableList.of(BuiltInTemperatureModifier.PLAYER_MODIFIERS, BuiltInTemperatureModifier.ITEM_MODIFIER, BuiltInTemperatureModifier.ARMOR_MODIFIER)
private static final List<String> DEFAULT_TEMPERATURE_MODIFIER_ORDER = ImmutableList.of(BuiltInTemperatureModifier.PLAYER_MODIFIERS, BuiltInTemperatureModifier.ITEM_MODIFIER, BuiltInTemperatureModifier.ARMOR_MODIFIER, BuiltInTemperatureModifier.INTERNAL_MODIFIER)
.stream().map(e -> e.toString().toLowerCase()).toList();

private static final Predicate<List<String>> TEMPERATURE_MODIFIER_VALIDATOR = list -> {
final var allModifiers = Arrays.stream(BuiltInTemperatureModifier.values()).map(BuiltInTemperatureModifier::toString).toList();
return list.stream().allMatch(s -> allModifiers.stream().anyMatch(s::equalsIgnoreCase));
Set<String> configEntries = list.stream().map(String::toLowerCase).collect(Collectors.toSet());
Set<String> allModifiers = Arrays.stream(BuiltInTemperatureModifier.values()).map(m -> m.toString().toLowerCase()).collect(Collectors.toSet());
return configEntries.containsAll(allModifiers) && allModifiers.containsAll(configEntries);
};

@Override
Expand All @@ -69,10 +75,12 @@ public void load()
armorTemperatureChangeDelay = addNumber("general.armor_temperature_change_delay", 50, 0, Integer.MAX_VALUE, "Number of ticks to delay changing the player's temperature after their temperature changes when wearing armor.");
handheldTemperatureChangeDelay = addNumber("general.handheld_temperature_change_delay", 375, 0, Integer.MAX_VALUE, "Number of ticks to delay changing the player's temperature after their temperature changes when holding an item.");
playerTemperatureChangeDelay = addNumber("general.player_temperature_change_delay", 125, 0, Integer.MAX_VALUE, "Number of ticks to delay changing the player's temperature after their temperature changes when affected by a player-based temperature modifier.");
internalTemperatureChangeDelay = addNumber("general.internal_temperature_change_delay", 20, 0, Integer.MAX_VALUE, "Number of ticks to delay changing the player's temperature after their temperature changes from consuming a heating or cooling item.");
extremityReboundTemperatureChangeDelay = addNumber("general.extremity_rebound_temperature_change_delay", 250, 0, Integer.MAX_VALUE, "Number of ticks to delay changing the player's temperature after their temperature changes when rebounding from an extreme temperature.");
extremityDamageDelay = addNumber("general.extremity_damage_delay", 500, 0, Integer.MAX_VALUE, "Number of ticks to delay taking damage when icy or hot.");
climateClemencyDuration = addNumber("general.climate_clemency_duration", 6000, 0, Integer.MAX_VALUE, "Number of ticks for the duration of Climate Clemency.");
climateClemencyRespawning = add("general.climate_clemency_respawning", false, "Whether or not Climate Clemency should be granted when respawning.");
consumableEffectDuration = add("general.consumable_effect_duration", 600, "Duration of heating or cooling effects given by consuming items.");
temperatureModifierOrder = add("general.temperature_modifier_order", DEFAULT_TEMPERATURE_MODIFIER_ORDER, "The order in which to apply built-in temperature modifiers", TEMPERATURE_MODIFIER_VALIDATOR);

// Altitude options
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/toughasnails/core/ToughAsNails.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private static void addHandlers()
{
// Temperature handlers
EventManager.addListener(TemperatureHandler::onChangeDimension);
EventManager.addListener(TemperatureHandler::onItemUseFinish);

// Thirst handlers
EventManager.addListener(ThirstHandler::onChangeDimension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.entity.player.Player;
import toughasnails.api.temperature.IPlayerTemperatureModifier;
import toughasnails.api.temperature.TemperatureLevel;
import toughasnails.core.ToughAsNails;
import toughasnails.init.ModConfig;

import java.util.List;
Expand Down Expand Up @@ -37,6 +38,12 @@ public enum BuiltInTemperatureModifier
TemperatureLevel newTarget = TemperatureHelperImpl.armorModifier(player, currentTarget);
if (newTarget != currentTarget) newChangeDelay = Math.min(currentChangeDelay, ModConfig.temperature.armorTemperatureChangeDelay);
return new Tuple<>(newTarget, newChangeDelay);
}),
INTERNAL_MODIFIER((player, currentTarget, currentChangeDelay) -> {
int newChangeDelay = currentChangeDelay;
TemperatureLevel newTarget = TemperatureHelperImpl.internalModifier(player, currentTarget);
if (newTarget != currentTarget) newChangeDelay = Math.min(currentChangeDelay, ModConfig.temperature.internalTemperatureChangeDelay);
return new Tuple<>(newTarget, newChangeDelay);
});

private final Modifier modifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
******************************************************************************/
package toughasnails.temperature;

import glitchcore.event.entity.LivingEntityUseItemEvent;
import glitchcore.event.player.PlayerEvent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.util.Tuple;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import toughasnails.api.damagesource.TANDamageTypes;
import toughasnails.api.potion.TANEffects;
import toughasnails.api.temperature.ITemperature;
import toughasnails.api.temperature.TemperatureHelper;
import toughasnails.api.temperature.TemperatureLevel;
import toughasnails.core.ToughAsNails;
import toughasnails.init.ModConfig;
import toughasnails.init.ModPackets;
import toughasnails.init.ModTags;
import toughasnails.network.UpdateTemperaturePacket;

import java.util.UUID;
Expand Down Expand Up @@ -146,6 +151,21 @@ public static void onChangeDimension(PlayerEvent.ChangeDimension event)
temperature.setLastHyperthermiaTicks(0);
}

public static void onItemUseFinish(LivingEntityUseItemEvent.Finish event)
{
if (!ModConfig.temperature.enableTemperature || !(event.getEntity() instanceof Player) || event.getEntity().level().isClientSide())
return;

Player player = (Player) event.getEntity();
ItemStack item = event.getItem();

if (item.is(ModTags.Items.COOLING_CONSUMED_ITEMS))
player.addEffect(new MobEffectInstance(TANEffects.INTERNAL_CHILL, ModConfig.temperature.consumableEffectDuration));

if (item.is(ModTags.Items.HEATING_CONSUMED_ITEMS))
player.addEffect(new MobEffectInstance(TANEffects.INTERNAL_WARMTH, ModConfig.temperature.consumableEffectDuration));
}

public static void syncTemperature(ServerPlayer player)
{
ITemperature temperature = TemperatureHelper.getTemperatureData(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.world.level.block.state.BlockState;
import toughasnails.api.enchantment.TANEnchantments;
import toughasnails.api.player.ITANPlayer;
import toughasnails.api.potion.TANEffects;
import toughasnails.api.temperature.*;
import toughasnails.api.temperature.IProximityBlockModifier.Type;
import toughasnails.init.ModConfig;
Expand Down Expand Up @@ -360,6 +361,21 @@ protected static TemperatureLevel armorModifier(Player player, TemperatureLevel
return current;
}

protected static TemperatureLevel internalModifier(Player player, TemperatureLevel current)
{
TemperatureLevel newTemperature = current;

if (player.hasEffect(TANEffects.INTERNAL_WARMTH)) newTemperature = newTemperature.increment(1);
if (player.hasEffect(TANEffects.INTERNAL_CHILL)) newTemperature = newTemperature.decrement(1);

// Prevent internal effects from sending players into extremities
if (newTemperature == TemperatureLevel.HOT && current != TemperatureLevel.HOT) current = newTemperature.decrement(1);
else if (newTemperature == TemperatureLevel.ICY && current != TemperatureLevel.ICY) current = newTemperature.increment(1);
else current = newTemperature;

return current;
}

private static boolean coldEnoughToSnow(Level level, Holder<Biome> biome, BlockPos pos)
{
return biome.value().coldEnoughToSnow(pos);
Expand Down
5 changes: 1 addition & 4 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,10 @@ curseforge {

mainArtifact(remapJar) {
displayName = "${mod_display_name} ${name} ${version}"

relations {
requiredDependency "fabric-api"
}
}

relations {
requiredDependency 'fabric-api'
requiredDependency 'glitchcore'
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ org.gradle.daemon=false

# Dependencies
nightconfig_version=3.6.7
glitchcore_version=1.0.0.27
glitchcore_version=1.0.0.31
serene_seasons_version=9.3.0.0

0 comments on commit 92b4087

Please sign in to comment.