-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement entity predicate, and migrate spilling effects to use it
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
1 parent
db5a9b2
commit 2c97314
Showing
24 changed files
with
450 additions
and
203 deletions.
There are no files selected for viewing
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
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
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
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
44 changes: 44 additions & 0 deletions
44
src/main/java/slimeknights/tconstruct/library/json/predicate/TagPredicateLoader.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,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()); | ||
} | ||
} |
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
Oops, something went wrong.