mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-14 14:34:16 +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
@ -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,23 +627,19 @@ 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 -> {
|
||||||
|
String colourName = colour.getString();
|
||||||
static {
|
return REGISTRATE.block(colourName + "_valve_handle", ValveHandleBlock::dyed)
|
||||||
for (DyeColor colour : DyeColor.values()) {
|
.transform(BuilderTransformers.valveHandle(colour))
|
||||||
String colourName = colour.getString();
|
.recipe((c, p) -> ShapedRecipeBuilder.shapedRecipe(c.get())
|
||||||
DYED_VALVE_HANDLES[colour.ordinal()] = REGISTRATE.block(colourName + "_valve_handle", ValveHandleBlock::dyed)
|
.patternLine("#")
|
||||||
.transform(BuilderTransformers.valveHandle(colour))
|
.patternLine("-")
|
||||||
.recipe((c, p) -> ShapedRecipeBuilder.shapedRecipe(c.get())
|
.key('#', DyeHelper.getTagOfDye(colour))
|
||||||
.patternLine("#")
|
.key('-', AllItemTags.VALVE_HANDLES.tag)
|
||||||
.patternLine("-")
|
.addCriterion("has_valve", RegistrateRecipeProvider.hasItem(AllItemTags.VALVE_HANDLES.tag))
|
||||||
.key('#', DyeHelper.getTagOfDye(colour))
|
.build(p, Create.asResource("crafting/kinetics/" + c.getName() + "_from_other_valve_handle")))
|
||||||
.key('-', AllItemTags.VALVE_HANDLES.tag)
|
.register();
|
||||||
.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<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,47 +958,41 @@ 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 -> {
|
||||||
|
String colourName = colour.getString();
|
||||||
static {
|
SeatMovementBehaviour movementBehaviour = new SeatMovementBehaviour();
|
||||||
// SEATS
|
return REGISTRATE.block(colourName + "_seat", p -> new SeatBlock(p, colour == DyeColor.RED))
|
||||||
for (DyeColor colour : DyeColor.values()) {
|
.initialProperties(SharedProperties::wooden)
|
||||||
String colourName = colour.getString();
|
.onRegister(addMovementBehaviour(movementBehaviour))
|
||||||
SeatMovementBehaviour movementBehaviour = new SeatMovementBehaviour();
|
.blockstate((c, p) -> {
|
||||||
SEATS[colour.ordinal()] =
|
p.simpleBlock(c.get(), p.models()
|
||||||
REGISTRATE.block(colourName + "_seat", p -> new SeatBlock(p, colour == DyeColor.RED))
|
.withExistingParent(colourName + "_seat", p.modLoc("block/seat"))
|
||||||
.initialProperties(SharedProperties::wooden)
|
.texture("1", p.modLoc("block/seat/top_" + colourName))
|
||||||
.onRegister(addMovementBehaviour(movementBehaviour))
|
.texture("2", p.modLoc("block/seat/side_" + colourName)));
|
||||||
.blockstate((c, p) -> {
|
})
|
||||||
p.simpleBlock(c.get(), p.models()
|
.recipe((c, p) -> {
|
||||||
.withExistingParent(colourName + "_seat", p.modLoc("block/seat"))
|
ShapedRecipeBuilder.shapedRecipe(c.get())
|
||||||
.texture("1", p.modLoc("block/seat/top_" + colourName))
|
.patternLine("#")
|
||||||
.texture("2", p.modLoc("block/seat/side_" + colourName)));
|
.patternLine("-")
|
||||||
})
|
.key('#', DyeHelper.getWoolOfDye(colour))
|
||||||
.recipe((c, p) -> {
|
.key('-', ItemTags.WOODEN_SLABS)
|
||||||
ShapedRecipeBuilder.shapedRecipe(c.get())
|
.addCriterion("has_wool", RegistrateRecipeProvider.hasItem(ItemTags.WOOL))
|
||||||
.patternLine("#")
|
.build(p, Create.asResource("crafting/kinetics/" + c.getName()));
|
||||||
.patternLine("-")
|
ShapedRecipeBuilder.shapedRecipe(c.get())
|
||||||
.key('#', DyeHelper.getWoolOfDye(colour))
|
.patternLine("#")
|
||||||
.key('-', ItemTags.WOODEN_SLABS)
|
.patternLine("-")
|
||||||
.addCriterion("has_wool", RegistrateRecipeProvider.hasItem(ItemTags.WOOL))
|
.key('#', DyeHelper.getTagOfDye(colour))
|
||||||
.build(p, Create.asResource("crafting/kinetics/" + c.getName()));
|
.key('-', AllItemTags.SEATS.tag)
|
||||||
ShapedRecipeBuilder.shapedRecipe(c.get())
|
.addCriterion("has_seat", RegistrateRecipeProvider.hasItem(AllItemTags.SEATS.tag))
|
||||||
.patternLine("#")
|
.build(p, Create.asResource("crafting/kinetics/" + c.getName() + "_from_other_seat"));
|
||||||
.patternLine("-")
|
})
|
||||||
.key('#', DyeHelper.getTagOfDye(colour))
|
.onRegisterAfter(Item.class, v -> TooltipHelper.referTo(v, "block.create.seat"))
|
||||||
.key('-', AllItemTags.SEATS.tag)
|
.tag(AllBlockTags.SEATS.tag)
|
||||||
.addCriterion("has_seat", RegistrateRecipeProvider.hasItem(AllItemTags.SEATS.tag))
|
.item()
|
||||||
.build(p, Create.asResource("crafting/kinetics/" + c.getName() + "_from_other_seat"));
|
.tag(AllItemTags.SEATS.tag)
|
||||||
})
|
.build()
|
||||||
.onRegisterAfter(Item.class, v -> TooltipHelper.referTo(v, "block.create.seat"))
|
.register();
|
||||||
.tag(AllBlockTags.SEATS.tag)
|
});
|
||||||
.item()
|
|
||||||
.tag(AllItemTags.SEATS.tag)
|
|
||||||
.build()
|
|
||||||
.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,26 +1011,22 @@ public class AllBlocks {
|
|||||||
.simpleItem()
|
.simpleItem()
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
static {
|
public static final DyedBlockList<SailBlock> DYED_SAILS = new DyedBlockList<>(colour -> {
|
||||||
// DYED SAILS
|
if (colour == DyeColor.WHITE) {
|
||||||
for (DyeColor colour : DyeColor.values()) {
|
return SAIL;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
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<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 New Issue
Block a user