Skip to content

Commit 65c6943

Browse files
committed
final v0.5 touches
adds NOT and FORWARD for you're convenience
1 parent bce7a70 commit 65c6943

7 files changed

Lines changed: 76 additions & 66 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ Note: `"SUCCESS"` refers to `ActionResult.CONSUME` when running on the server an
165165
|------------------------|---------|----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
166166
| `"FORCE_SWING_HAND"` | v0.3.0+ | Always returns `"SUCCESS"` | `quickfail` can be used to cause failure still |
167167
| `"PASS"` | v0.5.0+ | Always returns `"PASS"` | |
168+
| `"FORWARD"` | v0.5.0+ | Returns the previous return value, useful for templates | |
168169
| `"INVERT_COND"` | v0.3.0+ | Inverts the previous return value, `"SUCCESS"` becomes `"PASS"` and vice versa | `quickfail` can be used still |
169170
| `"AND"` | v0.5.0+ | Returns `"SUCCESS"` when ALL condition effect returns `"SUCCESS"` | `"conditions"`: JsonArray of effects to check the result of. `"short_circuit"`: (Optional = true) Boolean - if true, will stop evaluating conditions when any return `"PASS"` | |
170171
| `"OR"` | v0.5.0+ | Returns `"SUCCESS"` when ANY condition effect returns `"SUCCESS"` | `"conditions"`: JsonArray of effects to check the result of. `"short_circuit"`: (Optional = true) Boolean - if true, will stop evaluating conditions when any return `"SUCESS"` |
172+
| `"NOT"` | v0.5.0+ | Inverts the return value of the condition effect | `"condition"`: JsonObject - effect to invert result of. | |
171173
| `"IS_FROM_VANILLA"` | v0.3.0+ | Returns `"SUCCESS"` when the block is from vanilla | `quickfail` can be used still |
172174
| `"HAS_LEVEL"` | v0.3.0+ | Returns `"SUCCESS"` when the cauldron contains fluid | `"level"`: (Optional) integer - only returns `"SUCCESS"` if the fluid level is equal to this parameter |
173175
| `"HAS_HEAT"` | v0.3.0+ | Returns `"SUCCESS"` when the cauldron has a heat level more extreme then the parameter | `"heat"`: (Optional = 1) integer - heat level to compare against. When 0, cauldron heat must also be 0 |

src/main/java/net/sploder12/potioncraft/meta/parsers/RecipesParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static boolean parseBlockRecipes(JsonObject recipes, String blockId, Str
6161
return;
6262
}
6363

64-
parseBlockRecipes(behavior, recipes, id);
64+
parseBlockRecipes(behavior, recipes, id + "[" + Registries.BLOCK.getId(cauldronBlock) + "]");
6565
});
6666

6767
return true;

