diff --git a/src/main/java/net/zepalesque/redux/Redux.java b/src/main/java/net/zepalesque/redux/Redux.java index a4ba0bdfe..75bc84593 100644 --- a/src/main/java/net/zepalesque/redux/Redux.java +++ b/src/main/java/net/zepalesque/redux/Redux.java @@ -13,7 +13,10 @@ import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.metadata.pack.PackMetadataSection; import net.minecraft.util.InclusiveRange; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.DistExecutor; import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.common.Mod; import net.neoforged.fml.config.ModConfig; @@ -21,12 +24,16 @@ import net.neoforged.neoforge.common.data.DatapackBuiltinEntriesProvider; import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.neoforged.neoforge.data.event.GatherDataEvent; +import net.neoforged.neoforge.registries.datamaps.RegisterDataMapTypesEvent; import net.zepalesque.redux.block.ReduxBlocks; import net.zepalesque.redux.blockset.stone.ReduxStoneSets; import net.zepalesque.redux.blockset.wood.ReduxWoodSets; +import net.zepalesque.redux.client.ReduxColors; import net.zepalesque.redux.config.ReduxConfig; import net.zepalesque.redux.config.ReduxConfigHandler; +import net.zepalesque.redux.data.ReduxDataMaps; import net.zepalesque.redux.data.gen.ReduxBlockStateGen; +import net.zepalesque.redux.data.gen.ReduxDataMapGen; import net.zepalesque.redux.data.gen.ReduxItemModelGen; import net.zepalesque.redux.data.gen.ReduxLanguageGen; import net.zepalesque.redux.data.gen.ReduxLootGen; @@ -37,6 +44,8 @@ import net.zepalesque.redux.entity.ReduxEntities; import net.zepalesque.redux.item.ReduxItems; import net.zepalesque.redux.tile.ReduxTiles; +import net.zepalesque.redux.world.biome.tint.ReduxBiomeTints; +import net.zepalesque.zenith.api.biometint.BiomeTints; import net.zepalesque.zenith.api.blockset.AbstractStoneSet; import net.zepalesque.zenith.api.blockset.AbstractWoodSet; import net.zepalesque.zenith.api.condition.ConfigCondition; @@ -51,15 +60,21 @@ @Mod(Redux.MODID) public class Redux { public static final String MODID = "aether_redux"; - private static final Logger LOGGER = LogUtils.getLogger(); + public static final Logger LOGGER = LogUtils.getLogger(); public static final Collection WOOD_SETS = new ArrayList<>(); public static final Collection STONE_SETS = new ArrayList<>(); - public Redux(IEventBus bus) { + public Redux(IEventBus bus, Dist dist) { bus.addListener(this::commonSetup); bus.addListener(this::dataSetup); + bus.addListener(this::registerDataMaps); + if (dist == Dist.CLIENT) { + bus.addListener(EventPriority.LOWEST, ReduxColors::blockColors); + bus.addListener(ReduxColors::itemColors); + bus.addListener(ReduxColors::resolvers); + } ReduxWoodSets.init(); ReduxStoneSets.init(); @@ -68,6 +83,8 @@ public Redux(IEventBus bus) { ReduxItems.ITEMS.register(bus); ReduxEntities.ENTITIES.register(bus); ReduxTiles.TILES.register(bus); + ReduxBiomeTints.TINTS.register(bus); + ReduxConfigHandler.setup(bus); ConfigCondition.registerSerializer("redux_server", new ConfigSerializer(ReduxConfig.Server::serialize, ReduxConfig.Server::deserialize)); @@ -81,6 +98,9 @@ private void commonSetup(final FMLCommonSetupEvent event) { }); } + private void registerDataMaps(RegisterDataMapTypesEvent event) { + } + private void dataSetup(GatherDataEvent event) { DataGenerator generator = event.getGenerator(); ExistingFileHelper fileHelper = event.getExistingFileHelper(); diff --git a/src/main/java/net/zepalesque/redux/block/natural/AetherShortGrassBlock.java b/src/main/java/net/zepalesque/redux/block/natural/AetherShortGrassBlock.java index dd08d1d92..c8b450cfa 100644 --- a/src/main/java/net/zepalesque/redux/block/natural/AetherShortGrassBlock.java +++ b/src/main/java/net/zepalesque/redux/block/natural/AetherShortGrassBlock.java @@ -35,7 +35,7 @@ public class AetherShortGrassBlock extends AetherBushBlock { public AetherShortGrassBlock(Properties properties) { super(properties); - this.registerDefaultState(this.defaultBlockState().setValue(ReduxStates.ENCHANTED, false).setValue(ReduxStates.GRASS_SIZE, GrassSize.medium)); + this.registerDefaultState(this.defaultBlockState().setValue(ReduxStates.ENCHANTED, false).setValue(ReduxStates.GRASS_SIZE, GrassSize.MEDIUM)); } public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) { GrassSize size = pState.getValue(ReduxStates.GRASS_SIZE); diff --git a/src/main/java/net/zepalesque/redux/block/state/enums/GrassSize.java b/src/main/java/net/zepalesque/redux/block/state/enums/GrassSize.java index 36e2f9209..91a20aa33 100644 --- a/src/main/java/net/zepalesque/redux/block/state/enums/GrassSize.java +++ b/src/main/java/net/zepalesque/redux/block/state/enums/GrassSize.java @@ -3,7 +3,7 @@ import net.minecraft.util.StringRepresentable; public enum GrassSize implements StringRepresentable { - small("small"), medium("medium"), tall("tall"); + SHORT("short"), MEDIUM("medoium"), TALL("tall"); final String name; GrassSize(String name) { diff --git a/src/main/java/net/zepalesque/redux/client/ReduxColors.java b/src/main/java/net/zepalesque/redux/client/ReduxColors.java new file mode 100644 index 000000000..5c309915f --- /dev/null +++ b/src/main/java/net/zepalesque/redux/client/ReduxColors.java @@ -0,0 +1,128 @@ +package net.zepalesque.redux.client; + +import com.aetherteam.aether.block.AetherBlocks; +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.color.item.ItemColor; +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.ColorResolver; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent; +import net.zepalesque.redux.Redux; +import net.zepalesque.redux.block.ReduxBlocks; +import net.zepalesque.redux.block.state.ReduxStates; +import net.zepalesque.redux.data.ReduxTags; +import net.zepalesque.redux.world.biome.tint.ReduxBiomeTints; + +import javax.annotation.Nullable; +import java.util.function.Consumer; + +public class ReduxColors { + + public static class Tints { + public static final int AETHER_GRASS_COLOR = 0xADF9C4; + public static final int BLIGHT_GRASS_COLOR = 0xD5BAFF; + } + + public static ColorResolver AETHER_GRASS = (biome, x, z) -> ReduxBiomeTints.AETHER_GRASS.get().getColor(biome); + + public static void blockColors(RegisterColorHandlersEvent.Block event) { + Redux.LOGGER.debug("Beginning block color registration for the Aether: Redux"); + + event.register((state, level, pos, index) -> getColor(state, level, pos, index, 1, false), AetherBlocks.AETHER_GRASS_BLOCK.get()); + event.register((state, level, pos, index) -> getColor(state, level, pos, index, 0, true), ReduxBlocks.SHORT_AETHER_GRASS.get()); + event.register((state, level, pos, index) -> getColor(state, level, pos, index, 1, true), + AetherBlocks.WHITE_FLOWER.get(), + AetherBlocks.POTTED_WHITE_FLOWER.get(), + AetherBlocks.PURPLE_FLOWER.get(), + AetherBlocks.POTTED_PURPLE_FLOWER.get() + ); + + } + + public static void itemColors(RegisterColorHandlersEvent.Item event) { + Redux.LOGGER.debug("Beginning item color registration for the Aether: Redux"); + event.register((stack, tintIndex) -> tintIndex == 1 ? Tints.AETHER_GRASS_COLOR : 0xFFFFFF, + AetherBlocks.AETHER_GRASS_BLOCK.get(), + AetherBlocks.WHITE_FLOWER.get(), + AetherBlocks.PURPLE_FLOWER.get()/*, + ReduxBlocks.FLAREBLOSSOM.get(), + ReduxBlocks.INFERNIA.get(), + ReduxBlocks.WYNDSPROUTS.get()*/ + ); + event.register((stack, tintIndex) -> tintIndex == 0 ? Tints.AETHER_GRASS_COLOR : 0xFFFFFF, + ReduxBlocks.SHORT_AETHER_GRASS.get()/*, + ReduxBlocks.SPLITFERN.get())*/ + ); + + } + + public static void resolvers(RegisterColorHandlersEvent.ColorResolvers event) { + event.register(AETHER_GRASS); + } + + private static int getAverageColor(BlockAndTintGetter level, BlockPos blockPos, ColorResolver colorResolver) { + if (level != null && blockPos != null) { + try { + return level.getBlockTint(blockPos, colorResolver); + } catch (Exception e) { + Redux.LOGGER.error("Failed to get Aether Grass color, this is not intended! Ignoring exception and using default color", e); + } + } + return Tints.AETHER_GRASS_COLOR; + } + + public static int getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, int index, int indexGoal, boolean useBelowProperties) { + if (index == indexGoal) { + if (level != null && pos != null) { + if (level.getBlockState(pos.below()).is(ReduxTags.Blocks.SHORT_GRASS_BLIGHT_OVERRIDE) && useBelowProperties) { + return Tints.BLIGHT_GRASS_COLOR; + } else if (state.hasProperty(ReduxStates.ENCHANTED) && state.getValue(ReduxStates.ENCHANTED)) { + return 0xFFFFFF; + } + return getAverageColor(level, pos, AETHER_GRASS); + } + return Tints.AETHER_GRASS_COLOR; + } + return 0xFFFFFF; + } + + private static void register(RegisterColorHandlersEvent.Item colors, ItemColor resolver, Consumer onError, ResourceLocation... locations) { + for (ResourceLocation location : locations) { + if (BuiltInRegistries.ITEM.containsKey(location)) { + colors.register(resolver, BuiltInRegistries.ITEM.get(location)); + } else { + onError.accept(location.toString()); + } + } + } + + private static final Consumer BLOCK_ERROR = s -> { + Redux.LOGGER.warn("Tried to register compat color for block that does not exist! Could not find: {}", s); + Redux.LOGGER.warn("This is not NECESSARILY an issue, as some blocks that are mutually-exclusive in compatible mod versions exist, but it is being logged nonetheless"); + }; + private static final Consumer ITEM_ERROR = s -> { + Redux.LOGGER.warn("Tried to register compat color for item that does not exist! Could not find: {}", s); + Redux.LOGGER.warn("This is not NECESSARILY an issue, as some items that are mutually-exclusive in compatible mod versions exist, but it is being logged nonetheless"); + }; + + private static void register(RegisterColorHandlersEvent.Item colors, ItemColor resolver, ResourceLocation... locations) { + register(colors, resolver, ITEM_ERROR, locations); + } + private static void register(RegisterColorHandlersEvent.Block colors, BlockColor resolver, ResourceLocation... locations) { + register(colors, resolver, BLOCK_ERROR, locations); + } + + private static void register(RegisterColorHandlersEvent.Block colors, BlockColor resolver, Consumer onError, ResourceLocation... locations) { + for (ResourceLocation location : locations) { + if (BuiltInRegistries.BLOCK.containsKey(location)) { + colors.register(resolver, BuiltInRegistries.BLOCK.get(location)); + } else { + onError.accept(location.toString()); + } + } + } + +} diff --git a/src/main/java/net/zepalesque/redux/data/ReduxDataMaps.java b/src/main/java/net/zepalesque/redux/data/ReduxDataMaps.java new file mode 100644 index 000000000..361983344 --- /dev/null +++ b/src/main/java/net/zepalesque/redux/data/ReduxDataMaps.java @@ -0,0 +1,18 @@ +package net.zepalesque.redux.data; + +import com.mojang.serialization.Codec; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.block.Block; +import net.neoforged.neoforge.registries.datamaps.DataMapType; +import net.zepalesque.redux.Redux; + +public class ReduxDataMaps { + +// public static final DataMapType SHORT_GRASS_COLOR_CHANGERS = DataMapType.builder(Redux.loc("tint/override/short_grass_overrides"), +// Registries.BLOCK, Codec.INT) +// .synced(Codec.INT, false) +// .build(); + +} diff --git a/src/main/java/net/zepalesque/redux/data/ReduxTags.java b/src/main/java/net/zepalesque/redux/data/ReduxTags.java index dbcf8c25e..d8bdb7c71 100644 --- a/src/main/java/net/zepalesque/redux/data/ReduxTags.java +++ b/src/main/java/net/zepalesque/redux/data/ReduxTags.java @@ -18,6 +18,9 @@ public class ReduxTags { public static class Blocks { + public static final TagKey SHORT_GRASS_BLIGHT_OVERRIDE = tag("short_grass_blight_override"); + public static final TagKey SHORT_GRASS_COLORLESS_OVERRIDE = tag("short_grass_colorless_override"); + public static TagKey tag(String name) { return TagKey.create(Registries.BLOCK, Redux.loc(name)); } diff --git a/src/main/java/net/zepalesque/redux/data/gen/ReduxDataMapGen.java b/src/main/java/net/zepalesque/redux/data/gen/ReduxDataMapGen.java index 7a7b39ccb..570b76934 100644 --- a/src/main/java/net/zepalesque/redux/data/gen/ReduxDataMapGen.java +++ b/src/main/java/net/zepalesque/redux/data/gen/ReduxDataMapGen.java @@ -1,8 +1,12 @@ package net.zepalesque.redux.data.gen; +import com.aetherteam.aether.data.generators.AetherDataMapData; import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.zepalesque.redux.Redux; +import net.zepalesque.redux.client.ReduxColors; +import net.zepalesque.redux.data.ReduxDataMaps; +import net.zepalesque.redux.data.ReduxTags; import net.zepalesque.redux.data.prov.ReduxDataMapProvider; import java.util.concurrent.CompletableFuture; @@ -17,6 +21,5 @@ protected ReduxDataMapGen(PackOutput packOutput, CompletableFuture set.mapData(this)); Redux.STONE_SETS.forEach(set -> set.mapData(this)); - } } diff --git a/src/main/java/net/zepalesque/redux/mixin/mixins/client/color/AetherColorResolversMixin.java b/src/main/java/net/zepalesque/redux/mixin/mixins/client/color/AetherColorResolversMixin.java new file mode 100644 index 000000000..30503a9ae --- /dev/null +++ b/src/main/java/net/zepalesque/redux/mixin/mixins/client/color/AetherColorResolversMixin.java @@ -0,0 +1,21 @@ +package net.zepalesque.redux.mixin.mixins.client.color; + + +import com.aetherteam.aether.client.AetherColorResolvers; +import net.minecraft.client.renderer.entity.ItemRenderer; +import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + + +@Mixin(AetherColorResolvers.class) +public class AetherColorResolversMixin { + + @Inject(at = @At("HEAD"), method = "registerBlockColor", cancellable = true, remap = false) + private static void stupidMixinBlackMagic(RegisterColorHandlersEvent.Block event, CallbackInfo ci) { + // Cancel the aether's override of the grass color stuff + ci.cancel(); + } +} \ No newline at end of file diff --git a/src/main/java/net/zepalesque/redux/world/biome/tint/ReduxBiomeTints.java b/src/main/java/net/zepalesque/redux/world/biome/tint/ReduxBiomeTints.java new file mode 100644 index 000000000..4f9b59a24 --- /dev/null +++ b/src/main/java/net/zepalesque/redux/world/biome/tint/ReduxBiomeTints.java @@ -0,0 +1,18 @@ +package net.zepalesque.redux.world.biome.tint; + +import net.minecraft.core.Registry; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; +import net.neoforged.neoforge.registries.RegistryBuilder; +import net.zepalesque.redux.Redux; +import net.zepalesque.zenith.Zenith; +import net.zepalesque.zenith.api.biometint.BiomeTint; + +public class ReduxBiomeTints { + + + public static final DeferredRegister TINTS = DeferredRegister.create(Zenith.Keys.BIOME_TINT, Redux.MODID); + + public static final DeferredHolder AETHER_GRASS = TINTS.register("aether_grass", () -> new BiomeTint(Redux.loc("aether_grass"), 0xADF9C4)); + +} diff --git a/src/main/resources/aether_redux.mixins.json b/src/main/resources/aether_redux.mixins.json index efc75c472..af238c6ce 100644 --- a/src/main/resources/aether_redux.mixins.json +++ b/src/main/resources/aether_redux.mixins.json @@ -7,5 +7,8 @@ "refmap": "aether_redux.refmap.json", "mixins": [ "common.accessor.WallBlockAccessor" + ], + "client": [ + "client.color.AetherColorResolversMixin" ] } \ No newline at end of file