Skip to content

Commit

Permalink
feat: stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed May 29, 2024
1 parent 9e20573 commit 65e5e70
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 5 deletions.
24 changes: 22 additions & 2 deletions src/main/java/net/zepalesque/redux/Redux.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@
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;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
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;
Expand All @@ -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;
Expand All @@ -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<AbstractWoodSet> WOOD_SETS = new ArrayList<>();

public static final Collection<AbstractStoneSet> 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();
Expand All @@ -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));
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
128 changes: 128 additions & 0 deletions src/main/java/net/zepalesque/redux/client/ReduxColors.java
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 src/main/java/net/zepalesque/redux/data/ReduxDataMaps.java
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();

}
3 changes: 3 additions & 0 deletions src/main/java/net/zepalesque/redux/data/ReduxTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class ReduxTags {

public static class Blocks {

public static final TagKey<Block> SHORT_GRASS_BLIGHT_OVERRIDE = tag("short_grass_blight_override");
public static final TagKey<Block> SHORT_GRASS_COLORLESS_OVERRIDE = tag("short_grass_colorless_override");

public static TagKey<Block> tag(String name) {
return TagKey.create(Registries.BLOCK, Redux.loc(name));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,6 +21,5 @@ protected ReduxDataMapGen(PackOutput packOutput, CompletableFuture<HolderLookup.
protected void gather() {
Redux.WOOD_SETS.forEach(set -> set.mapData(this));
Redux.STONE_SETS.forEach(set -> set.mapData(this));

}
}
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();
}
}
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));

}
3 changes: 3 additions & 0 deletions src/main/resources/aether_redux.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"refmap": "aether_redux.refmap.json",
"mixins": [
"common.accessor.WallBlockAccessor"
],
"client": [
"client.color.AetherColorResolversMixin"
]
}

0 comments on commit 65e5e70

Please sign in to comment.