generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
108f1bc
commit 837caeb
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/com/github/thedeathlycow/thermoo/api/predicate/SoakedLootCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters