Skip to content

Commit

Permalink
Implement entity predicate, and migrate spilling effects to use it
Browse files Browse the repository at this point in the history
Instead of just damage effects supporting entity predicates, now have a new conditional spilling effect to nest it on any effect type
  • Loading branch information
KnightMiner committed Apr 15, 2022
1 parent db5a9b2 commit 2c97314
Show file tree
Hide file tree
Showing 24 changed files with 450 additions and 203 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ forge_range=[40.0.41,)
parchment_version=2022.03.13

# Build Dependencies
mantle_version=1.9.11
mantle_range=1.9.11,)
mantle_version=1.9.14
mantle_range=1.9.14,)

# Optional compat
jei_version=9.5.3.153
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
},
"effects": [
{
"type": "tconstruct:damage",
"entity": "not_fire_immune",
"damage_type": "fire",
"damage_amount": 3.0
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:inverted",
"predicate": {
"type": "tconstruct:fire_immune"
}
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "fire",
"damage_amount": 3.0
}
},
{
"type": "tconstruct:set_fire",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
},
"effects": [
{
"type": "tconstruct:damage",
"entity": "not_fire_immune",
"damage_type": "fire",
"damage_amount": 1.5
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:inverted",
"predicate": {
"type": "tconstruct:fire_immune"
}
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "fire",
"damage_amount": 1.5
}
},
{
"type": "tconstruct:set_fire",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
},
"effects": [
{
"type": "tconstruct:damage",
"entity": "not_fire_immune",
"damage_type": "fire",
"damage_amount": 1.0
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:inverted",
"predicate": {
"type": "tconstruct:fire_immune"
}
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "fire",
"damage_amount": 1.0
}
},
{
"type": "tconstruct:set_fire",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
},
"effects": [
{
"type": "tconstruct:damage",
"entity": "not_fire_immune",
"damage_type": "fire",
"damage_amount": 2.0
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:inverted",
"predicate": {
"type": "tconstruct:fire_immune"
}
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "fire",
"damage_amount": 2.0
}
},
{
"type": "tconstruct:set_fire",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
},
"effects": [
{
"type": "tconstruct:damage",
"entity": "not_fire_immune",
"damage_type": "fire",
"damage_amount": 2.0
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:inverted",
"predicate": {
"type": "tconstruct:fire_immune"
}
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "fire",
"damage_amount": 2.0
}
},
{
"type": "tconstruct:set_fire",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
},
"effects": [
{
"type": "tconstruct:damage",
"entity": "not_fire_immune",
"damage_type": "fire",
"damage_amount": 1.5
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:inverted",
"predicate": {
"type": "tconstruct:fire_immune"
}
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "fire",
"damage_amount": 1.5
}
},
{
"type": "tconstruct:set_fire",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
},
"effects": [
{
"type": "tconstruct:damage",
"entity": "not_fire_immune",
"damage_type": "fire",
"damage_amount": 2.5
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:inverted",
"predicate": {
"type": "tconstruct:fire_immune"
}
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "fire",
"damage_amount": 2.5
}
},
{
"type": "tconstruct:set_fire",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
},
"effects": [
{
"type": "tconstruct:damage",
"damage_type": "magic",
"damage_amount": 2.0
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:mob_type",
"mobs": "minecraft:undead"
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "magic",
"damage_amount": 2.0
}
},
{
"type": "tconstruct:set_fire",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
},
"effects": [
{
"type": "tconstruct:damage",
"entity": "not_fire_immune",
"damage_type": "fire",
"damage_amount": 1.5
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:inverted",
"predicate": {
"type": "tconstruct:fire_immune"
}
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "fire",
"damage_amount": 1.5
}
},
{
"type": "tconstruct:effect",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
},
"effects": [
{
"type": "tconstruct:damage",
"entity": "water_sensitive",
"damage_type": "piercing",
"damage_amount": 2.0
"type": "tconstruct:conditional",
"entity": {
"type": "tconstruct:water_sensitive"
},
"effect": {
"type": "tconstruct:damage",
"damage_type": "piercing",
"damage_amount": 2.0
}
},
{
"type": "tconstruct:extinguish"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.GsonHelper;
import slimeknights.mantle.data.GenericLoaderRegistry;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;

Expand Down Expand Up @@ -40,7 +39,7 @@ public InvertedJsonPredicate<I> create(IJsonPredicate<I> predicate) {

@Override
public InvertedJsonPredicate<I> deserialize(JsonObject json) {
return create(loader.deserialize(GsonHelper.getAsJsonObject(json, "predicate")));
return create(loader.getAndDeserialize(json, "predicate"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package slimeknights.tconstruct.library.json.predicate;

import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.util.JsonHelper;

import java.util.function.Function;

/**
* Generic loader for a tag based JSON predicate
* @param <T> Tag registry key
* @param <C> Constructor for the predicate
*/
@RequiredArgsConstructor
public class TagPredicateLoader<T,C extends IJsonPredicate<?>> implements IGenericLoader<C> {
private final ResourceKey<? extends Registry<T>> registry;
private final Function<TagKey<T>,C> constructor;
private final Function<C,TagKey<T>> getter;

@Override
public C deserialize(JsonObject json) {
return constructor.apply(TagKey.create(registry, JsonHelper.getResourceLocation(json, "tag")));
}

@Override
public C fromNetwork(FriendlyByteBuf buffer) {
return constructor.apply(TagKey.create(registry, buffer.readResourceLocation()));
}

@Override
public void serialize(C object, JsonObject json) {
json.addProperty("tag", getter.apply(object).location().toString());
}

@Override
public void toNetwork(C object, FriendlyByteBuf buffer) {
buffer.writeResourceLocation(getter.apply(object).location());
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package slimeknights.tconstruct.library.json.predicate.block;

import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.util.JsonHelper;
import slimeknights.tconstruct.library.json.predicate.TagPredicateLoader;

/**
* Modifier matching a tag
* Modifier matching a block tag
*/
@RequiredArgsConstructor
public class TagBlockPredicate implements BlockPredicate {
public static final TagPredicateLoader<Block,TagBlockPredicate> LOADER = new TagPredicateLoader<>(Registry.BLOCK_REGISTRY, TagBlockPredicate::new, c -> c.tag);
private final TagKey<Block> tag;

@Override
Expand All @@ -26,29 +25,4 @@ public boolean matches(BlockState state) {
public IGenericLoader<? extends BlockPredicate> getLoader() {
return LOADER;
}

/**
* Loader for this predicate
*/
public static final IGenericLoader<TagBlockPredicate> LOADER = new IGenericLoader<>() {
@Override
public TagBlockPredicate deserialize(JsonObject json) {
return new TagBlockPredicate(TagKey.create(Registry.BLOCK_REGISTRY, JsonHelper.getResourceLocation(json, "tag")));
}

@Override
public TagBlockPredicate fromNetwork(FriendlyByteBuf buffer) {
return new TagBlockPredicate(TagKey.create(Registry.BLOCK_REGISTRY, buffer.readResourceLocation()));
}

@Override
public void serialize(TagBlockPredicate object, JsonObject json) {
json.addProperty("tag", object.tag.location().toString());
}

@Override
public void toNetwork(TagBlockPredicate object, FriendlyByteBuf buffer) {
buffer.writeResourceLocation(object.tag.location());
}
};
}

0 comments on commit 2c97314

Please sign in to comment.