-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e20573
commit 65e5e70
Showing
10 changed files
with
219 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/main/java/net/zepalesque/redux/client/ReduxColors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<String> 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<String> 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<String> onError, ResourceLocation... locations) { | ||
for (ResourceLocation location : locations) { | ||
if (BuiltInRegistries.BLOCK.containsKey(location)) { | ||
colors.register(resolver, BuiltInRegistries.BLOCK.get(location)); | ||
} else { | ||
onError.accept(location.toString()); | ||
} | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/net/zepalesque/redux/data/ReduxDataMaps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Block, Integer> SHORT_GRASS_COLOR_CHANGERS = DataMapType.builder(Redux.loc("tint/override/short_grass_overrides"), | ||
// Registries.BLOCK, Codec.INT) | ||
// .synced(Codec.INT, false) | ||
// .build(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/net/zepalesque/redux/mixin/mixins/client/color/AetherColorResolversMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/net/zepalesque/redux/world/biome/tint/ReduxBiomeTints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BiomeTint> TINTS = DeferredRegister.create(Zenith.Keys.BIOME_TINT, Redux.MODID); | ||
|
||
public static final DeferredHolder<BiomeTint, BiomeTint> AETHER_GRASS = TINTS.register("aether_grass", () -> new BiomeTint(Redux.loc("aether_grass"), 0xADF9C4)); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters