Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void onInitialize() {
FAttributeTypes.initialize();
FEnvironmentAttributes.initialize();
FBlockTransformerTypes.initialize();
FEnvironmentProviderTypes.initialize();

ServerLivingEntityEvents.AFTER_DAMAGE.register(FrostWandRootComponent::afterDamage);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.thedeathlycow.frostiful.registry;

import com.github.thedeathlycow.frostiful.Frostiful;
import com.github.thedeathlycow.frostiful.survival.environment.EnsureTemperatureBelow;
import com.github.thedeathlycow.frostiful.survival.environment.IfSnowy;
import com.github.thedeathlycow.thermoo.api.ThermooRegistries;
import com.github.thedeathlycow.thermoo.api.environment.provider.EnvironmentProvider;
import com.github.thedeathlycow.thermoo.api.environment.provider.EnvironmentProviderType;
import net.minecraft.core.Registry;

public final class FEnvironmentProviderTypes {
public static final EnvironmentProviderType<IfSnowy> IF_SNOWY = register(
"if_snowy",
new EnvironmentProviderType<>(IfSnowy.CODEC)
);

public static final EnvironmentProviderType<EnsureTemperatureBelow> ENSURE_TEMPERATURE_BELOW = register(
"ensure_temperature_below",
new EnvironmentProviderType<>(EnsureTemperatureBelow.CODEC)
);

public static void initialize() {
Frostiful.LOGGER.debug("Initialized Frostiful environment provider types");
}

private static <T extends EnvironmentProvider> EnvironmentProviderType<T> register(
String name,
EnvironmentProviderType<T> type
) {
return Registry.register(ThermooRegistries.ENVIRONMENT_PROVIDER_TYPE, Frostiful.id(name), type);
}

private FEnvironmentProviderTypes() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.github.thedeathlycow.frostiful.survival.environment;

import com.github.thedeathlycow.frostiful.registry.FEnvironmentProviderTypes;
import com.github.thedeathlycow.thermoo.api.environment.component.EnvironmentComponentTypes;
import com.github.thedeathlycow.thermoo.api.environment.component.TemperatureRecordComponent;
import com.github.thedeathlycow.thermoo.api.environment.provider.EnvironmentProvider;
import com.github.thedeathlycow.thermoo.api.environment.provider.EnvironmentProviderType;
import com.github.thedeathlycow.thermoo.api.util.TemperatureRecord;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;

public record EnsureTemperatureBelow(
TemperatureRecord value
) implements EnvironmentProvider {
public static final MapCodec<EnsureTemperatureBelow> CODEC = RecordCodecBuilder.mapCodec(
instance -> instance.group(
TemperatureRecord.CODEC
.fieldOf("value")
.forGetter(EnsureTemperatureBelow::value)
).apply(instance, EnsureTemperatureBelow::new)
);

@Override
public void buildCurrentComponents(Level level, BlockPos pos, Holder<Biome> biome, DataComponentMap.Builder builder) {
TemperatureRecord temperature = builder.getOrDefault(
EnvironmentComponentTypes.TEMPERATURE,
TemperatureRecordComponent.DEFAULT
);

if (this.value.compareTo(temperature) < 0) {
builder.set(EnvironmentComponentTypes.TEMPERATURE, this.value);
}
}

@Override
public EnvironmentProviderType<EnsureTemperatureBelow> getType() {
return FEnvironmentProviderTypes.ENSURE_TEMPERATURE_BELOW;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.github.thedeathlycow.frostiful.survival.environment;

import com.github.thedeathlycow.frostiful.registry.FEnvironmentProviderTypes;
import com.github.thedeathlycow.thermoo.api.environment.provider.EnvironmentProvider;
import com.github.thedeathlycow.thermoo.api.environment.provider.EnvironmentProviderType;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;

public record IfSnowy(
Holder<EnvironmentProvider> whenTrue
) implements EnvironmentProvider {
public static final MapCodec<IfSnowy> CODEC = RecordCodecBuilder.mapCodec(
instance -> instance.group(
EnvironmentProvider.HOLDER_CODEC
.fieldOf("when_true")
.forGetter(IfSnowy::whenTrue)
).apply(instance, IfSnowy::new)
);

@Override
public void buildCurrentComponents(Level level, BlockPos pos, Holder<Biome> biome, DataComponentMap.Builder builder) {
if (isSnowy(level, pos, biome)) {
whenTrue.value().buildCurrentComponents(level, pos, biome, builder);
}
}

@Override
public EnvironmentProviderType<IfSnowy> getType() {
return FEnvironmentProviderTypes.IF_SNOWY;
}

private static boolean isSnowy(Level level, BlockPos pos, Holder<Biome> biomeHolder) {
Biome biome = biomeHolder.value();

return biome.getBaseTemperature() < 0.15f
|| biome.getPrecipitationAt(pos, level.getSeaLevel()) == Biome.Precipitation.SNOW;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"replace": false,
"values": [
"frostiful:modifier/check_snowy",
"frostiful:modifier/sun_light"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"biomes": "#c:is_overworld",
"exclude_biomes": "#frostiful:is_not_climate/temperate",
"priority": 900,
"provider": {
"type": "frostiful:if_snowy",
"when_true": {
"type": "thermoo:modify",
"modifiers": "#frostiful:temperature_modifiers",
"base": {
"type": "thermoo:constant",
"components": {}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "frostiful:if_snowy",
"when_true": {
"type": "frostiful:ensure_temperature_below",
"value": -5
}
}