From 4e9cd1db498fe23b019cb3246fb771852da51942 Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sun, 24 May 2020 12:31:05 +0200 Subject: [PATCH] ColorRegistrate, Part II - Added functional interface for block vertex coloring - Removed several unused type-check-based behaviours - Belt now registers its color handler in the builder - Natural scoria now registers its color handler in the builder - Fixed wrong offset in colored vertex models --- .../java/com/simibubi/create/AllBlocks.java | 4 +- .../com/simibubi/create/AllColorHandlers.java | 20 +++++-- .../java/com/simibubi/create/AllItems.java | 1 + .../com/simibubi/create/CreateClient.java | 10 +++- .../contraptions/relays/belt/BeltBlock.java | 16 +---- .../contraptions/relays/belt/BeltColor.java | 2 +- .../content/palettes/AllPaletteBlocks.java | 3 +- ...coriaBlock.java => ScoriaVertexColor.java} | 19 +----- .../block/AbstractTileEntityContainer.java | 58 ------------------- .../foundation/block/IBlockVertexColor.java | 8 +++ .../foundation/block/IHaveColorHandler.java | 12 ---- .../block/IHaveColoredVertices.java | 19 ------ .../block/IHaveCustomBlockModel.java | 14 ----- .../foundation/block/IRenderUtilityBlock.java | 8 --- .../foundation/block/IWithContainer.java | 36 ------------ .../block/render/ColoredVertexModel.java | 18 ++---- .../foundation/data/CreateRegistrate.java | 23 ++++++-- 17 files changed, 66 insertions(+), 205 deletions(-) rename src/main/java/com/simibubi/create/content/palettes/{ScoriaBlock.java => ScoriaVertexColor.java} (53%) delete mode 100644 src/main/java/com/simibubi/create/foundation/block/AbstractTileEntityContainer.java create mode 100644 src/main/java/com/simibubi/create/foundation/block/IBlockVertexColor.java delete mode 100644 src/main/java/com/simibubi/create/foundation/block/IHaveColorHandler.java delete mode 100644 src/main/java/com/simibubi/create/foundation/block/IHaveColoredVertices.java delete mode 100644 src/main/java/com/simibubi/create/foundation/block/IHaveCustomBlockModel.java delete mode 100644 src/main/java/com/simibubi/create/foundation/block/IRenderUtilityBlock.java delete mode 100644 src/main/java/com/simibubi/create/foundation/block/IWithContainer.java diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index feb29221c..33f957fe8 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -34,8 +34,8 @@ import com.simibubi.create.content.contraptions.components.saw.SawGenerator; import com.simibubi.create.content.contraptions.components.structureMovement.bearing.ClockworkBearingBlock; import com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock; import com.simibubi.create.content.contraptions.components.structureMovement.chassis.LinearChassisBlock; -import com.simibubi.create.content.contraptions.components.structureMovement.chassis.RadialChassisBlock; import com.simibubi.create.content.contraptions.components.structureMovement.chassis.LinearChassisBlock.ChassisCTBehaviour; +import com.simibubi.create.content.contraptions.components.structureMovement.chassis.RadialChassisBlock; import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerBlock; import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerBlock.MinecartAnchorBlock; import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock; @@ -49,6 +49,7 @@ import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerB import com.simibubi.create.content.contraptions.relays.advanced.sequencer.SequencedGearshiftBlock; import com.simibubi.create.content.contraptions.relays.advanced.sequencer.SequencedGearshiftGenerator; import com.simibubi.create.content.contraptions.relays.belt.BeltBlock; +import com.simibubi.create.content.contraptions.relays.belt.BeltColor; import com.simibubi.create.content.contraptions.relays.belt.BeltGenerator; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.content.contraptions.relays.elementary.CogwheelBlockItem; @@ -240,6 +241,7 @@ public class AllBlocks { .initialProperties(SharedProperties.beltMaterial, MaterialColor.GRAY) .properties(p -> p.sound(SoundType.CLOTH)) .transform(StressConfigDefaults.setImpact(1.0)) + .transform(CreateRegistrate.blockColors(() -> BeltColor::new)) .blockstate(new BeltGenerator()::generate) .register(); diff --git a/src/main/java/com/simibubi/create/AllColorHandlers.java b/src/main/java/com/simibubi/create/AllColorHandlers.java index df89a12e1..b6e9d9167 100644 --- a/src/main/java/com/simibubi/create/AllColorHandlers.java +++ b/src/main/java/com/simibubi/create/AllColorHandlers.java @@ -3,6 +3,9 @@ package com.simibubi.create; import java.util.HashMap; import java.util.Map; +import com.simibubi.create.foundation.block.IBlockVertexColor; +import com.simibubi.create.foundation.block.render.ColoredVertexModel; + import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; @@ -19,8 +22,9 @@ import net.minecraft.world.biome.BiomeColors; public class AllColorHandlers { - private static Map coloredBlocks = new HashMap<>(); - private static Map coloredItems = new HashMap<>(); + private Map coloredVertexBlocks = new HashMap<>(); + private Map coloredBlocks = new HashMap<>(); + private Map coloredItems = new HashMap<>(); // @@ -36,15 +40,19 @@ public class AllColorHandlers { // - public static void register(Block block, IBlockColor color) { + public void register(Block block, IBlockColor color) { coloredBlocks.put(block, color); } - public static void register(IItemProvider item, IItemColor color) { + public void register(Block block, IBlockVertexColor color) { + coloredVertexBlocks.put(block, color); + } + + public void register(IItemProvider item, IItemColor color) { coloredItems.put(item, color); } - public static void registerColorHandlers() { + public void init() { BlockColors blockColors = Minecraft.getInstance() .getBlockColors(); ItemColors itemColors = Minecraft.getInstance() @@ -52,6 +60,8 @@ public class AllColorHandlers { coloredBlocks.forEach((block, color) -> blockColors.register(color, block)); coloredItems.forEach((item, color) -> itemColors.register(color, item)); + coloredVertexBlocks.forEach((block, color) -> CreateClient.getCustomBlockModels() + .register(() -> block, model -> new ColoredVertexModel(model, color))); } // diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index e22b3f62e..703b09d72 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -236,6 +236,7 @@ public enum AllItems { } @OnlyIn(Dist.CLIENT) + @Deprecated // Use CreateRegistrate#itemColor when porting AllItems public static void registerColorHandlers() { ItemColors itemColors = Minecraft.getInstance().getItemColors(); for (AllItems item : values()) { diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 3ff600309..f57d63885 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -47,7 +47,9 @@ public class CreateClient { public static SchematicAndQuillHandler schematicAndQuillHandler; public static SuperByteBufferCache bufferCache; public static Outliner outliner; + private static CustomBlockModels customBlockModels; + private static AllColorHandlers colorHandlers; public static void addListeners(IEventBus modEventBus) { DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { @@ -74,7 +76,7 @@ public class CreateClient { AllTileEntities.registerRenderers(); AllItems.registerColorHandlers(); AllEntityTypes.registerRenderers(); - AllColorHandlers.registerColorHandlers(); + getColorHandler().init(); IResourceManager resourceManager = Minecraft.getInstance() .getResourceManager(); @@ -174,5 +176,11 @@ public class CreateClient { customBlockModels = new CustomBlockModels(); return customBlockModels; } + + public static AllColorHandlers getColorHandler() { + if (colorHandlers == null) + colorHandlers = new AllColorHandlers(); + return colorHandlers; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlock.java index 3ddf932d9..dd202a31a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltBlock.java @@ -15,7 +15,6 @@ import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock; import com.simibubi.create.content.schematics.ISpecialBlockItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement.ItemUseType; -import com.simibubi.create.foundation.block.IHaveColorHandler; import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Lang; @@ -27,7 +26,6 @@ import net.minecraft.block.Blocks; import net.minecraft.block.material.Material; import net.minecraft.client.particle.DiggingParticle; import net.minecraft.client.particle.ParticleManager; -import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.entity.Entity; import net.minecraft.entity.MobEntity; import net.minecraft.entity.item.ItemEntity; @@ -69,8 +67,7 @@ import net.minecraftforge.common.Tags; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; -public class BeltBlock extends HorizontalKineticBlock - implements ITE, IHaveColorHandler, ISpecialBlockItemRequirement { +public class BeltBlock extends HorizontalKineticBlock implements ITE, ISpecialBlockItemRequirement { public static final IProperty SLOPE = EnumProperty.create("slope", Slope.class); public static final IProperty PART = EnumProperty.create("part", Part.class); @@ -415,11 +412,6 @@ public class BeltBlock extends HorizontalKineticBlock : BlockRenderType.ENTITYBLOCK_ANIMATED; } -// @Override // TODO 1.15 register layer -// public boolean canRenderInLayer(BlockState state, BlockRenderLayer layer) { -// return state.get(CASING) && state.get(SLOPE) != Slope.VERTICAL && layer == getRenderLayer(); -// } - public static void initBelt(World world, BlockPos pos) { if (world.isRemote || world.getWorldType() == WorldType.DEBUG_ALL_BLOCK_STATES) return; @@ -627,12 +619,6 @@ public class BeltBlock extends HorizontalKineticBlock return true; } - @Override - @OnlyIn(Dist.CLIENT) - public IBlockColor getColorHandler() { - return new BeltColor(); - } - @Override public Class getTileEntityClass() { return BeltTileEntity.class; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltColor.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltColor.java index d3be41a99..ed5e85f14 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltColor.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltColor.java @@ -9,7 +9,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) -class BeltColor implements IBlockColor { +public class BeltColor implements IBlockColor { @Override public int getColor(BlockState state, ILightReader reader, BlockPos pos, int layer) { diff --git a/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java b/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java index 3b7067875..8ce4d0900 100644 --- a/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java +++ b/src/main/java/com/simibubi/create/content/palettes/AllPaletteBlocks.java @@ -125,8 +125,9 @@ public class AllPaletteBlocks { public static final PalettesVariantEntry GABBRO_VARIANTS = new PalettesVariantEntry(PaletteStoneVariants.GABBRO, PaletteBlockPatterns.standardRange, GABBRO); - public static final BlockEntry NATURAL_SCORIA = REGISTRATE.block("natural_scoria", ScoriaBlock::new) + public static final BlockEntry NATURAL_SCORIA = REGISTRATE.block("natural_scoria", Block::new) .initialProperties(() -> Blocks.ANDESITE) + .transform(CreateRegistrate.blockVertexColors(new ScoriaVertexColor())) .blockstate(palettesCubeAll()) .simpleItem() .register(); diff --git a/src/main/java/com/simibubi/create/content/palettes/ScoriaBlock.java b/src/main/java/com/simibubi/create/content/palettes/ScoriaVertexColor.java similarity index 53% rename from src/main/java/com/simibubi/create/content/palettes/ScoriaBlock.java rename to src/main/java/com/simibubi/create/content/palettes/ScoriaVertexColor.java index 1aefc47dc..ef93a2872 100644 --- a/src/main/java/com/simibubi/create/content/palettes/ScoriaBlock.java +++ b/src/main/java/com/simibubi/create/content/palettes/ScoriaVertexColor.java @@ -1,24 +1,9 @@ package com.simibubi.create.content.palettes; -import com.simibubi.create.foundation.block.IHaveColoredVertices; +import com.simibubi.create.foundation.block.IBlockVertexColor; import com.simibubi.create.foundation.utility.ColorHelper; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.material.MaterialColor; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockReader; - -public class ScoriaBlock extends Block implements IHaveColoredVertices { - - public ScoriaBlock(Properties p_i48440_1_) { - super(p_i48440_1_); - } - - @Override - public MaterialColor getMaterialColor(BlockState state, IBlockReader worldIn, BlockPos pos) { - return MaterialColor.GRAY_TERRACOTTA; - } +public class ScoriaVertexColor implements IBlockVertexColor { @Override public int getColor(float x, float y, float z) { diff --git a/src/main/java/com/simibubi/create/foundation/block/AbstractTileEntityContainer.java b/src/main/java/com/simibubi/create/foundation/block/AbstractTileEntityContainer.java deleted file mode 100644 index c42f3bf1e..000000000 --- a/src/main/java/com/simibubi/create/foundation/block/AbstractTileEntityContainer.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.simibubi.create.foundation.block; - -import com.simibubi.create.AllContainerTypes; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; - -public abstract class AbstractTileEntityContainer extends Container { - - public T te; - public PlayerEntity player; - - @SuppressWarnings("unchecked") - public AbstractTileEntityContainer(AllContainerTypes containerType, int id, PlayerInventory inv, - PacketBuffer extraData) { - super(containerType.type, id); - ClientWorld world = Minecraft.getInstance().world; - this.te = (T) world.getTileEntity(extraData.readBlockPos()); - this.te.handleUpdateTag(extraData.readCompoundTag()); - this.player = inv.player; - init(); - } - - public AbstractTileEntityContainer(AllContainerTypes containerType, int id, PlayerInventory inv, T te) { - super(containerType.type, id); - this.te = te; - this.player = inv.player; - init(); - } - - protected abstract void init(); - - protected void addPlayerSlots(int x, int y) { - for (int row = 0; row < 3; ++row) - for (int col = 0; col < 9; ++col) - this.addSlot(new Slot(player.inventory, col + row * 9 + 9, x + col * 18, y + row * 18)); - for (int hotbarSlot = 0; hotbarSlot < 9; ++hotbarSlot) - this.addSlot(new Slot(player.inventory, hotbarSlot, x + hotbarSlot * 18, y + 3 * 18 + 4)); - } - - @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return true; - } - - @Override - public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { - return ItemStack.EMPTY; - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/block/IBlockVertexColor.java b/src/main/java/com/simibubi/create/foundation/block/IBlockVertexColor.java new file mode 100644 index 000000000..0a9a9d281 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/block/IBlockVertexColor.java @@ -0,0 +1,8 @@ +package com.simibubi.create.foundation.block; + +@FunctionalInterface +public interface IBlockVertexColor { + + public int getColor(float x, float y, float z); + +} diff --git a/src/main/java/com/simibubi/create/foundation/block/IHaveColorHandler.java b/src/main/java/com/simibubi/create/foundation/block/IHaveColorHandler.java deleted file mode 100644 index 88560d998..000000000 --- a/src/main/java/com/simibubi/create/foundation/block/IHaveColorHandler.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.simibubi.create.foundation.block; - -import net.minecraft.client.renderer.color.IBlockColor; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -public interface IHaveColorHandler { - - @OnlyIn(Dist.CLIENT) - public IBlockColor getColorHandler(); - -} diff --git a/src/main/java/com/simibubi/create/foundation/block/IHaveColoredVertices.java b/src/main/java/com/simibubi/create/foundation/block/IHaveColoredVertices.java deleted file mode 100644 index f9b0c1348..000000000 --- a/src/main/java/com/simibubi/create/foundation/block/IHaveColoredVertices.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.simibubi.create.foundation.block; - -import com.simibubi.create.foundation.block.render.ColoredVertexModel; - -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -public interface IHaveColoredVertices extends IHaveCustomBlockModel { - - public int getColor(float x, float y, float z); - - @Override - @OnlyIn(Dist.CLIENT) - default IBakedModel createModel(IBakedModel original) { - return new ColoredVertexModel(original, this); - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/block/IHaveCustomBlockModel.java b/src/main/java/com/simibubi/create/foundation/block/IHaveCustomBlockModel.java deleted file mode 100644 index 40d6920be..000000000 --- a/src/main/java/com/simibubi/create/foundation/block/IHaveCustomBlockModel.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.simibubi.create.foundation.block; - -import javax.annotation.Nullable; - -import net.minecraft.client.renderer.model.IBakedModel; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -public interface IHaveCustomBlockModel { - - @OnlyIn(value = Dist.CLIENT) - public IBakedModel createModel(@Nullable IBakedModel original); - -} diff --git a/src/main/java/com/simibubi/create/foundation/block/IRenderUtilityBlock.java b/src/main/java/com/simibubi/create/foundation/block/IRenderUtilityBlock.java deleted file mode 100644 index 9757cd295..000000000 --- a/src/main/java/com/simibubi/create/foundation/block/IRenderUtilityBlock.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.simibubi.create.foundation.block; - -/** - * Blocks only registered for use in other blocks' renderers. - */ -public interface IRenderUtilityBlock { - -} diff --git a/src/main/java/com/simibubi/create/foundation/block/IWithContainer.java b/src/main/java/com/simibubi/create/foundation/block/IWithContainer.java deleted file mode 100644 index b57e86d09..000000000 --- a/src/main/java/com/simibubi/create/foundation/block/IWithContainer.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.simibubi.create.foundation.block; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; - -public interface IWithContainer> extends INamedContainerProvider { - - public IContainerFactory getContainerFactory(); - - @SuppressWarnings("unchecked") - @Override - default Container createMenu(int id, PlayerInventory inv, PlayerEntity player) { - return getContainerFactory().create(id, inv, ((T) this)); - } - - @Override - default ITextComponent getDisplayName() { - return new StringTextComponent(((TileEntity) this).getType().getRegistryName().toString()); - } - - public interface IContainerFactory> { - public C create(int id, PlayerInventory inv, T te); - } - - default void sendToContainer(PacketBuffer buffer) { - buffer.writeBlockPos(((TileEntity) this).getPos()); - buffer.writeCompoundTag(((TileEntity) this).getUpdateTag()); - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/block/render/ColoredVertexModel.java b/src/main/java/com/simibubi/create/foundation/block/render/ColoredVertexModel.java index 5f6ed7714..391801a9b 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/ColoredVertexModel.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/ColoredVertexModel.java @@ -5,7 +5,7 @@ import java.util.Arrays; import java.util.List; import java.util.Random; -import com.simibubi.create.foundation.block.IHaveColoredVertices; +import com.simibubi.create.foundation.block.IBlockVertexColor; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.BakedQuad; @@ -22,12 +22,12 @@ import net.minecraftforge.client.model.data.ModelProperty; public class ColoredVertexModel extends BakedModelWrapper { - private IHaveColoredVertices colorer; + private IBlockVertexColor color; private static ModelProperty POSITION_PROPERTY = new ModelProperty<>(); - public ColoredVertexModel(IBakedModel originalModel, IHaveColoredVertices colorer) { + public ColoredVertexModel(IBakedModel originalModel, IBlockVertexColor color) { super(originalModel); - this.colorer = colorer; + this.color = color; } @Override @@ -38,13 +38,11 @@ public class ColoredVertexModel extends BakedModelWrapper { @Override public List getQuads(BlockState state, Direction side, Random rand, IModelData extraData) { List quads = new ArrayList<>(super.getQuads(state, side, rand, extraData)); - if (!extraData.hasProperty(POSITION_PROPERTY)) return quads; for (int i = 0; i < quads.size(); i++) { BakedQuad quad = quads.get(i); - BakedQuad newQuad = new BakedQuad(Arrays.copyOf(quad.getVertexData(), quad.getVertexData().length), quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting()); @@ -52,16 +50,12 @@ public class ColoredVertexModel extends BakedModelWrapper { int[] vertexData = newQuad.getVertexData(); BlockPos data = extraData.getData(POSITION_PROPERTY); -// Direction direction = quad.getFace(); -// if (direction.getAxis().isHorizontal()) -// continue; - for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) { - int colorOffset = 16 / 4; // TODO 1.15 is this the right offset? + int colorOffset = 12 / 4; float x = Float.intBitsToFloat(vertexData[vertex]); float y = Float.intBitsToFloat(vertexData[vertex + 1]); float z = Float.intBitsToFloat(vertexData[vertex + 2]); - int color = colorer.getColor(x + data.getX(), y + data.getY(), z + data.getZ()); + int color = this.color.getColor(x + data.getX(), y + data.getY(), z + data.getZ()); vertexData[vertex + colorOffset] = color; } diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java b/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java index a63de148a..e353b6e77 100644 --- a/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java +++ b/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java @@ -7,9 +7,9 @@ import java.util.Map.Entry; import java.util.function.Supplier; import java.util.stream.Collectors; -import com.simibubi.create.AllColorHandlers; import com.simibubi.create.CreateClient; import com.simibubi.create.content.AllSections; +import com.simibubi.create.foundation.block.IBlockVertexColor; import com.simibubi.create.foundation.block.connected.CTModel; import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour; import com.tterrag.registrate.AbstractRegistrate; @@ -119,6 +119,11 @@ public class CreateRegistrate extends AbstractRegistrate { return b -> b.onRegister(entry -> onClient(() -> () -> registerBlockColor(entry, colorFunc))); } + public static NonNullUnaryOperator> blockVertexColors( + IBlockVertexColor colorFunc) { + return b -> b.onRegister(entry -> onClient(() -> () -> registerBlockVertexColor(entry, colorFunc))); + } + public static NonNullUnaryOperator> itemColors( Supplier> colorFunc) { return b -> b.onRegister(entry -> onClient(() -> () -> registerItemColor(entry, colorFunc))); @@ -136,14 +141,22 @@ public class CreateRegistrate extends AbstractRegistrate { @OnlyIn(Dist.CLIENT) private static void registerBlockColor(Block entry, Supplier> colorFunc) { - AllColorHandlers.register(entry, colorFunc.get() - .get()); + CreateClient.getColorHandler() + .register(entry, colorFunc.get() + .get()); + } + + @OnlyIn(Dist.CLIENT) + private static void registerBlockVertexColor(Block entry, IBlockVertexColor colorFunc) { + CreateClient.getColorHandler() + .register(entry, colorFunc); } @OnlyIn(Dist.CLIENT) private static void registerItemColor(IItemProvider entry, Supplier> colorFunc) { - AllColorHandlers.register(entry, colorFunc.get() - .get()); + CreateClient.getColorHandler() + .register(entry, colorFunc.get() + .get()); } }