src/main/java/net/sploder12/potioncraft/meta/templates/Conditional.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public interface Conditional {
3131
// always returns "false"
3232
MetaEffectTemplate PASS = (params, file) -> (ActionResult prev, CauldronData data, World world, BlockPos pos, PlayerEntity player, Hand hand, ItemStack stack) -> ActionResult.PASS;
3333

34+
// always returns prev
35+
MetaEffectTemplate FORWARD = (params, file) -> (ActionResult prev, CauldronData data, World world, BlockPos pos, PlayerEntity player, Hand hand, ItemStack stack) -> prev;
36+
3437
// Predicate templates are useful for checking conditions!
3538

3639
MetaEffectTemplate INVERT_COND = (params, file) -> (ActionResult prev, CauldronData data, World world, BlockPos pos, PlayerEntity player, Hand hand, ItemStack stack) -> {
@@ -117,6 +120,28 @@ public interface Conditional {
117120
};
118121
};
119122

123+
MetaEffectTemplate NOT = (params, file) -> {
124+
JsonElement conditionE = params.get("condition");
125+
if (conditionE == null || !conditionE.isJsonObject()) {
126+
Main.warn("NOT has no condition! " + file);
127+
return PASS.apply(params, file);
128+
}
129+
130+
MetaEffect effect = EffectParser.parseEffect(conditionE.getAsJsonObject(), file + "-condition");
131+
if (effect == null) {
132+
return PASS.apply(params, file);
133+
}
134+
135+
return (ActionResult prev, CauldronData data, World world, BlockPos pos, PlayerEntity player, Hand hand, ItemStack stack) -> {
136+
ActionResult res = effect.interact(prev, data, world, pos, player, hand, stack);
137+
if (res == ActionResult.PASS) {
138+
return ActionResult.success(world.isClient);
139+
}
140+
141+
return ActionResult.PASS;
142+
};
143+
};
144+
120145
MetaEffectTemplate IS_FROM_VANILLA = (params, file) -> (ActionResult prev, CauldronData data, World world, BlockPos pos, PlayerEntity player, Hand hand, ItemStack stack) -> {
121146
if (Registries.BLOCK.getId(data.source).getNamespace().equalsIgnoreCase("minecraft")) {
122147
return ActionResult.success(world.isClient);

src/main/java/net/sploder12/potioncraft/meta/templates/CustomTemplate.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ protected CustomTemplate(JsonArray arr, String name) {
7373
}
7474

7575
public MetaEffect apply(JsonObject params, String file) {
76-
final String fileLocation = file + "-" + name;
76+
final String fileLocation = file;
7777

7878
try {
7979
parameters.forEach((String id, ParameterEntry entry) -> {
8080
JsonElement elem = params.get(id);
8181

82-
entry.apply(elem, fileLocation);
82+
entry.apply(elem, fileLocation + "-" + id);
8383
});
8484

8585
final Collection<MetaEffect> effects = EffectParser.parseEffects(this.effects, fileLocation);
@@ -147,7 +147,7 @@ else if (element.isJsonPrimitive()) {
147147
public static CustomTemplate parse(JsonObject template, String name, String file) {
148148
JsonElement effectsE = template.get("effects");
149149

150-
if (effectsE.isJsonArray()) {
150+
if (effectsE != null && effectsE.isJsonArray()) {
151151
JsonArray effects = effectsE.getAsJsonArray();
152152

153153
CustomTemplate out = new CustomTemplate(effects, name);
@@ -158,7 +158,7 @@ public static CustomTemplate parse(JsonObject template, String name, String file
158158

159159
JsonElement defaultsE = template.get("defaults");
160160

161-
if (defaultsE.isJsonObject()) {
161+
if (defaultsE != null && defaultsE.isJsonObject()) {
162162
JsonObject defaults = defaultsE.getAsJsonObject();
163163

164164
defaults.asMap().forEach((String arg, JsonElement defaultVal) -> {
@@ -177,6 +177,7 @@ public static CustomTemplate parse(JsonObject template, String name, String file
177177
return out;
178178
}
179179

180+
Main.warn("template " + name + " has no effects! " + file);
180181
return null;
181182
}
182183
}

src/main/java/net/sploder12/potioncraft/meta/templates/MetaEffectTemplate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ static void register() {
2222

2323
templates.put("FORCE_SWING_HAND", Conditional.FORCE_SWING_HAND);
2424
templates.put("PASS", Conditional.PASS);
25+
templates.put("FORWARD", Conditional.FORWARD);
2526
templates.put("INVERT_COND", Conditional.INVERT_COND);
2627

2728
templates.put("AND", Conditional.AND);
2829
templates.put("OR", Conditional.OR);
30+
templates.put("NOT", Conditional.NOT);
2931

3032
templates.put("IS_FROM_VANILLA", Conditional.IS_FROM_VANILLA);
3133
templates.put("HAS_LEVEL", Conditional.HAS_LEVEL);

src/main/java/net/sploder12/potioncraft/util/FluidHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public static void addFluidMapping(Fluid fluid, AbstractCauldronBlock cauldron)
9090
public static Fluid getStill(Fluid fluid) {
9191
Objects.requireNonNull(fluid, "Fluid may not be null.");
9292

93+
if (fluid == Fluids.EMPTY) return Fluids.EMPTY;
94+
9395
if (!fluid.isStill(fluid.getDefaultState())) {
9496
if (fluid instanceof FlowableFluid flowable) {
9597
return flowable.getStill();

src/main/resources/data/potioncraft/metamixing/data.json

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@
8181
}
8282
}
8383
]
84+
},
85+
86+
"add_potion_if_water": {
87+
"effects": [
88+
{
89+
"id": "${use_if_fluid}"
90+
},
91+
{
92+
"id": "ADD_POTION_EFFECT",
93+
"quickfail": "PASS",
94+
"params": {
95+
"id": "@{potion}"
96+
}
97+
}
98+
]
8499
}
85100
},
86101

@@ -90,13 +105,9 @@
90105
"potency": 1,
91106
"effects": [
92107
{
93-
"id": "${use_if_fluid}"
94-
},
95-
{
96-
"id": "ADD_POTION_EFFECT",
97-
"quickfail": "PASS",
108+
"id": "${add_potion_if_water}",
98109
"params": {
99-
"id": "swiftness"
110+
"potion": "swiftness"
100111
}
101112
}
102113
]
@@ -106,13 +117,9 @@
106117
"potency": 1,
107118
"effects": [
108119
{
109-
"id": "${use_if_fluid}"
110-
},
111-
{
112-
"id": "ADD_POTION_EFFECT",
113-
"quickfail": "PASS",
120+
"id": "${add_potion_if_water}",
114121
"params": {
115-
"id": "leaping"
122+
"potion": "leaping"
116123
}
117124
}
118125
]
@@ -122,13 +129,9 @@
122129
"potency": 1,
123130
"effects": [
124131
{
125-
"id": "${use_if_fluid}"
126-
},
127-
{
128-
"id": "ADD_POTION_EFFECT",
129-
"quickfail": "PASS",
132+
"id": "${add_potion_if_water}",
130133
"params": {
131-
"id": "healing"
134+
"potion": "healing"
132135
}
133136
}
134137
]
@@ -138,13 +141,9 @@
138141
"potency": 1,
139142
"effects": [
140143
{
141-
"id": "${use_if_fluid}"
142-
},
143-
{
144-
"id": "ADD_POTION_EFFECT",
145-
"quickfail": "PASS",
144+
"id": "${add_potion_if_water}",
146145
"params": {
147-
"id": "poison"
146+
"potion": "poison"
148147
}
149148
}
150149
]
@@ -154,13 +153,9 @@
154153
"potency": 1,
155154
"effects": [
156155
{
157-
"id": "${use_if_fluid}"
158-
},
159-
{
160-
"id": "ADD_POTION_EFFECT",
161-
"quickfail": "PASS",
156+
"id": "${add_potion_if_water}",
162157
"params": {
163-
"id": "water_breathing"
158+
"potion": "water_breathing"
164159
}
165160
}
166161
]
@@ -170,13 +165,9 @@
170165
"potency": 1,
171166
"effects": [
172167
{
173-
"id": "${use_if_fluid}"
174-
},
175-
{
176-
"id": "ADD_POTION_EFFECT",
177-
"quickfail": "PASS",
168+
"id": "${add_potion_if_water}",
178169
"params": {
179-
"id": "fire_resistance"
170+
"potion": "fire_resistance"
180171
}
181172
}
182173
]
@@ -186,13 +177,9 @@
186177
"potency": 1,
187178
"effects": [
188179
{
189-
"id": "${use_if_fluid}"
190-
},
191-
{
192-
"id": "ADD_POTION_EFFECT",
193-
"quickfail": "PASS",
180+
"id": "${add_potion_if_water}",
194181
"params": {
195-
"id": "night_vision"
182+
"potion": "night_vision"
196183
}
197184
}
198185
]
@@ -202,13 +189,9 @@
202189
"potency": 1,
203190
"effects": [
204191
{
205-
"id": "${use_if_fluid}"
206-
},
207-
{
208-
"id": "ADD_POTION_EFFECT",
209-
"quickfail": "PASS",
192+
"id": "${add_potion_if_water}",
210193
"params": {
211-
"id": "strength"
194+
"potion": "strength"
212195
}
213196
}
214197
]
@@ -218,13 +201,9 @@
218201
"potency": 1,
219202
"effects": [
220203
{
221-
"id": "${use_if_fluid}"
222-
},
223-
{
224-
"id": "ADD_POTION_EFFECT",
225-
"quickfail": "PASS",
204+
"id": "${add_potion_if_water}",
226205
"params": {
227-
"id": "regeneration"
206+
"potion": "regeneration"
228207
}
229208
}
230209
]
@@ -261,13 +240,9 @@
261240
"potency": 1,
262241
"effects": [
263242
{
264-
"id": "${use_if_fluid}"
265-
},
266-
{
267-
"id": "ADD_POTION_EFFECT",
268-
"quickfail": "PASS",
243+
"id": "${add_potion_if_water}",
269244
"params": {
270-
"id": "slow_falling"
245+
"potion": "slow_falling"
271246
}
272247
}
273248
]
@@ -515,7 +490,10 @@
515490
},
516491
{
517492
"id": "ADD_LEVEL",
518-
"quickfail": "PASS"
493+
"quickfail": "PASS",
494+
"params": {
495+
"fluid": "water"
496+
}
519497
},
520498
{
521499
"id": "APPLY_ITEM_EFFECTS",

0 commit comments

Comments
 (0)