ColorRegistrate

- Added support for Block & ItemColors in CreateRegistrate
- Updated forge and removed obsolete warning suppressions
- Fixed mossy & overgrown block items not having their foliage layer coloured
This commit is contained in:
simibubi 2020-05-24 03:12:18 +02:00
parent 61aab48cdb
commit e9c26eed0a
18 changed files with 180 additions and 72 deletions

View file

@ -95,7 +95,7 @@ configurations {
}
dependencies {
minecraft 'net.minecraftforge:forge:1.15.2-31.2.0'
minecraft 'net.minecraftforge:forge:1.15.2-31.2.3'
def registrate = "com.tterrag.registrate:Registrate:MC1.15.2-0.0.3.11"
implementation fg.deobf(registrate)

View file

@ -1419,8 +1419,8 @@ cb315814960850b5080598b89ee94c833b5048f7 data\create\loot_tables\blocks\limeston
8db1e3f0dac48b91a4839206a7d5a88cef415fdc data\create\loot_tables\blocks\limestone_cobblestone_stairs.json
92fb16606f289ad33860270d098fad2522b24e09 data\create\loot_tables\blocks\limestone_cobblestone_wall.json
371115e5ceb08c07a9ab2371509960c31e0baa8a data\create\loot_tables\blocks\limestone_pillar.json
205f5899101262f31f5c1a88bb7d954918d08d04 data\create\loot_tables\blocks\linked_extractor.json
205f5899101262f31f5c1a88bb7d954918d08d04 data\create\loot_tables\blocks\linked_transposer.json
dac789cf53b00eed34308848b5e267b7ccec090c data\create\loot_tables\blocks\linked_extractor.json
7af5a13c9e10903b11732fbc01ae3299328216f0 data\create\loot_tables\blocks\linked_transposer.json
90ddf7b5c3b61758a4ad12a1e6ef16fe6ebf7794 data\create\loot_tables\blocks\mechanical_bearing.json
e93872a90e4f4642a003539e7db28fdacfdcd114 data\create\loot_tables\blocks\mechanical_crafter.json
b12efeeef5682966016ce6ea2d171eecd33d9667 data\create\loot_tables\blocks\mechanical_mixer.json

View file

@ -6,7 +6,7 @@
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:air"
"name": "create:linked_extractor"
}
],
"conditions": [

View file

@ -6,7 +6,7 @@
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:air"
"name": "create:linked_transposer"
}
],
"conditions": [

View file

@ -0,0 +1,99 @@
package com.simibubi.create;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GrassColors;
import net.minecraft.world.ILightReader;
import net.minecraft.world.biome.BiomeColors;
public class AllColorHandlers {
private static Map<Block, IBlockColor> coloredBlocks = new HashMap<>();
private static Map<IItemProvider, IItemColor> coloredItems = new HashMap<>();
//
public static IBlockColor getGrassyBlock() {
return new BlockColor(
(state, world, pos, layer) -> pos != null && world != null ? BiomeColors.getGrassColor(world, pos)
: GrassColors.get(0.5D, 1.0D));
}
public static IItemColor getGrassyItem() {
return new ItemColor((stack, layer) -> GrassColors.get(0.5D, 1.0D));
}
//
public static void register(Block block, IBlockColor color) {
coloredBlocks.put(block, color);
}
public static void register(IItemProvider item, IItemColor color) {
coloredItems.put(item, color);
}
public static void registerColorHandlers() {
BlockColors blockColors = Minecraft.getInstance()
.getBlockColors();
ItemColors itemColors = Minecraft.getInstance()
.getItemColors();
coloredBlocks.forEach((block, color) -> blockColors.register(color, block));
coloredItems.forEach((item, color) -> itemColors.register(color, item));
}
//
private static class ItemColor implements IItemColor {
private Function function;
@FunctionalInterface
interface Function {
int apply(ItemStack stack, int layer);
}
public ItemColor(Function function) {
this.function = function;
}
@Override
public int getColor(ItemStack stack, int layer) {
return function.apply(stack, layer);
}
}
private static class BlockColor implements IBlockColor {
private Function function;
@FunctionalInterface
interface Function {
int apply(BlockState state, ILightReader world, BlockPos pos, int layer);
}
public BlockColor(Function function) {
this.function = function;
}
@Override
public int getColor(BlockState state, ILightReader world, BlockPos pos, int layer) {
return function.apply(state, world, pos, layer);
}
}
}

View file

@ -12,7 +12,6 @@ import com.simibubi.create.content.schematics.ClientSchematicLoader;
import com.simibubi.create.content.schematics.client.SchematicAndQuillHandler;
import com.simibubi.create.content.schematics.client.SchematicHandler;
import com.simibubi.create.foundation.ResourceReloadHandler;
import com.simibubi.create.foundation.block.IHaveColorHandler;
import com.simibubi.create.foundation.block.render.CustomBlockModels;
import com.simibubi.create.foundation.block.render.SpriteShifter;
import com.simibubi.create.foundation.item.IHaveCustomItemModel;
@ -21,12 +20,10 @@ import com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkRenderer;
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueRenderer;
import com.simibubi.create.foundation.utility.SuperByteBufferCache;
import com.simibubi.create.foundation.utility.outliner.Outliner;
import com.tterrag.registrate.util.entry.RegistryEntry;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.inventory.container.PlayerContainer;
@ -77,7 +74,7 @@ public class CreateClient {
AllTileEntities.registerRenderers();
AllItems.registerColorHandlers();
AllEntityTypes.registerRenderers();
registerColorHandlers();
AllColorHandlers.registerColorHandlers();
IResourceManager resourceManager = Minecraft.getInstance()
.getResourceManager();
@ -172,19 +169,6 @@ public class CreateClient {
});
}
@OnlyIn(Dist.CLIENT)
protected static void registerColorHandlers() {
BlockColors blockColors = Minecraft.getInstance()
.getBlockColors();
for (RegistryEntry<Block> registryEntry : Create.registrate()
.getAll(Block.class)) {
Block blockEntry = registryEntry.get();
if (blockEntry instanceof IHaveColorHandler) {
blockColors.register(((IHaveColorHandler) blockEntry).getColorHandler(), blockEntry);
}
}
}
public static CustomBlockModels getCustomBlockModels() {
if (customBlockModels == null)
customBlockModels = new CustomBlockModels();

View file

@ -25,7 +25,6 @@ import net.minecraft.util.Direction;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.MathHelper;
@SuppressWarnings("deprecation")
public class SawTileEntityRenderer extends SafeTileEntityRenderer<SawTileEntity> {
public SawTileEntityRenderer(TileEntityRendererDispatcher dispatcher) {

View file

@ -17,7 +17,6 @@ import net.minecraft.util.math.Vec3d;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;
@SuppressWarnings("deprecation")
public class BasinTileEntityRenderer extends SafeTileEntityRenderer<BasinTileEntity> {
public BasinTileEntityRenderer(TileEntityRendererDispatcher dispatcher) {

View file

@ -17,7 +17,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.MathHelper;
@SuppressWarnings("deprecation")
public class SandPaperItemRenderer extends ItemStackTileEntityRenderer {
@Override

View file

@ -25,7 +25,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.HandSide;
import net.minecraft.util.math.MathHelper;
@SuppressWarnings("deprecation")
public class BlockzapperItemRenderer extends ZapperItemRenderer {
@Override

View file

@ -16,7 +16,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.HandSide;
import net.minecraft.util.math.MathHelper;
@SuppressWarnings("deprecation")
public class TerrainzapperItemRenderer extends ZapperItemRenderer {
@Override

View file

@ -1,22 +0,0 @@
package com.simibubi.create.content.palettes;
import com.simibubi.create.foundation.block.IHaveColorHandler;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class MossyBlock extends Block implements IHaveColorHandler {
public MossyBlock(Properties p_i48440_1_) {
super(p_i48440_1_);
}
@Override
@OnlyIn(Dist.CLIENT)
public IBlockColor getColorHandler() {
return new StandardFoliageColorHandler();
}
}

View file

@ -57,14 +57,14 @@ public class PaletteBlockPatterns {
.textures("pillar", "pillar_end"),
MOSSY = create("mossy", Prefix).blockStateFactory(p -> p::cubeAllButMossy)
.block(MossyBlock::new)
.textures("bricks", "mossy")
.useTranslucentLayer(),
.useTranslucentLayer()
.withFoliage(),
OVERGROWN = create("overgrown", Prefix).blockStateFactory(p -> p::cubeAllButMossy)
.block(MossyBlock::new)
.textures("bricks", "overgrown")
.useTranslucentLayer()
.withFoliage()
;
@ -81,6 +81,7 @@ public class PaletteBlockPatterns {
private String[] textures;
private String id;
private boolean isTranslucent;
private boolean hasFoliage;
private Optional<Function<PaletteStoneVariants, ConnectedTextureBehaviour>> ctBehaviour;
private IPatternBlockStateGenerator blockStateGenerator;
@ -98,6 +99,7 @@ public class PaletteBlockPatterns {
pattern.nameType = nameType;
pattern.partials = partials;
pattern.isTranslucent = false;
pattern.hasFoliage = false;
pattern.blockFactory = Block::new;
pattern.textures = new String[] { name };
pattern.blockStateGenerator = p -> p::cubeAll;
@ -112,6 +114,10 @@ public class PaletteBlockPatterns {
return isTranslucent;
}
public boolean hasFoliage() {
return hasFoliage;
}
public NonNullFunction<Properties, ? extends Block> getBlockFactory() {
return blockFactory;
}
@ -150,6 +156,11 @@ public class PaletteBlockPatterns {
return this;
}
private PaletteBlockPatterns withFoliage() {
hasFoliage = true;
return this;
}
private PaletteBlockPatterns connectedTextures(Function<PaletteStoneVariants, ConnectedTextureBehaviour> factory) {
this.ctBehaviour = Optional.of(factory);
return this;

View file

@ -3,6 +3,7 @@ package com.simibubi.create.content.palettes;
import static com.simibubi.create.foundation.data.CreateRegistrate.connectedTextures;
import com.google.common.collect.ImmutableList;
import com.simibubi.create.AllColorHandlers;
import com.simibubi.create.Create;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.simibubi.create.foundation.utility.Lang;
@ -29,18 +30,26 @@ public class PalettesVariantEntry {
CreateRegistrate registrate = Create.registrate();
BlockBuilder<? extends Block, CreateRegistrate> builder =
registrate.block(pattern.createName(name), pattern.getBlockFactory())
.initialProperties(initialProperties)
.blockstate(pattern.getBlockStateGenerator()
.apply(pattern)
.apply(name)::accept);
if (pattern.isTranslucent())
builder.addLayer(() -> RenderType::getTranslucent);
if (pattern.hasFoliage())
builder.transform(CreateRegistrate.blockColors(() -> AllColorHandlers::getGrassyBlock));
pattern.createCTBehaviour(variant)
.ifPresent(b -> builder.transform(connectedTextures(b)));
BlockEntry<? extends Block> block = builder.initialProperties(initialProperties)
.simpleItem()
.register();
if (pattern.hasFoliage())
builder.item()
.transform(CreateRegistrate.itemColors(() -> AllColorHandlers::getGrassyItem)::apply)
.build();
else
builder.simpleItem();
BlockEntry<? extends Block> block = builder.register();
registeredBlocks.add(block);
for (PaletteBlockPartial<? extends Block> partialBlock : pattern.getPartials())

View file

@ -15,7 +15,6 @@ import net.minecraft.util.Direction;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.data.IModelData;
@SuppressWarnings("deprecation")
public class WrappedBakedModel implements IBakedModel {
protected IBakedModel template;

View file

@ -4,8 +4,10 @@ import java.util.Collection;
import java.util.IdentityHashMap;
import java.util.Map;
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.connected.CTModel;
@ -13,6 +15,7 @@ import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour;
import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.builders.BlockBuilder;
import com.tterrag.registrate.builders.Builder;
import com.tterrag.registrate.builders.ItemBuilder;
import com.tterrag.registrate.util.NonNullLazyValue;
import com.tterrag.registrate.util.entry.RegistryEntry;
import com.tterrag.registrate.util.nullness.NonNullFunction;
@ -21,6 +24,10 @@ import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import net.minecraft.block.Block;
import net.minecraft.block.Block.Properties;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.item.BlockItem;
import net.minecraft.util.IItemProvider;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.DistExecutor;
@ -35,8 +42,9 @@ public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
}
public static NonNullLazyValue<CreateRegistrate> lazy(String modid) {
return new NonNullLazyValue<>(() -> new CreateRegistrate(modid)
.registerEventListeners(FMLJavaModLoadingContext.get().getModEventBus()));
return new NonNullLazyValue<>(
() -> new CreateRegistrate(modid).registerEventListeners(FMLJavaModLoadingContext.get()
.getModEventBus()));
}
/* Section Tracking */
@ -80,8 +88,10 @@ public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
.orElse(AllSections.UNASSIGNED);
}
public <R extends IForgeRegistryEntry<R>> Collection<RegistryEntry<R>> getAll(AllSections section, Class<? super R> registryType) {
return this.<R>getAll(registryType).stream()
public <R extends IForgeRegistryEntry<R>> Collection<RegistryEntry<R>> getAll(AllSections section,
Class<? super R> registryType) {
return this.<R>getAll(registryType)
.stream()
.filter(e -> getSection(e) == section)
.collect(Collectors.toList());
}
@ -101,7 +111,21 @@ public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
public static <T extends Block> NonNullUnaryOperator<BlockBuilder<T, CreateRegistrate>> connectedTextures(
ConnectedTextureBehaviour behavior) {
return b -> b.onRegister(entry -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> registerModel(entry, behavior)));
return b -> b.onRegister(entry -> onClient(() -> () -> registerModel(entry, behavior)));
}
public static <T extends Block> NonNullUnaryOperator<BlockBuilder<T, CreateRegistrate>> blockColors(
Supplier<Supplier<IBlockColor>> colorFunc) {
return b -> b.onRegister(entry -> onClient(() -> () -> registerBlockColor(entry, colorFunc)));
}
public static NonNullUnaryOperator<ItemBuilder<? extends BlockItem, ?>> itemColors(
Supplier<Supplier<IItemColor>> colorFunc) {
return b -> b.onRegister(entry -> onClient(() -> () -> registerItemColor(entry, colorFunc)));
}
protected static void onClient(Supplier<Runnable> toRun) {
DistExecutor.runWhenOn(Dist.CLIENT, toRun);
}
@OnlyIn(Dist.CLIENT)
@ -109,4 +133,17 @@ public class CreateRegistrate extends AbstractRegistrate<CreateRegistrate> {
CreateClient.getCustomBlockModels()
.register(entry.delegate, model -> new CTModel(model, behavior));
}
@OnlyIn(Dist.CLIENT)
private static void registerBlockColor(Block entry, Supplier<Supplier<IBlockColor>> colorFunc) {
AllColorHandlers.register(entry, colorFunc.get()
.get());
}
@OnlyIn(Dist.CLIENT)
private static void registerItemColor(IItemProvider entry, Supplier<Supplier<IItemColor>> colorFunc) {
AllColorHandlers.register(entry, colorFunc.get()
.get());
}
}

View file

@ -17,7 +17,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tags.BlockTags;
@SuppressWarnings("deprecation")
public class ValueBoxRenderer {
public static void renderItemIntoValueBox(ItemStack filter, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {

View file

@ -1,3 +0,0 @@
{
"parent": "create:block/schematic_table"
}