Skip to content

Commit

Permalink
Rearrange some data generator code to make it clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Dec 30, 2019
1 parent 5fbb00e commit ef95761
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 46 deletions.
Expand Up @@ -205,17 +205,11 @@ public ShapedBuilder textureMatchFirst() {

@Override
public void build(Consumer<IFinishedRecipe> consumer, ResourceLocation recipeLoc) {
// Capture the finished recipe which will be sent to the consumer.
final IFinishedRecipe[] output = {null};
super.build((res) -> output[0] = res, recipeLoc);

// It should have been called immediately.
assert output[0] != null;
// Then wrap.
consumer.accept(textureSource != null ?
new FinishedTexture(recipeLoc, output[0], mirror, textureSource, textureMatchFirst, conditions) :
new Finished(recipeLoc, output[0], custSerial, mirror, conditions)
);
// Capture the finished recipe in the consumer, then wrap in our own class.
super.build((result) -> consumer.accept(textureSource != null ?
new FinishedTexture(recipeLoc, result, mirror, textureSource, textureMatchFirst, conditions) :
new Finished(recipeLoc, result, custSerial, mirror, conditions)
), recipeLoc);
}

@Override
Expand All @@ -225,17 +219,11 @@ public void build(@Nonnull Consumer<IFinishedRecipe> consumer, String path) {

@Override
public void build(Consumer<IFinishedRecipe> consumer) {
// Capture the finished recipe which will be sent to the consumer.
final IFinishedRecipe[] output = {null};
super.build((res) -> output[0] = res);

// It should have been called immediately.
assert output[0] != null;
// Then wrap.
consumer.accept(textureSource != null ?
new FinishedTexture(output[0].getID(), output[0], mirror, textureSource, textureMatchFirst, conditions) :
new Finished(output[0].getID(), output[0], custSerial, mirror, conditions)
);
// Capture the finished recipe in the consumer, then wrap in our own class.
super.build((result) -> consumer.accept(textureSource != null ?
new FinishedTexture(result.getID(), result, mirror, textureSource, textureMatchFirst, conditions) :
new Finished(result.getID(), result, custSerial, mirror, conditions)
));
}
}

Expand All @@ -261,14 +249,10 @@ public ShapelessBuilder custom(IRecipeSerializer<?> serializer) {

@Override
public void build(Consumer<IFinishedRecipe> consumer, ResourceLocation recipeLoc) {
// Capture the finished recipe which will be sent to the consumer.
final IFinishedRecipe[] output = {null};
super.build((res) -> output[0] = res, recipeLoc);

// It should have been called immediately.
assert output[0] != null;
// Then wrap.
consumer.accept(new Finished(recipeLoc, output[0], custSerial, false, conditions));
// Capture the finished recipe in the consumer, then wrap in our own class.
super.build((result) -> consumer.accept(
new Finished(recipeLoc, result, custSerial, false, conditions)
), recipeLoc);
}

@Override
Expand All @@ -292,15 +276,14 @@ public CustomBuilder addCondition(ICondition cond) {
}

public void build(@Nonnull Consumer<IFinishedRecipe> consumer, ResourceLocation path) {
// Capture the finished recipe which will be sent to the consumer.
// Reuse vanilla's builder - which just writes "type".
CustomRecipeBuilder builder = CustomRecipeBuilder.func_218656_a(serializer);
final IFinishedRecipe[] output = {null};
builder.build((res) -> output[0] = res, path.toString());

// It should have been called immediately.
assert output[0] != null;
// Then wrap.
consumer.accept(new Finished(path, output[0], serializer, false, conditions));
// Capture the finished recipe in the consumer, then wrap in our own class.
builder.build((result) ->
consumer.accept(new Finished(path, result, serializer, false, conditions)),
path.toString()
);
}

public void build(@Nonnull Consumer<IFinishedRecipe> consumer, String path) {
Expand Down
Expand Up @@ -42,15 +42,9 @@ protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Bui
// Override to skip validating that vanilla's tables are present.
@Override
protected void validate(Map<ResourceLocation, LootTable> map, ValidationResults validationresults) {
Map<ResourceLocation, LootTable> kept = new HashMap<>();
map.forEach((loc, table) -> {
if (loc.getNamespace().equals(Inspirations.modID)) {
LootTableManager.func_215302_a(validationresults, loc, table, map::get);
kept.put(loc, table);
}
});
map.forEach((loc, table) -> LootTableManager.func_215302_a(validationresults, loc, table, map::get));
// Remove vanilla's tables, which we also loaded so we can redirect stuff to them.
map.clear();
map.putAll(kept);
// This ensures the remaining generator logic doesn't write those to files.
map.keySet().removeIf((loc) -> !loc.getNamespace().equals(Inspirations.modID));
}
}

0 comments on commit ef95761

Please sign in to comment.