Skip to content

Commit 55b43ed

Browse files
authored
fix animator (#358)
1 parent 2b08f85 commit 55b43ed

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

examples/postInit/thebetweenlands.groovy

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ log.info 'mod \'thebetweenlands\' detected, running script'
66

77
// Animator:
88
// Converts an input item, Life amount from Life Crystals, and Fuel from Sulfur into an output itemstack, summoning an
9-
// entity, a random item from a loottable, or summoning an entity and outputting an itemstack.
9+
// entity, or a random item from a loottable.
1010

1111
mods.thebetweenlands.animator.removeByEntity(entity('thebetweenlands:sporeling'))
1212
mods.thebetweenlands.animator.removeByInput(item('thebetweenlands:bone_leggings'))
@@ -35,14 +35,6 @@ mods.thebetweenlands.animator.recipeBuilder()
3535
.fuel(5)
3636
.register()
3737

38-
mods.thebetweenlands.animator.recipeBuilder()
39-
.input(item('minecraft:diamond'))
40-
.entity(entity('minecraft:enderman'))
41-
.output(item('minecraft:clay'))
42-
.life(3)
43-
.fuel(10)
44-
.register()
45-
4638

4739
// Compost:
4840
// Converts an input itemstack into an amount of compost.

src/main/java/com/cleanroommc/groovyscript/compat/mods/betweenlands/Animator.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class Animator extends StandardListRegistry<IAnimatorRecipe> {
3131
@Example(".input(item('minecraft:clay')).output(item('minecraft:diamond')).life(1).fuel(1)"),
3232
@Example(".input(item('minecraft:gold_ingot')).lootTable(resource('minecraft:entities/zombie')).life(5).fuel(1)"),
3333
@Example(".input(item('minecraft:gold_block')).entity(entity('minecraft:zombie').getEntityClass()).life(1).fuel(5)"),
34-
@Example(".input(item('minecraft:diamond')).entity(entity('minecraft:enderman')).output(item('minecraft:clay')).life(3).fuel(10)"),
3534
})
3635
public RecipeBuilder recipeBuilder() {
3736
return new RecipeBuilder();
@@ -68,16 +67,16 @@ public boolean removeByEntity(EntityEntry entity) {
6867
}
6968

7069
@Property(property = "input", comp = @Comp(eq = 1))
71-
@Property(property = "output", comp = @Comp(eq = 1))
70+
@Property(property = "output", comp = @Comp(gte = 0, lte = 1, unique = "groovyscript.wiki.thebetweenlands.animator.pick_one.required"))
7271
public static class RecipeBuilder extends AbstractRecipeBuilder<IAnimatorRecipe> {
7372

7473
@Property(comp = @Comp(gte = 0))
7574
private int life;
7675
@Property(comp = @Comp(gte = 0))
7776
private int fuel;
78-
@Property
77+
@Property(comp = @Comp(unique = "groovyscript.wiki.thebetweenlands.animator.pick_one.required"))
7978
private ResourceLocation lootTable;
80-
@Property
79+
@Property(comp = @Comp(unique = "groovyscript.wiki.thebetweenlands.animator.pick_one.required"))
8180
private Class<? extends Entity> entity;
8281
@Property
8382
private ResourceLocation render;
@@ -135,10 +134,10 @@ public void validate(GroovyLog.Msg msg) {
135134
msg.add(life < 0, "life must be a positive integer greater than 0, yet it was {}", life);
136135
msg.add(fuel < 0, "fuel must be a positive integer greater than 0, yet it was {}", fuel);
137136
if (lootTable != null) {
138-
validateCustom(msg, output, 0, 0, "item output");
139137
msg.add(entity != null, "entity was defined even though lootTable was defined");
140138
msg.add(!output.isEmpty(), "output was defined even though lootTable was defined");
141139
}
140+
msg.add(!output.isEmpty() && entity != null, "both entity and output were defined, yet only one can be");
142141
msg.add(output.isEmpty() && lootTable == null && entity == null, "output, lootTable, and entity were all not defined. one of them should be defined to properly create the recipe");
143142
}
144143

@@ -168,21 +167,17 @@ public void validate(GroovyLog.Msg msg) {
168167
ModSupport.BETWEENLANDS.get().animator.add(recipe);
169168
}
170169
} else if (entity != null) {
171-
if (output.isEmpty()) {
172-
for (var stack : input.get(0).getMatchingStacks()) {
173-
recipe = new AnimatorRecipe(stack, fuel, life, entity);
174-
recipe.setRenderEntity(render);
175-
ModSupport.BETWEENLANDS.get().animator.add(recipe);
176-
}
177-
} else {
178-
for (var stack : input.get(0).getMatchingStacks()) {
179-
recipe = new AnimatorRecipe(stack, fuel, life, output.get(0), entity);
180-
recipe.setRenderEntity(render);
181-
ModSupport.BETWEENLANDS.get().animator.add(recipe);
182-
}
170+
for (var stack : input.get(0).getMatchingStacks()) {
171+
recipe = new AnimatorRecipe(stack, fuel, life, entity);
172+
recipe.setRenderEntity(render);
173+
ModSupport.BETWEENLANDS.get().animator.add(recipe);
174+
}
175+
} else {
176+
for (var stack : input.get(0).getMatchingStacks()) {
177+
recipe = new AnimatorRecipe(stack, fuel, life, output.get(0));
178+
ModSupport.BETWEENLANDS.get().animator.add(recipe);
183179
}
184180
}
185-
ModSupport.BETWEENLANDS.get().animator.add(recipe);
186181
return recipe;
187182
}
188183
}

src/main/resources/assets/groovyscript/lang/en_us.lang

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,13 @@ groovyscript.wiki.betterwithmods.turntable.outputBlock.value=Sets the blockstate
776776

777777
# The Betweenlands
778778
groovyscript.wiki.thebetweenlands.animator.title=Animator
779-
groovyscript.wiki.thebetweenlands.animator.description=Converts an input item, Life amount from Life Crystals, and Fuel from Sulfur into an output itemstack, summoning an entity, a random item from a loottable, or summoning an entity and outputting an itemstack.
779+
groovyscript.wiki.thebetweenlands.animator.description=Converts an input item, Life amount from Life Crystals, and Fuel from Sulfur into an output itemstack, summoning an entity, or a random item from a loottable.
780780
groovyscript.wiki.thebetweenlands.animator.fuel.value=Sets the fuel consumed
781781
groovyscript.wiki.thebetweenlands.animator.life.value=Sets the life consumed from the life crystal
782782
groovyscript.wiki.thebetweenlands.animator.entity.value=Sets the entity being spawned
783783
groovyscript.wiki.thebetweenlands.animator.render.value=Sets the entity to render, typically the same as the entity to be spawned
784784
groovyscript.wiki.thebetweenlands.animator.lootTable.value=Sets the LootTable used to generate outputs
785+
groovyscript.wiki.thebetweenlands.animator.pick_one.required=Only one of output, entity, or lootTable can be set
785786
groovyscript.wiki.thebetweenlands.animator.removeByEntity=Removes all entries that match the given entity
786787
groovyscript.wiki.thebetweenlands.animator.removeByLootTable=Removes all entries that output the given Loot Table
787788

0 commit comments

Comments
 (0)