diff --git a/build.gradle b/build.gradle index e0e893ea6..aaa7cd4e5 100644 --- a/build.gradle +++ b/build.gradle @@ -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) diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 910fcc290..4f78f52c1 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -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 diff --git a/src/generated/resources/data/create/loot_tables/blocks/linked_extractor.json b/src/generated/resources/data/create/loot_tables/blocks/linked_extractor.json index 78793172c..3faa7e519 100644 --- a/src/generated/resources/data/create/loot_tables/blocks/linked_extractor.json +++ b/src/generated/resources/data/create/loot_tables/blocks/linked_extractor.json @@ -6,7 +6,7 @@ "entries": [ { "type": "minecraft:item", - "name": "minecraft:air" + "name": "create:linked_extractor" } ], "conditions": [ diff --git a/src/generated/resources/data/create/loot_tables/blocks/linked_transposer.json b/src/generated/resources/data/create/loot_tables/blocks/linked_transposer.json index 78793172c..31ecac893 100644 --- a/src/generated/resources/data/create/loot_tables/blocks/linked_transposer.json +++ b/src/generated/resources/data/create/loot_tables/blocks/linked_transposer.json @@ -6,7 +6,7 @@ "entries": [ { "type": "minecraft:item", - "name": "minecraft:air" + "name": "create:linked_transposer" } ], "conditions": [ diff --git a/src/main/java/com/simibubi/create/AllColorHandlers.java b/src/main/java/com/simibubi/create/AllColorHandlers.java new file mode 100644 index 000000000..df89a12e1 --- /dev/null +++ b/src/main/java/com/simibubi/create/AllColorHandlers.java @@ -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 coloredBlocks = new HashMap<>(); + private static Map 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); + } + + } + +} diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index d8552b941..3ff600309 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -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(); @@ -171,19 +168,6 @@ public class CreateClient { swapModels(modelRegistry, location, factory); }); } - - @OnlyIn(Dist.CLIENT) - protected static void registerColorHandlers() { - BlockColors blockColors = Minecraft.getInstance() - .getBlockColors(); - for (RegistryEntry 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) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntityRenderer.java index 23a6416fa..63c2db5b7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawTileEntityRenderer.java @@ -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 { public SawTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntityRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntityRenderer.java index 01baf51c9..cc7781d40 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/BasinTileEntityRenderer.java @@ -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 { public BasinTileEntityRenderer(TileEntityRendererDispatcher dispatcher) { diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java index 5aee228fc..78b741a2b 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/SandPaperItemRenderer.java @@ -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 diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java index 163509651..c1bd030e3 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItemRenderer.java @@ -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 diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/TerrainzapperItemRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/TerrainzapperItemRenderer.java index 53a14f228..e8a85bc16 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/TerrainzapperItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/TerrainzapperItemRenderer.java @@ -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 diff --git a/src/main/java/com/simibubi/create/content/palettes/MossyBlock.java b/src/main/java/com/simibubi/create/content/palettes/MossyBlock.java deleted file mode 100644 index d882ac47d..000000000 --- a/src/main/java/com/simibubi/create/content/palettes/MossyBlock.java +++ /dev/null @@ -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(); - } - -} diff --git a/src/main/java/com/simibubi/create/content/palettes/PaletteBlockPatterns.java b/src/main/java/com/simibubi/create/content/palettes/PaletteBlockPatterns.java index 4d6ccc015..998b35543 100644 --- a/src/main/java/com/simibubi/create/content/palettes/PaletteBlockPatterns.java +++ b/src/main/java/com/simibubi/create/content/palettes/PaletteBlockPatterns.java @@ -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> 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; @@ -111,6 +113,10 @@ public class PaletteBlockPatterns { public boolean isTranslucent() { return isTranslucent; } + + public boolean hasFoliage() { + return hasFoliage; + } public NonNullFunction getBlockFactory() { return blockFactory; @@ -150,6 +156,11 @@ public class PaletteBlockPatterns { return this; } + private PaletteBlockPatterns withFoliage() { + hasFoliage = true; + return this; + } + private PaletteBlockPatterns connectedTextures(Function factory) { this.ctBehaviour = Optional.of(factory); return this; diff --git a/src/main/java/com/simibubi/create/content/palettes/PalettesVariantEntry.java b/src/main/java/com/simibubi/create/content/palettes/PalettesVariantEntry.java index 4f7fb2a27..3bfd287f3 100644 --- a/src/main/java/com/simibubi/create/content/palettes/PalettesVariantEntry.java +++ b/src/main/java/com/simibubi/create/content/palettes/PalettesVariantEntry.java @@ -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 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 block = builder.initialProperties(initialProperties) - .simpleItem() - .register(); + if (pattern.hasFoliage()) + builder.item() + .transform(CreateRegistrate.itemColors(() -> AllColorHandlers::getGrassyItem)::apply) + .build(); + else + builder.simpleItem(); + + BlockEntry block = builder.register(); registeredBlocks.add(block); for (PaletteBlockPartial partialBlock : pattern.getPartials()) diff --git a/src/main/java/com/simibubi/create/foundation/block/render/WrappedBakedModel.java b/src/main/java/com/simibubi/create/foundation/block/render/WrappedBakedModel.java index 8a2f84f63..cf545c8ee 100644 --- a/src/main/java/com/simibubi/create/foundation/block/render/WrappedBakedModel.java +++ b/src/main/java/com/simibubi/create/foundation/block/render/WrappedBakedModel.java @@ -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; 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 b5662ea1e..a63de148a 100644 --- a/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java +++ b/src/main/java/com/simibubi/create/foundation/data/CreateRegistrate.java @@ -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 { } public static NonNullLazyValue 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 */ @@ -55,8 +63,8 @@ public class CreateRegistrate extends AbstractRegistrate { @Override protected , T extends R> RegistryEntry accept(String name, - Class type, Builder builder, NonNullSupplier creator, - NonNullFunction, ? extends RegistryEntry> entryFactory) { + Class type, Builder builder, NonNullSupplier creator, + NonNullFunction, ? extends RegistryEntry> entryFactory) { RegistryEntry ret = super.accept(name, type, builder, creator, entryFactory); sectionLookup.put(ret, currentSection()); return ret; @@ -79,15 +87,17 @@ public class CreateRegistrate extends AbstractRegistrate { .findFirst() .orElse(AllSections.UNASSIGNED); } - - public > Collection> getAll(AllSections section, Class registryType) { - return this.getAll(registryType).stream() - .filter(e -> getSection(e) == section) - .collect(Collectors.toList()); + + public > Collection> getAll(AllSections section, + Class registryType) { + return this.getAll(registryType) + .stream() + .filter(e -> getSection(e) == section) + .collect(Collectors.toList()); } - + /* Palettes */ - + public BlockBuilder baseBlock(String name, NonNullFunction factory, NonNullSupplier propertiesFrom) { return super.block(name, factory).initialProperties(propertiesFrom) @@ -101,7 +111,21 @@ public class CreateRegistrate extends AbstractRegistrate { public static NonNullUnaryOperator> 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 NonNullUnaryOperator> blockColors( + Supplier> colorFunc) { + return b -> b.onRegister(entry -> onClient(() -> () -> registerBlockColor(entry, colorFunc))); + } + + public static NonNullUnaryOperator> itemColors( + Supplier> colorFunc) { + return b -> b.onRegister(entry -> onClient(() -> () -> registerItemColor(entry, colorFunc))); + } + + protected static void onClient(Supplier toRun) { + DistExecutor.runWhenOn(Dist.CLIENT, toRun); } @OnlyIn(Dist.CLIENT) @@ -109,4 +133,17 @@ public class CreateRegistrate extends AbstractRegistrate { CreateClient.getCustomBlockModels() .register(entry.delegate, model -> new CTModel(model, behavior)); } + + @OnlyIn(Dist.CLIENT) + private static void registerBlockColor(Block entry, Supplier> colorFunc) { + AllColorHandlers.register(entry, colorFunc.get() + .get()); + } + + @OnlyIn(Dist.CLIENT) + private static void registerItemColor(IItemProvider entry, Supplier> colorFunc) { + AllColorHandlers.register(entry, colorFunc.get() + .get()); + } + } diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBoxRenderer.java b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBoxRenderer.java index d35672133..e27466235 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBoxRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBoxRenderer.java @@ -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) { diff --git a/src/main/resources/assets/create/models/item/schematic_table.json b/src/main/resources/assets/create/models/item/schematic_table.json deleted file mode 100644 index b718d873b..000000000 --- a/src/main/resources/assets/create/models/item/schematic_table.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "create:block/schematic_table" -} \ No newline at end of file