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
73cc9a7
commit 7f3f9a3
Showing
7 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...a/com/github/thedeathlycow/thermoo/api/temperature/effects/SequenceTemperatureEffect.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,54 @@ | ||
package com.github.thedeathlycow.thermoo.api.temperature.effects; | ||
|
||
import com.google.gson.*; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.server.world.ServerWorld; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Applies multiple child temperature effects at once. Useful for when you want to apply several different temperature | ||
* effects under the same base set of conditions, without the overhead of checking those conditions multiple times. | ||
*/ | ||
public class SequenceTemperatureEffect extends TemperatureEffect<SequenceTemperatureEffect.Config> { | ||
|
||
@Override | ||
public void apply(LivingEntity victim, ServerWorld serverWorld, Config config) { | ||
for (ConfiguredTemperatureEffect<?> child : config.children()) { | ||
EntityType<?> childType = child.getEntityType(); | ||
if (childType == null || victim.getType() == childType) { | ||
child.applyIfPossible(victim); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean shouldApply(LivingEntity victim, Config config) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Config configFromJson(JsonElement json, JsonDeserializationContext context) throws JsonSyntaxException { | ||
return Config.fromJson(json, context); | ||
} | ||
|
||
public record Config(List<ConfiguredTemperatureEffect<?>> children) { | ||
|
||
public static Config fromJson(JsonElement json, JsonDeserializationContext context) throws JsonSyntaxException { | ||
JsonObject object = json.getAsJsonObject(); | ||
|
||
JsonArray jsonChildren = object.get("children").getAsJsonArray(); | ||
List<ConfiguredTemperatureEffect<?>> children = new ArrayList<>(jsonChildren.size()); | ||
for (JsonElement jsonChild : jsonChildren) { | ||
ConfiguredTemperatureEffect<?> child = context.deserialize(jsonChild, ConfiguredTemperatureEffect.class); | ||
children.add(child); | ||
} | ||
|
||
return new Config(children); | ||
} | ||
|
||
} | ||
|
||
} |
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
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
11 changes: 11 additions & 0 deletions
11
src/testmod/resources/data/thermoo-test/predicates/is_cold.json
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,11 @@ | ||
{ | ||
"condition": "minecraft:entity_properties", | ||
"entity": "this", | ||
"predicate": { | ||
"thermoo.temperature": { | ||
"scale": { | ||
"max": 0 | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/testmod/resources/data/thermoo-test/predicates/is_warm.json
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,11 @@ | ||
{ | ||
"condition": "minecraft:entity_properties", | ||
"entity": "this", | ||
"predicate": { | ||
"thermoo.temperature": { | ||
"scale": { | ||
"min": 0 | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/testmod/resources/data/thermoo-test/thermoo/temperature_effects/sequence_test.json
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,36 @@ | ||
{ | ||
"type": "thermoo:sequence", | ||
"entity": { | ||
"condition": "minecraft:reference", | ||
"name": "thermoo-test:is_warm" | ||
}, | ||
"config": { | ||
"children": [ | ||
{ | ||
"type": "thermoo:damage", | ||
"entity_type": "minecraft:player", | ||
"config": { | ||
"amount": 1, | ||
"damage_interval": 20, | ||
"damage_type": "minecraft:in_fire" | ||
} | ||
}, | ||
{ | ||
"type": "thermoo:status_effect", | ||
"entity": { | ||
"condition": "minecraft:reference", | ||
"name": "thermoo-test:is_cold" | ||
}, | ||
"config": { | ||
"effects": [ | ||
{ | ||
"amplifier": 0, | ||
"duration": 200, | ||
"effect": "minecraft:nausea" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} |