diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 2d9106b4c..1f8aa812e 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -155,6 +155,7 @@ import com.simibubi.create.content.logistics.block.redstone.RedstoneLinkGenerato import com.simibubi.create.content.logistics.block.redstone.StockpileSwitchBlock; import com.simibubi.create.content.schematics.block.SchematicTableBlock; import com.simibubi.create.content.schematics.block.SchematicannonBlock; +import com.simibubi.create.foundation.block.DyedBlockList; import com.simibubi.create.foundation.block.ItemUseOverrides; import com.simibubi.create.foundation.config.StressConfigDefaults; import com.simibubi.create.foundation.data.AssetLookup; @@ -626,23 +627,19 @@ public class AllBlocks { .transform(BuilderTransformers.valveHandle(null)) .register(); - public static final BlockEntry[] DYED_VALVE_HANDLES = new BlockEntry[DyeColor.values().length]; - - static { - for (DyeColor colour : DyeColor.values()) { - String colourName = colour.getString(); - DYED_VALVE_HANDLES[colour.ordinal()] = REGISTRATE.block(colourName + "_valve_handle", ValveHandleBlock::dyed) - .transform(BuilderTransformers.valveHandle(colour)) - .recipe((c, p) -> ShapedRecipeBuilder.shapedRecipe(c.get()) - .patternLine("#") - .patternLine("-") - .key('#', DyeHelper.getTagOfDye(colour)) - .key('-', AllItemTags.VALVE_HANDLES.tag) - .addCriterion("has_valve", RegistrateRecipeProvider.hasItem(AllItemTags.VALVE_HANDLES.tag)) - .build(p, Create.asResource("crafting/kinetics/" + c.getName() + "_from_other_valve_handle"))) - .register(); - } - } + public static final DyedBlockList DYED_VALVE_HANDLES = new DyedBlockList<>(colour -> { + String colourName = colour.getString(); + return REGISTRATE.block(colourName + "_valve_handle", ValveHandleBlock::dyed) + .transform(BuilderTransformers.valveHandle(colour)) + .recipe((c, p) -> ShapedRecipeBuilder.shapedRecipe(c.get()) + .patternLine("#") + .patternLine("-") + .key('#', DyeHelper.getTagOfDye(colour)) + .key('-', AllItemTags.VALVE_HANDLES.tag) + .addCriterion("has_valve", RegistrateRecipeProvider.hasItem(AllItemTags.VALVE_HANDLES.tag)) + .build(p, Create.asResource("crafting/kinetics/" + c.getName() + "_from_other_valve_handle"))) + .register(); + }); public static final BlockEntry FLUID_TANK = REGISTRATE.block("fluid_tank", FluidTankBlock::regular) .initialProperties(SharedProperties::softMetal) @@ -961,47 +958,41 @@ public class AllBlocks { .simpleItem() .register(); - public static final BlockEntry[] SEATS = new BlockEntry[DyeColor.values().length]; - - static { - // SEATS - for (DyeColor colour : DyeColor.values()) { - String colourName = colour.getString(); - SeatMovementBehaviour movementBehaviour = new SeatMovementBehaviour(); - SEATS[colour.ordinal()] = - REGISTRATE.block(colourName + "_seat", p -> new SeatBlock(p, colour == DyeColor.RED)) - .initialProperties(SharedProperties::wooden) - .onRegister(addMovementBehaviour(movementBehaviour)) - .blockstate((c, p) -> { - p.simpleBlock(c.get(), p.models() - .withExistingParent(colourName + "_seat", p.modLoc("block/seat")) - .texture("1", p.modLoc("block/seat/top_" + colourName)) - .texture("2", p.modLoc("block/seat/side_" + colourName))); - }) - .recipe((c, p) -> { - ShapedRecipeBuilder.shapedRecipe(c.get()) - .patternLine("#") - .patternLine("-") - .key('#', DyeHelper.getWoolOfDye(colour)) - .key('-', ItemTags.WOODEN_SLABS) - .addCriterion("has_wool", RegistrateRecipeProvider.hasItem(ItemTags.WOOL)) - .build(p, Create.asResource("crafting/kinetics/" + c.getName())); - ShapedRecipeBuilder.shapedRecipe(c.get()) - .patternLine("#") - .patternLine("-") - .key('#', DyeHelper.getTagOfDye(colour)) - .key('-', AllItemTags.SEATS.tag) - .addCriterion("has_seat", RegistrateRecipeProvider.hasItem(AllItemTags.SEATS.tag)) - .build(p, Create.asResource("crafting/kinetics/" + c.getName() + "_from_other_seat")); - }) - .onRegisterAfter(Item.class, v -> TooltipHelper.referTo(v, "block.create.seat")) - .tag(AllBlockTags.SEATS.tag) - .item() - .tag(AllItemTags.SEATS.tag) - .build() - .register(); - } - } + public static final DyedBlockList SEATS = new DyedBlockList<>(colour -> { + String colourName = colour.getString(); + SeatMovementBehaviour movementBehaviour = new SeatMovementBehaviour(); + return REGISTRATE.block(colourName + "_seat", p -> new SeatBlock(p, colour == DyeColor.RED)) + .initialProperties(SharedProperties::wooden) + .onRegister(addMovementBehaviour(movementBehaviour)) + .blockstate((c, p) -> { + p.simpleBlock(c.get(), p.models() + .withExistingParent(colourName + "_seat", p.modLoc("block/seat")) + .texture("1", p.modLoc("block/seat/top_" + colourName)) + .texture("2", p.modLoc("block/seat/side_" + colourName))); + }) + .recipe((c, p) -> { + ShapedRecipeBuilder.shapedRecipe(c.get()) + .patternLine("#") + .patternLine("-") + .key('#', DyeHelper.getWoolOfDye(colour)) + .key('-', ItemTags.WOODEN_SLABS) + .addCriterion("has_wool", RegistrateRecipeProvider.hasItem(ItemTags.WOOL)) + .build(p, Create.asResource("crafting/kinetics/" + c.getName())); + ShapedRecipeBuilder.shapedRecipe(c.get()) + .patternLine("#") + .patternLine("-") + .key('#', DyeHelper.getTagOfDye(colour)) + .key('-', AllItemTags.SEATS.tag) + .addCriterion("has_seat", RegistrateRecipeProvider.hasItem(AllItemTags.SEATS.tag)) + .build(p, Create.asResource("crafting/kinetics/" + c.getName() + "_from_other_seat")); + }) + .onRegisterAfter(Item.class, v -> TooltipHelper.referTo(v, "block.create.seat")) + .tag(AllBlockTags.SEATS.tag) + .item() + .tag(AllItemTags.SEATS.tag) + .build() + .register(); + }); public static final BlockEntry SAIL_FRAME = REGISTRATE.block("sail_frame", p -> SailBlock.frame(p)) .initialProperties(SharedProperties::wooden) @@ -1012,8 +1003,6 @@ public class AllBlocks { .simpleItem() .register(); - public static final BlockEntry[] DYED_SAILS = new BlockEntry[DyeColor.values().length]; - public static final BlockEntry SAIL = REGISTRATE.block("white_sail", p -> SailBlock.withCanvas(p)) .initialProperties(SharedProperties::wooden) .properties(Block.Properties::nonOpaque) @@ -1022,26 +1011,22 @@ public class AllBlocks { .simpleItem() .register(); - static { - // DYED SAILS - for (DyeColor colour : DyeColor.values()) { - if (colour == DyeColor.WHITE) { - DYED_SAILS[colour.ordinal()] = SAIL; - continue; - } - String colourName = colour.getString(); - DYED_SAILS[colour.ordinal()] = REGISTRATE.block(colourName + "_sail", p -> SailBlock.withCanvas(p)) - .properties(Block.Properties::nonOpaque) - .initialProperties(SharedProperties::wooden) - .blockstate((c, p) -> p.directionalBlock(c.get(), p.models() - .withExistingParent(colourName + "_sail", p.modLoc("block/white_sail")) - .texture("0", p.modLoc("block/sail/canvas_" + colourName)))) - .tag(AllBlockTags.WINDMILL_SAILS.tag) - .tag(AllBlockTags.SAILS.tag) - .loot((p, b) -> p.registerDropping(b, SAIL.get())) - .register(); + public static final DyedBlockList DYED_SAILS = new DyedBlockList<>(colour -> { + if (colour == DyeColor.WHITE) { + return SAIL; } - } + String colourName = colour.getString(); + return REGISTRATE.block(colourName + "_sail", p -> SailBlock.withCanvas(p)) + .properties(Block.Properties::nonOpaque) + .initialProperties(SharedProperties::wooden) + .blockstate((c, p) -> p.directionalBlock(c.get(), p.models() + .withExistingParent(colourName + "_sail", p.modLoc("block/white_sail")) + .texture("0", p.modLoc("block/sail/canvas_" + colourName)))) + .tag(AllBlockTags.WINDMILL_SAILS.tag) + .tag(AllBlockTags.SAILS.tag) + .loot((p, b) -> p.registerDropping(b, SAIL.get())) + .register(); + }); public static final BlockEntry ANDESITE_CASING = REGISTRATE.block("andesite_casing", CasingBlock::new) .transform(BuilderTransformers.casing(AllSpriteShifts.ANDESITE_CASING)) diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 1ff2f9a0f..5b4be0796 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -248,7 +248,7 @@ public class AllTileEntities { .tileEntity("hand_crank", HandCrankTileEntity::new) .instance(() -> HandCrankInstance::new) .validBlocks(AllBlocks.HAND_CRANK, AllBlocks.COPPER_VALVE_HANDLE) - .validBlocks(AllBlocks.DYED_VALVE_HANDLES) + .validBlocks(AllBlocks.DYED_VALVE_HANDLES.toArray()) .renderer(() -> HandCrankRenderer::new) .register(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java index 3cccce364..f931d8197 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/SeatBlock.java @@ -101,7 +101,7 @@ public class SeatBlock extends Block { if (world.isRemote) return ActionResultType.SUCCESS; - BlockState newState = AllBlocks.SEATS[color.ordinal()].getDefaultState(); + BlockState newState = AllBlocks.SEATS.get(color).getDefaultState(); if (newState != state) world.setBlockState(pos, newState); return ActionResultType.SUCCESS; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/ValveHandleBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/ValveHandleBlock.java index a29a996c1..1a5d99e74 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/ValveHandleBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/ValveHandleBlock.java @@ -48,7 +48,7 @@ public class ValveHandleBlock extends HandCrankBlock { if (worldIn.isRemote) return ActionResultType.SUCCESS; - BlockState newState = AllBlocks.DYED_VALVE_HANDLES[color.ordinal()] + BlockState newState = AllBlocks.DYED_VALVE_HANDLES.get(color) .getDefaultState() .with(FACING, state.get(FACING)); if (newState != state) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java index 73e80c2e3..b4cfaea85 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/SailBlock.java @@ -97,7 +97,7 @@ public class SailBlock extends ProperDirectionalBlock { protected void applyDye(BlockState state, World world, BlockPos pos, @Nullable DyeColor color) { BlockState newState = - (color == null ? AllBlocks.SAIL_FRAME : AllBlocks.DYED_SAILS[color.ordinal()]).getDefaultState() + (color == null ? AllBlocks.SAIL_FRAME : AllBlocks.DYED_SAILS.get(color)).getDefaultState() .with(FACING, state.get(FACING)); // Dye the block itself diff --git a/src/main/java/com/simibubi/create/foundation/block/DyedBlockList.java b/src/main/java/com/simibubi/create/foundation/block/DyedBlockList.java new file mode 100644 index 000000000..f0a5d97f6 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/block/DyedBlockList.java @@ -0,0 +1,33 @@ +package com.simibubi.create.foundation.block; + +import java.util.Arrays; +import java.util.function.Function; + +import com.tterrag.registrate.util.entry.BlockEntry; + +import net.minecraft.block.Block; +import net.minecraft.item.DyeColor; + +public class DyedBlockList { + + private static final int COLOR_AMOUNT = DyeColor.values().length; + + private final BlockEntry[] values = new BlockEntry[COLOR_AMOUNT]; + + public DyedBlockList(Function> filler) { + for (DyeColor color : DyeColor.values()) { + values[color.ordinal()] = filler.apply(color); + } + } + + @SuppressWarnings("unchecked") + public BlockEntry get(DyeColor color) { + return (BlockEntry) values[color.ordinal()]; + } + + @SuppressWarnings("unchecked") + public BlockEntry[] toArray() { + return (BlockEntry[]) Arrays.copyOf(values, values.length); + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/BearingScenes.java b/src/main/java/com/simibubi/create/foundation/ponder/content/BearingScenes.java index 843f8a622..436faf4d9 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/BearingScenes.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/BearingScenes.java @@ -632,7 +632,7 @@ public class BearingScenes { .withItem(new ItemStack(Items.BLUE_DYE)); scene.overlay.showControls(input, 30); scene.idle(7); - scene.world.setBlock(util.grid.at(2, 3, 1), AllBlocks.DYED_SAILS[DyeColor.BLUE.ordinal()].getDefaultState() + scene.world.setBlock(util.grid.at(2, 3, 1), AllBlocks.DYED_SAILS.get(DyeColor.BLUE).getDefaultState() .with(SailBlock.FACING, Direction.WEST), false); scene.idle(10); scene.overlay.showText(40) @@ -645,7 +645,7 @@ public class BearingScenes { scene.overlay.showControls(input, 30); scene.idle(7); scene.world.replaceBlocks(util.select.fromTo(2, 2, 1, 2, 4, 1), - AllBlocks.DYED_SAILS[DyeColor.BLUE.ordinal()].getDefaultState() + AllBlocks.DYED_SAILS.get(DyeColor.BLUE).getDefaultState() .with(SailBlock.FACING, Direction.WEST), false); diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/KineticsScenes.java b/src/main/java/com/simibubi/create/foundation/ponder/content/KineticsScenes.java index 8177eb9b3..b10e501a7 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/KineticsScenes.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/KineticsScenes.java @@ -26,6 +26,7 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.FurnaceBlock; import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.item.DyeColor; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.particles.ParticleTypes; @@ -631,7 +632,7 @@ public class KineticsScenes { scene.overlay.showControls(new InputWindowElement(centerOf, Pointing.DOWN).rightClick() .withItem(new ItemStack(Items.BLUE_DYE)), 40); scene.idle(7); - scene.world.modifyBlock(util.grid.at(2, 2, 2), s -> AllBlocks.DYED_VALVE_HANDLES[11].getDefaultState() + scene.world.modifyBlock(util.grid.at(2, 2, 2), s -> AllBlocks.DYED_VALVE_HANDLES.get(DyeColor.BLUE).getDefaultState() .with(ValveHandleBlock.FACING, Direction.UP), true); scene.idle(10); scene.overlay.showText(70) diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java index 71fb38cb2..1f914624b 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndex.java @@ -5,6 +5,7 @@ import com.simibubi.create.AllItems; import com.simibubi.create.foundation.ponder.PonderRegistry; import net.minecraft.block.Blocks; +import net.minecraft.item.DyeColor; public class PonderIndex { @@ -62,7 +63,7 @@ public class PonderIndex { PonderRegistry.addStoryBoard(AllBlocks.COPPER_VALVE_HANDLE, "valve_handle", KineticsScenes::valveHandle, PonderTag.KINETIC_SOURCES); - PonderRegistry.forComponents(AllBlocks.DYED_VALVE_HANDLES) + PonderRegistry.forComponents(AllBlocks.DYED_VALVE_HANDLES.toArray()) .addStoryBoard("valve_handle", KineticsScenes::valveHandle); PonderRegistry.addStoryBoard(AllBlocks.ENCASED_CHAIN_DRIVE, "chain_drive/relay", @@ -408,7 +409,7 @@ public class PonderIndex { .add(AllBlocks.MECHANICAL_BEARING) .add(AllBlocks.ANDESITE_FUNNEL) .add(AllBlocks.BRASS_FUNNEL) - .add(AllBlocks.SEATS[0]) + .add(AllBlocks.SEATS.get(DyeColor.WHITE)) .add(AllBlocks.REDSTONE_CONTACT) .add(Blocks.BELL) .add(Blocks.DISPENSER)