Skip to content

Commit

Permalink
soaked loot condition type
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeathlyCow committed Apr 13, 2024
1 parent 108f1bc commit 837caeb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.github.thedeathlycow.thermoo.api.predicate;

import com.github.thedeathlycow.thermoo.api.temperature.Soakable;
import com.github.thedeathlycow.thermoo.api.temperature.TemperatureAware;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.loot.condition.LootCondition;
import net.minecraft.loot.condition.LootConditionType;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.predicate.NumberRange;

public record SoakedLootCondition(
NumberRange.IntRange value,
NumberRange.DoubleRange scale
) implements LootCondition {

public static final Codec<SoakedLootCondition> CODEC = RecordCodecBuilder.create(
instance -> instance.group(
NumberRange.IntRange.CODEC
.fieldOf("value")
.orElse(NumberRange.IntRange.ANY)
.forGetter(SoakedLootCondition::value),
NumberRange.DoubleRange.CODEC
.fieldOf("scale")
.orElse(NumberRange.DoubleRange.ANY)
.forGetter(SoakedLootCondition::scale)
).apply(instance, SoakedLootCondition::new)
);

@Override
public LootConditionType getType() {
return ThermooLootConditionTypes.SOAKED;
}

@Override
public boolean test(LootContext lootContext) {
Entity entity = lootContext.get(LootContextParameters.THIS_ENTITY);
if (entity instanceof Soakable soakable) {
return this.value.test(soakable.thermoo$getWetTicks())
&& this.scale.test(soakable.thermoo$getSoakedScale());
}

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class ThermooLootConditionTypes {


public static final LootConditionType TEMPERATURE = new LootConditionType(TemperatureLootCondition.CODEC);
public static final LootConditionType SOAKED = new LootConditionType(SoakedLootCondition.CODEC);

private ThermooLootConditionTypes() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static void registerAttributes() {

public static void registerLootConditionTypes() {
registerLootConditionType("temperature", ThermooLootConditionTypes.TEMPERATURE);
registerLootConditionType("soaked", ThermooLootConditionTypes.SOAKED);
}

private static void registerAttribute(String name, EntityAttribute attribute) {
Expand Down

0 comments on commit 837caeb

Please sign in to comment.