Skip to content

Commit

Permalink
Add RegisteredMap.forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Aug 19, 2024
1 parent ea911ca commit 5acd6f6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
10 changes: 10 additions & 0 deletions common/src/main/java/juuxel/adorn/lib/registry/RegisteredMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.util.EnumMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import java.util.stream.Stream;

public final class RegisteredMap<K, V> implements Registered<Map<K, V>> {
private final Map<K, Registered<? extends V>> map;
Expand Down Expand Up @@ -34,6 +36,14 @@ public Map<K, V> get() {
return builtMap.get();
}

public Stream<V> values() {
return map.values().stream().map(Registered::get);
}

public void forEach(BiConsumer<? super K, ? super V> action) {
map.forEach((key, value) -> action.accept(key, value.get()));
}

public static <K, V> Builder<K, V> builder(MapFactory<K> mapFactory) {
return new Builder<>(mapFactory, mapFactory.create());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public AdornBlockLootTableGenerator(FabricDataOutput dataOutput, CompletableFutu

@Override
public void generate() {
AdornBlocks.PAINTED_PLANKS.get().values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_SLABS.get().values().forEach(this::slabDrops);
AdornBlocks.PAINTED_WOOD_STAIRS.get().values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_FENCES.get().values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_FENCE_GATES.get().values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_PRESSURE_PLATES.get().values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_BUTTONS.get().values().forEach(this::addDrop);
AdornBlocks.PAINTED_PLANKS.values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_SLABS.values().forEach(this::slabDrops);
AdornBlocks.PAINTED_WOOD_STAIRS.values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_FENCES.values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_FENCE_GATES.values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_PRESSURE_PLATES.values().forEach(this::addDrop);
AdornBlocks.PAINTED_WOOD_BUTTONS.values().forEach(this::addDrop);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ public AdornBlockTagGenerator(FabricDataOutput output, CompletableFuture<Registr
@Override
protected void configure(RegistryWrapper.WrapperLookup wrapperLookup) {
getOrCreateTagBuilder(AdornTags.PAINTED_PLANKS.block())
.add(AdornBlocks.PAINTED_PLANKS.get().values().toArray(Block[]::new));
.add(AdornBlocks.PAINTED_PLANKS.values().toArray(Block[]::new));
getOrCreateTagBuilder(AdornTags.PAINTED_WOOD_SLABS.block())
.add(AdornBlocks.PAINTED_WOOD_SLABS.get().values().toArray(Block[]::new));
.add(AdornBlocks.PAINTED_WOOD_SLABS.values().toArray(Block[]::new));
getOrCreateTagBuilder(AdornTags.PAINTED_WOOD_STAIRS.block())
.add(AdornBlocks.PAINTED_WOOD_STAIRS.get().values().toArray(Block[]::new));
.add(AdornBlocks.PAINTED_WOOD_STAIRS.values().toArray(Block[]::new));
getOrCreateTagBuilder(AdornTags.PAINTED_WOOD_FENCES.block())
.add(AdornBlocks.PAINTED_WOOD_FENCES.get().values().toArray(Block[]::new));
.add(AdornBlocks.PAINTED_WOOD_FENCES.values().toArray(Block[]::new));
getOrCreateTagBuilder(AdornTags.PAINTED_WOOD_FENCE_GATES.block())
.add(AdornBlocks.PAINTED_WOOD_FENCE_GATES.get().values().toArray(Block[]::new));
.add(AdornBlocks.PAINTED_WOOD_FENCE_GATES.values().toArray(Block[]::new));
getOrCreateTagBuilder(AdornTags.PAINTED_WOOD_PRESSURE_PLATES.block())
.add(AdornBlocks.PAINTED_WOOD_PRESSURE_PLATES.get().values().toArray(Block[]::new));
.add(AdornBlocks.PAINTED_WOOD_PRESSURE_PLATES.values().toArray(Block[]::new));
getOrCreateTagBuilder(AdornTags.PAINTED_WOOD_BUTTONS.block())
.add(AdornBlocks.PAINTED_WOOD_BUTTONS.get().values().toArray(Block[]::new));
.add(AdornBlocks.PAINTED_WOOD_BUTTONS.values().toArray(Block[]::new));
getOrCreateTagBuilder(BlockTags.PLANKS).addTag(AdornTags.PAINTED_PLANKS.block());
getOrCreateTagBuilder(BlockTags.WOODEN_SLABS).addTag(AdornTags.PAINTED_WOOD_SLABS.block());
getOrCreateTagBuilder(BlockTags.WOODEN_STAIRS).addTag(AdornTags.PAINTED_WOOD_STAIRS.block());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public AdornModelGenerator(FabricDataOutput output) {

@Override
public void generateBlockStateModels(BlockStateModelGenerator generator) {
AdornBlocks.PAINTED_PLANKS.get().forEach((color, planks) -> {
AdornBlocks.PAINTED_PLANKS.forEach((color, planks) -> {
generator.registerCubeAllModelTexturePool(planks)
.slab(AdornBlocks.PAINTED_WOOD_SLABS.getEager(color))
.stairs(AdornBlocks.PAINTED_WOOD_STAIRS.getEager(color))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ public AdornRecipeGenerator(FabricDataOutput output, CompletableFuture<RegistryW

@Override
public void generate(RecipeExporter exporter) {
AdornBlocks.PAINTED_PLANKS.get().forEach((color, block) -> offerPlankDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_SLABS.get().forEach((color, block) -> offerPaintedSlabRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_SLABS.get().forEach((color, block) -> offerSlabDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_STAIRS.get().forEach((color, block) -> offerPaintedStairsRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_STAIRS.get().forEach((color, block) -> offerStairDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_FENCES.get().forEach((color, block) -> offerPaintedFenceRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_FENCES.get().forEach((color, block) -> offerFenceDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_FENCE_GATES.get().forEach((color, block) -> offerPaintedFenceGateRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_FENCE_GATES.get().forEach((color, block) -> offerFenceGateDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_PRESSURE_PLATES.get().forEach((color, block) -> offerPaintedPressurePlateRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_PRESSURE_PLATES.get().forEach((color, block) -> offerPressurePlateDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_BUTTONS.get().forEach((color, block) -> offerPaintedButtonRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_BUTTONS.get().forEach((color, block) -> offerButtonDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_PLANKS.forEach((color, block) -> offerPlankDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_SLABS.forEach((color, block) -> offerPaintedSlabRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_SLABS.forEach((color, block) -> offerSlabDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_STAIRS.forEach((color, block) -> offerPaintedStairsRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_STAIRS.forEach((color, block) -> offerStairDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_FENCES.forEach((color, block) -> offerPaintedFenceRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_FENCES.forEach((color, block) -> offerFenceDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_FENCE_GATES.forEach((color, block) -> offerPaintedFenceGateRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_FENCE_GATES.forEach((color, block) -> offerFenceGateDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_PRESSURE_PLATES.forEach((color, block) -> offerPaintedPressurePlateRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_PRESSURE_PLATES.forEach((color, block) -> offerPressurePlateDyeingRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_BUTTONS.forEach((color, block) -> offerPaintedButtonRecipe(exporter, block, color));
AdornBlocks.PAINTED_WOOD_BUTTONS.forEach((color, block) -> offerButtonDyeingRecipe(exporter, block, color));
}

private static void offerPlankDyeingRecipe(RecipeExporter exporter, ItemConvertible output, DyeColor color) {
Expand Down

0 comments on commit 5acd6f6

Please sign in to comment.