mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 16:36:37 +01:00
Improve handling of dyed blocks
- Create DyedBlockList for storing and accessing a set of dyed blocks - Switch usage of BlockEntry<?>[] to DyedBlockList in AllBlocks - These changes also finally fix the compilation error related to generic arrays
This commit is contained in:
parent
fec329e3d2
commit
823520e047
9 changed files with 108 additions and 88 deletions
|
@ -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.logistics.block.redstone.StockpileSwitchBlock;
|
||||||
import com.simibubi.create.content.schematics.block.SchematicTableBlock;
|
import com.simibubi.create.content.schematics.block.SchematicTableBlock;
|
||||||
import com.simibubi.create.content.schematics.block.SchematicannonBlock;
|
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.block.ItemUseOverrides;
|
||||||
import com.simibubi.create.foundation.config.StressConfigDefaults;
|
import com.simibubi.create.foundation.config.StressConfigDefaults;
|
||||||
import com.simibubi.create.foundation.data.AssetLookup;
|
import com.simibubi.create.foundation.data.AssetLookup;
|
||||||
|
@ -626,12 +627,9 @@ public class AllBlocks {
|
||||||
.transform(BuilderTransformers.valveHandle(null))
|
.transform(BuilderTransformers.valveHandle(null))
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
public static final BlockEntry<?>[] DYED_VALVE_HANDLES = new BlockEntry<?>[DyeColor.values().length];
|
public static final DyedBlockList<ValveHandleBlock> DYED_VALVE_HANDLES = new DyedBlockList<>(colour -> {
|
||||||
|
|
||||||
static {
|
|
||||||
for (DyeColor colour : DyeColor.values()) {
|
|
||||||
String colourName = colour.getString();
|
String colourName = colour.getString();
|
||||||
DYED_VALVE_HANDLES[colour.ordinal()] = REGISTRATE.block(colourName + "_valve_handle", ValveHandleBlock::dyed)
|
return REGISTRATE.block(colourName + "_valve_handle", ValveHandleBlock::dyed)
|
||||||
.transform(BuilderTransformers.valveHandle(colour))
|
.transform(BuilderTransformers.valveHandle(colour))
|
||||||
.recipe((c, p) -> ShapedRecipeBuilder.shapedRecipe(c.get())
|
.recipe((c, p) -> ShapedRecipeBuilder.shapedRecipe(c.get())
|
||||||
.patternLine("#")
|
.patternLine("#")
|
||||||
|
@ -641,8 +639,7 @@ public class AllBlocks {
|
||||||
.addCriterion("has_valve", RegistrateRecipeProvider.hasItem(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")))
|
.build(p, Create.asResource("crafting/kinetics/" + c.getName() + "_from_other_valve_handle")))
|
||||||
.register();
|
.register();
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
public static final BlockEntry<FluidTankBlock> FLUID_TANK = REGISTRATE.block("fluid_tank", FluidTankBlock::regular)
|
public static final BlockEntry<FluidTankBlock> FLUID_TANK = REGISTRATE.block("fluid_tank", FluidTankBlock::regular)
|
||||||
.initialProperties(SharedProperties::softMetal)
|
.initialProperties(SharedProperties::softMetal)
|
||||||
|
@ -961,15 +958,10 @@ public class AllBlocks {
|
||||||
.simpleItem()
|
.simpleItem()
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
public static final BlockEntry<?>[] SEATS = new BlockEntry<?>[DyeColor.values().length];
|
public static final DyedBlockList<SeatBlock> SEATS = new DyedBlockList<>(colour -> {
|
||||||
|
|
||||||
static {
|
|
||||||
// SEATS
|
|
||||||
for (DyeColor colour : DyeColor.values()) {
|
|
||||||
String colourName = colour.getString();
|
String colourName = colour.getString();
|
||||||
SeatMovementBehaviour movementBehaviour = new SeatMovementBehaviour();
|
SeatMovementBehaviour movementBehaviour = new SeatMovementBehaviour();
|
||||||
SEATS[colour.ordinal()] =
|
return REGISTRATE.block(colourName + "_seat", p -> new SeatBlock(p, colour == DyeColor.RED))
|
||||||
REGISTRATE.block(colourName + "_seat", p -> new SeatBlock(p, colour == DyeColor.RED))
|
|
||||||
.initialProperties(SharedProperties::wooden)
|
.initialProperties(SharedProperties::wooden)
|
||||||
.onRegister(addMovementBehaviour(movementBehaviour))
|
.onRegister(addMovementBehaviour(movementBehaviour))
|
||||||
.blockstate((c, p) -> {
|
.blockstate((c, p) -> {
|
||||||
|
@ -1000,8 +992,7 @@ public class AllBlocks {
|
||||||
.tag(AllItemTags.SEATS.tag)
|
.tag(AllItemTags.SEATS.tag)
|
||||||
.build()
|
.build()
|
||||||
.register();
|
.register();
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
public static final BlockEntry<SailBlock> SAIL_FRAME = REGISTRATE.block("sail_frame", p -> SailBlock.frame(p))
|
public static final BlockEntry<SailBlock> SAIL_FRAME = REGISTRATE.block("sail_frame", p -> SailBlock.frame(p))
|
||||||
.initialProperties(SharedProperties::wooden)
|
.initialProperties(SharedProperties::wooden)
|
||||||
|
@ -1012,8 +1003,6 @@ public class AllBlocks {
|
||||||
.simpleItem()
|
.simpleItem()
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
public static final BlockEntry<?>[] DYED_SAILS = new BlockEntry<?>[DyeColor.values().length];
|
|
||||||
|
|
||||||
public static final BlockEntry<SailBlock> SAIL = REGISTRATE.block("white_sail", p -> SailBlock.withCanvas(p))
|
public static final BlockEntry<SailBlock> SAIL = REGISTRATE.block("white_sail", p -> SailBlock.withCanvas(p))
|
||||||
.initialProperties(SharedProperties::wooden)
|
.initialProperties(SharedProperties::wooden)
|
||||||
.properties(Block.Properties::nonOpaque)
|
.properties(Block.Properties::nonOpaque)
|
||||||
|
@ -1022,15 +1011,12 @@ public class AllBlocks {
|
||||||
.simpleItem()
|
.simpleItem()
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
static {
|
public static final DyedBlockList<SailBlock> DYED_SAILS = new DyedBlockList<>(colour -> {
|
||||||
// DYED SAILS
|
|
||||||
for (DyeColor colour : DyeColor.values()) {
|
|
||||||
if (colour == DyeColor.WHITE) {
|
if (colour == DyeColor.WHITE) {
|
||||||
DYED_SAILS[colour.ordinal()] = SAIL;
|
return SAIL;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
String colourName = colour.getString();
|
String colourName = colour.getString();
|
||||||
DYED_SAILS[colour.ordinal()] = REGISTRATE.block(colourName + "_sail", p -> SailBlock.withCanvas(p))
|
return REGISTRATE.block(colourName + "_sail", p -> SailBlock.withCanvas(p))
|
||||||
.properties(Block.Properties::nonOpaque)
|
.properties(Block.Properties::nonOpaque)
|
||||||
.initialProperties(SharedProperties::wooden)
|
.initialProperties(SharedProperties::wooden)
|
||||||
.blockstate((c, p) -> p.directionalBlock(c.get(), p.models()
|
.blockstate((c, p) -> p.directionalBlock(c.get(), p.models()
|
||||||
|
@ -1040,8 +1026,7 @@ public class AllBlocks {
|
||||||
.tag(AllBlockTags.SAILS.tag)
|
.tag(AllBlockTags.SAILS.tag)
|
||||||
.loot((p, b) -> p.registerDropping(b, SAIL.get()))
|
.loot((p, b) -> p.registerDropping(b, SAIL.get()))
|
||||||
.register();
|
.register();
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
public static final BlockEntry<CasingBlock> ANDESITE_CASING = REGISTRATE.block("andesite_casing", CasingBlock::new)
|
public static final BlockEntry<CasingBlock> ANDESITE_CASING = REGISTRATE.block("andesite_casing", CasingBlock::new)
|
||||||
.transform(BuilderTransformers.casing(AllSpriteShifts.ANDESITE_CASING))
|
.transform(BuilderTransformers.casing(AllSpriteShifts.ANDESITE_CASING))
|
||||||
|
|
|
@ -248,7 +248,7 @@ public class AllTileEntities {
|
||||||
.tileEntity("hand_crank", HandCrankTileEntity::new)
|
.tileEntity("hand_crank", HandCrankTileEntity::new)
|
||||||
.instance(() -> HandCrankInstance::new)
|
.instance(() -> HandCrankInstance::new)
|
||||||
.validBlocks(AllBlocks.HAND_CRANK, AllBlocks.COPPER_VALVE_HANDLE)
|
.validBlocks(AllBlocks.HAND_CRANK, AllBlocks.COPPER_VALVE_HANDLE)
|
||||||
.validBlocks(AllBlocks.DYED_VALVE_HANDLES)
|
.validBlocks(AllBlocks.DYED_VALVE_HANDLES.toArray())
|
||||||
.renderer(() -> HandCrankRenderer::new)
|
.renderer(() -> HandCrankRenderer::new)
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class SeatBlock extends Block {
|
||||||
if (world.isRemote)
|
if (world.isRemote)
|
||||||
return ActionResultType.SUCCESS;
|
return ActionResultType.SUCCESS;
|
||||||
|
|
||||||
BlockState newState = AllBlocks.SEATS[color.ordinal()].getDefaultState();
|
BlockState newState = AllBlocks.SEATS.get(color).getDefaultState();
|
||||||
if (newState != state)
|
if (newState != state)
|
||||||
world.setBlockState(pos, newState);
|
world.setBlockState(pos, newState);
|
||||||
return ActionResultType.SUCCESS;
|
return ActionResultType.SUCCESS;
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class ValveHandleBlock extends HandCrankBlock {
|
||||||
if (worldIn.isRemote)
|
if (worldIn.isRemote)
|
||||||
return ActionResultType.SUCCESS;
|
return ActionResultType.SUCCESS;
|
||||||
|
|
||||||
BlockState newState = AllBlocks.DYED_VALVE_HANDLES[color.ordinal()]
|
BlockState newState = AllBlocks.DYED_VALVE_HANDLES.get(color)
|
||||||
.getDefaultState()
|
.getDefaultState()
|
||||||
.with(FACING, state.get(FACING));
|
.with(FACING, state.get(FACING));
|
||||||
if (newState != state)
|
if (newState != state)
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class SailBlock extends ProperDirectionalBlock {
|
||||||
|
|
||||||
protected void applyDye(BlockState state, World world, BlockPos pos, @Nullable DyeColor color) {
|
protected void applyDye(BlockState state, World world, BlockPos pos, @Nullable DyeColor color) {
|
||||||
BlockState newState =
|
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));
|
.with(FACING, state.get(FACING));
|
||||||
|
|
||||||
// Dye the block itself
|
// Dye the block itself
|
||||||
|
|
|
@ -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<T extends Block> {
|
||||||
|
|
||||||
|
private static final int COLOR_AMOUNT = DyeColor.values().length;
|
||||||
|
|
||||||
|
private final BlockEntry<?>[] values = new BlockEntry<?>[COLOR_AMOUNT];
|
||||||
|
|
||||||
|
public DyedBlockList(Function<DyeColor, BlockEntry<? extends T>> filler) {
|
||||||
|
for (DyeColor color : DyeColor.values()) {
|
||||||
|
values[color.ordinal()] = filler.apply(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public BlockEntry<T> get(DyeColor color) {
|
||||||
|
return (BlockEntry<T>) values[color.ordinal()];
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public BlockEntry<T>[] toArray() {
|
||||||
|
return (BlockEntry<T>[]) Arrays.copyOf(values, values.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -632,7 +632,7 @@ public class BearingScenes {
|
||||||
.withItem(new ItemStack(Items.BLUE_DYE));
|
.withItem(new ItemStack(Items.BLUE_DYE));
|
||||||
scene.overlay.showControls(input, 30);
|
scene.overlay.showControls(input, 30);
|
||||||
scene.idle(7);
|
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);
|
.with(SailBlock.FACING, Direction.WEST), false);
|
||||||
scene.idle(10);
|
scene.idle(10);
|
||||||
scene.overlay.showText(40)
|
scene.overlay.showText(40)
|
||||||
|
@ -645,7 +645,7 @@ public class BearingScenes {
|
||||||
scene.overlay.showControls(input, 30);
|
scene.overlay.showControls(input, 30);
|
||||||
scene.idle(7);
|
scene.idle(7);
|
||||||
scene.world.replaceBlocks(util.select.fromTo(2, 2, 1, 2, 4, 1),
|
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),
|
.with(SailBlock.FACING, Direction.WEST),
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.FurnaceBlock;
|
import net.minecraft.block.FurnaceBlock;
|
||||||
import net.minecraft.block.RedstoneWireBlock;
|
import net.minecraft.block.RedstoneWireBlock;
|
||||||
|
import net.minecraft.item.DyeColor;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.particles.ParticleTypes;
|
import net.minecraft.particles.ParticleTypes;
|
||||||
|
@ -631,7 +632,7 @@ public class KineticsScenes {
|
||||||
scene.overlay.showControls(new InputWindowElement(centerOf, Pointing.DOWN).rightClick()
|
scene.overlay.showControls(new InputWindowElement(centerOf, Pointing.DOWN).rightClick()
|
||||||
.withItem(new ItemStack(Items.BLUE_DYE)), 40);
|
.withItem(new ItemStack(Items.BLUE_DYE)), 40);
|
||||||
scene.idle(7);
|
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);
|
.with(ValveHandleBlock.FACING, Direction.UP), true);
|
||||||
scene.idle(10);
|
scene.idle(10);
|
||||||
scene.overlay.showText(70)
|
scene.overlay.showText(70)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.simibubi.create.AllItems;
|
||||||
import com.simibubi.create.foundation.ponder.PonderRegistry;
|
import com.simibubi.create.foundation.ponder.PonderRegistry;
|
||||||
|
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.item.DyeColor;
|
||||||
|
|
||||||
public class PonderIndex {
|
public class PonderIndex {
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ public class PonderIndex {
|
||||||
|
|
||||||
PonderRegistry.addStoryBoard(AllBlocks.COPPER_VALVE_HANDLE, "valve_handle", KineticsScenes::valveHandle,
|
PonderRegistry.addStoryBoard(AllBlocks.COPPER_VALVE_HANDLE, "valve_handle", KineticsScenes::valveHandle,
|
||||||
PonderTag.KINETIC_SOURCES);
|
PonderTag.KINETIC_SOURCES);
|
||||||
PonderRegistry.forComponents(AllBlocks.DYED_VALVE_HANDLES)
|
PonderRegistry.forComponents(AllBlocks.DYED_VALVE_HANDLES.toArray())
|
||||||
.addStoryBoard("valve_handle", KineticsScenes::valveHandle);
|
.addStoryBoard("valve_handle", KineticsScenes::valveHandle);
|
||||||
|
|
||||||
PonderRegistry.addStoryBoard(AllBlocks.ENCASED_CHAIN_DRIVE, "chain_drive/relay",
|
PonderRegistry.addStoryBoard(AllBlocks.ENCASED_CHAIN_DRIVE, "chain_drive/relay",
|
||||||
|
@ -408,7 +409,7 @@ public class PonderIndex {
|
||||||
.add(AllBlocks.MECHANICAL_BEARING)
|
.add(AllBlocks.MECHANICAL_BEARING)
|
||||||
.add(AllBlocks.ANDESITE_FUNNEL)
|
.add(AllBlocks.ANDESITE_FUNNEL)
|
||||||
.add(AllBlocks.BRASS_FUNNEL)
|
.add(AllBlocks.BRASS_FUNNEL)
|
||||||
.add(AllBlocks.SEATS[0])
|
.add(AllBlocks.SEATS.get(DyeColor.WHITE))
|
||||||
.add(AllBlocks.REDSTONE_CONTACT)
|
.add(AllBlocks.REDSTONE_CONTACT)
|
||||||
.add(Blocks.BELL)
|
.add(Blocks.BELL)
|
||||||
.add(Blocks.DISPENSER)
|
.add(Blocks.DISPENSER)
|
||||||
|
|
Loading…
Reference in a new issue