diff --git a/src/main/java/vazkii/quark/addons/oddities/item/BackpackItem.java b/src/main/java/vazkii/quark/addons/oddities/item/BackpackItem.java index 40b4b5496f..6822ddbe4d 100644 --- a/src/main/java/vazkii/quark/addons/oddities/item/BackpackItem.java +++ b/src/main/java/vazkii/quark/addons/oddities/item/BackpackItem.java @@ -40,13 +40,13 @@ import vazkii.quark.base.handler.ProxiedItemStackHandler; import vazkii.quark.base.item.IQuarkItem; import vazkii.zeta.module.ZetaModule; -import vazkii.zeta.registry.IZetaItemColorProvider; +import vazkii.zeta.registry.IZetaItemColorProvider_OLD; import javax.annotation.Nonnull; import java.util.Map; import java.util.function.Consumer; -public class BackpackItem extends DyeableArmorItem implements IQuarkItem, MenuProvider, IZetaItemColorProvider { +public class BackpackItem extends DyeableArmorItem implements IQuarkItem, MenuProvider, IZetaItemColorProvider_OLD { private static final String WORN_TEXTURE = Quark.MOD_ID + ":textures/misc/backpack_worn.png"; private static final String WORN_OVERLAY_TEXTURE = Quark.MOD_ID + ":textures/misc/backpack_worn_overlay.png"; diff --git a/src/main/java/vazkii/quark/base/block/QuarkInheritedPaneBlock.java b/src/main/java/vazkii/quark/base/block/QuarkInheritedPaneBlock.java index 99e06d7e2f..0a5166bee2 100644 --- a/src/main/java/vazkii/quark/base/block/QuarkInheritedPaneBlock.java +++ b/src/main/java/vazkii/quark/base/block/QuarkInheritedPaneBlock.java @@ -2,14 +2,10 @@ import javax.annotation.Nullable; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import vazkii.quark.base.handler.RenderLayerHandler; import vazkii.zeta.registry.IZetaBlockColorProvider; import vazkii.zeta.registry.IZetaItemColorProvider; @@ -49,14 +45,13 @@ public float[] getBeaconColorMultiplier(BlockState state, LevelReader world, Blo } @Override - @OnlyIn(Dist.CLIENT) - public BlockColor getBlockColor() { - return parent instanceof IZetaBlockColorProvider provider ? provider.getBlockColor() : null; + public @Nullable String getBlockColorProviderName() { + return parent instanceof IZetaBlockColorProvider prov ? prov.getBlockColorProviderName() : null; } @Override - @OnlyIn(Dist.CLIENT) - public ItemColor getItemColor() { - return parent instanceof IZetaItemColorProvider provider ? provider.getItemColor() : null; + public @Nullable String getItemColorProviderName() { + return parent instanceof IZetaItemColorProvider prov ? prov.getItemColorProviderName() : null; } + } diff --git a/src/main/java/vazkii/quark/base/block/QuarkSlabBlock.java b/src/main/java/vazkii/quark/base/block/QuarkSlabBlock.java index 6edda3ec49..697e9e3b30 100644 --- a/src/main/java/vazkii/quark/base/block/QuarkSlabBlock.java +++ b/src/main/java/vazkii/quark/base/block/QuarkSlabBlock.java @@ -1,7 +1,5 @@ package vazkii.quark.base.block; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; @@ -11,8 +9,6 @@ import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.SlabBlock; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import vazkii.quark.base.Quark; import vazkii.quark.base.handler.CreativeTabHandler; import vazkii.quark.base.handler.RenderLayerHandler; @@ -82,14 +78,12 @@ public float[] getBeaconColorMultiplier(BlockState state, LevelReader world, Blo } @Override - @OnlyIn(Dist.CLIENT) - public BlockColor getBlockColor() { - return parent instanceof IZetaBlockColorProvider provider ? provider.getBlockColor() : null; + public @Nullable String getBlockColorProviderName() { + return parent instanceof IZetaBlockColorProvider prov ? prov.getBlockColorProviderName() : null; } @Override - @OnlyIn(Dist.CLIENT) - public ItemColor getItemColor() { - return parent instanceof IZetaItemColorProvider provider ? provider.getItemColor() : null; + public @Nullable String getItemColorProviderName() { + return parent instanceof IZetaItemColorProvider prov ? prov.getItemColorProviderName() : null; } } diff --git a/src/main/java/vazkii/quark/base/block/QuarkStairsBlock.java b/src/main/java/vazkii/quark/base/block/QuarkStairsBlock.java index e77e00681e..599670374a 100644 --- a/src/main/java/vazkii/quark/base/block/QuarkStairsBlock.java +++ b/src/main/java/vazkii/quark/base/block/QuarkStairsBlock.java @@ -5,8 +5,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; @@ -16,8 +14,6 @@ import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.StairBlock; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import vazkii.quark.base.Quark; import vazkii.quark.base.handler.CreativeTabHandler; import vazkii.quark.base.handler.RenderLayerHandler; @@ -82,16 +78,15 @@ public boolean doesConditionApply() { public float[] getBeaconColorMultiplier(BlockState state, LevelReader world, BlockPos pos, BlockPos beaconPos) { return parent.getBlock().getBeaconColorMultiplier(parent.getBlock().defaultBlockState(), world, pos, beaconPos); } - + @Override - @OnlyIn(Dist.CLIENT) - public BlockColor getBlockColor() { - return parent instanceof IZetaBlockColorProvider provider ? provider.getBlockColor() : null; + public @Nullable String getBlockColorProviderName() { + return parent instanceof IZetaBlockColorProvider prov ? prov.getBlockColorProviderName() : null; } @Override - @OnlyIn(Dist.CLIENT) - public ItemColor getItemColor() { - return parent instanceof IZetaItemColorProvider provider ? provider.getItemColor() : null; + public @Nullable String getItemColorProviderName() { + return parent instanceof IZetaItemColorProvider prov ? prov.getItemColorProviderName() : null; } + } diff --git a/src/main/java/vazkii/quark/base/block/QuarkWallBlock.java b/src/main/java/vazkii/quark/base/block/QuarkWallBlock.java index c69ccdfeab..48d0e7cc87 100644 --- a/src/main/java/vazkii/quark/base/block/QuarkWallBlock.java +++ b/src/main/java/vazkii/quark/base/block/QuarkWallBlock.java @@ -1,7 +1,5 @@ package vazkii.quark.base.block; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; import net.minecraft.world.item.CreativeModeTab; @@ -9,8 +7,6 @@ import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.WallBlock; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import vazkii.quark.base.Quark; import vazkii.quark.base.handler.CreativeTabHandler; import vazkii.quark.base.handler.RenderLayerHandler; @@ -69,15 +65,13 @@ public float[] getBeaconColorMultiplier(BlockState state, LevelReader world, Blo } @Override - @OnlyIn(Dist.CLIENT) - public BlockColor getBlockColor() { - return parent instanceof IZetaBlockColorProvider provider ? provider.getBlockColor() : null; + public @Nullable String getBlockColorProviderName() { + return parent instanceof IZetaBlockColorProvider prov ? prov.getBlockColorProviderName() : null; } @Override - @OnlyIn(Dist.CLIENT) - public ItemColor getItemColor() { - return parent instanceof IZetaItemColorProvider provider ? provider.getItemColor() : null; + public @Nullable String getItemColorProviderName() { + return parent instanceof IZetaItemColorProvider prov ? prov.getItemColorProviderName() : null; } } diff --git a/src/main/java/vazkii/quark/content/building/block/CutVineBlock.java b/src/main/java/vazkii/quark/content/building/block/CutVineBlock.java index b71ae6f92d..303bd02f97 100644 --- a/src/main/java/vazkii/quark/content/building/block/CutVineBlock.java +++ b/src/main/java/vazkii/quark/content/building/block/CutVineBlock.java @@ -12,10 +12,12 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.phys.HitResult; +import org.jetbrains.annotations.Nullable; import vazkii.quark.base.block.QuarkVineBlock; import vazkii.zeta.module.ZetaModule; +import vazkii.zeta.registry.IZetaBlockColorProvider; -public class CutVineBlock extends QuarkVineBlock { +public class CutVineBlock extends QuarkVineBlock implements IZetaBlockColorProvider { public CutVineBlock(ZetaModule module) { super(module, "cut_vine", false); @@ -36,4 +38,14 @@ public boolean canSupportAtFace(@Nonnull BlockGetter level, @Nonnull BlockPos po public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter world, BlockPos pos, Player player) { return new ItemStack(Items.VINE); } + + @Override + public @Nullable String getBlockColorProviderName() { + return "vine"; + } + + @Override + public @Nullable String getItemColorProviderName() { + return "vine"; + } } diff --git a/src/main/java/vazkii/quark/content/building/block/HedgeBlock.java b/src/main/java/vazkii/quark/content/building/block/HedgeBlock.java index 50711f438f..6749284ae9 100644 --- a/src/main/java/vazkii/quark/content/building/block/HedgeBlock.java +++ b/src/main/java/vazkii/quark/content/building/block/HedgeBlock.java @@ -8,9 +8,6 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import net.minecraft.client.Minecraft; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.NonNullList; @@ -30,10 +27,9 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.PlantType; +import org.jetbrains.annotations.Nullable; import vazkii.quark.base.Quark; import vazkii.quark.base.block.IQuarkBlock; import vazkii.quark.base.handler.CreativeTabHandler; @@ -43,6 +39,7 @@ import vazkii.quark.content.world.block.BlossomLeavesBlock; import vazkii.zeta.registry.IZetaBlockColorProvider; +//TODO ZETA: extend QuarkFenceBlock public class HedgeBlock extends FenceBlock implements IQuarkBlock, IZetaBlockColorProvider { private static final VoxelShape WOOD_SHAPE = box(6F, 0F, 6F, 10F, 15F, 10F); @@ -57,7 +54,7 @@ public class HedgeBlock extends FenceBlock implements IQuarkBlock, IZetaBlockCol private final VoxelShape[] hedgeShapes; private final ZetaModule module; - private final Block leaf; + public final BlockState leafState; private BooleanSupplier enabledSupplier = () -> true; public static final BooleanProperty EXTEND = BooleanProperty.create("extend"); @@ -66,7 +63,7 @@ public HedgeBlock(ZetaModule module, Block fence, Block leaf) { super(Block.Properties.copy(fence)); this.module = module; - this.leaf = leaf; + this.leafState = leaf.defaultBlockState(); ResourceLocation leafRes = Quark.ZETA.registry.getRegistryName(leaf, Registry.BLOCK); if (leaf instanceof BlossomLeavesBlock) { @@ -86,6 +83,10 @@ public HedgeBlock(ZetaModule module, Block fence, Block leaf) { hedgeShapes = cacheHedgeShapes(stateDefinition.getPossibleStates()); } + public BlockState getLeaf() { + return leafState; + } + @Override public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext ctx) { return hedgeShapes[getHedgeAABBIndex(state)]; @@ -133,7 +134,6 @@ protected int getHedgeAABBIndex(BlockState curr) { }); } - @Override public boolean connectsTo(BlockState state, boolean isSideSolid, @Nonnull Direction direction) { return state.is(HedgesModule.hedgesTag); @@ -175,17 +175,13 @@ protected void createBlockStateDefinition(@Nonnull StateDefinition.Builder Minecraft.getInstance().getBlockColors().getColor(leafState, world, pos, tintIndex); + public @Nullable String getBlockColorProviderName() { + return "hedge"; } @Override - @OnlyIn(Dist.CLIENT) - public ItemColor getItemColor() { - final ItemStack leafStack = new ItemStack(leaf); - return (stack, tintIndex) -> Minecraft.getInstance().getItemColors().getColor(leafStack, tintIndex); + public @Nullable String getItemColorProviderName() { + return "hedge"; } @Override diff --git a/src/main/java/vazkii/quark/content/building/block/LeafCarpetBlock.java b/src/main/java/vazkii/quark/content/building/block/LeafCarpetBlock.java index 0f0ab3436f..12f11d7fbe 100644 --- a/src/main/java/vazkii/quark/content/building/block/LeafCarpetBlock.java +++ b/src/main/java/vazkii/quark/content/building/block/LeafCarpetBlock.java @@ -2,9 +2,6 @@ import javax.annotation.Nonnull; -import net.minecraft.client.Minecraft; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.CreativeModeTab; @@ -21,8 +18,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import org.jetbrains.annotations.Nullable; import vazkii.quark.base.block.QuarkBlock; import vazkii.quark.base.handler.RenderLayerHandler; import vazkii.zeta.module.ZetaModule; @@ -32,7 +28,7 @@ public class LeafCarpetBlock extends QuarkBlock implements IZetaBlockColorProvid private static final VoxelShape SHAPE = box(0, 0, 0, 16, 1, 16); - private final BlockState baseState; + public final BlockState baseState; private ItemStack baseStack; public LeafCarpetBlock(String name, Block base, ZetaModule module) { @@ -47,6 +43,10 @@ public LeafCarpetBlock(String name, Block base, ZetaModule module) { RenderLayerHandler.setRenderType(this, RenderLayerHandler.RenderTypeSkeleton.CUTOUT_MIPPED); } + public BlockState getBaseState() { + return baseState; + } + @Override public boolean canBeReplaced(@Nonnull BlockState state, @Nonnull BlockPlaceContext useContext) { return useContext.getItemInHand().isEmpty() || useContext.getItemInHand().getItem() != this.asItem(); @@ -77,18 +77,13 @@ public boolean canSurvive(@Nonnull BlockState state, LevelReader world, BlockPos } @Override - @OnlyIn(Dist.CLIENT) - public ItemColor getItemColor() { - if (baseStack == null) - baseStack = new ItemStack(baseState.getBlock()); - - return (stack, tintIndex) -> Minecraft.getInstance().getItemColors().getColor(baseStack, tintIndex); + public @Nullable String getBlockColorProviderName() { + return "leaf_carpet"; } @Override - @OnlyIn(Dist.CLIENT) - public BlockColor getBlockColor() { - return (state, worldIn, pos, tintIndex) -> Minecraft.getInstance().getBlockColors().getColor(baseState, worldIn, pos, tintIndex); + public @Nullable String getItemColorProviderName() { + return "leaf_carpet"; } } diff --git a/src/main/java/vazkii/quark/content/building/block/MyalitePillarBlock.java b/src/main/java/vazkii/quark/content/building/block/MyalitePillarBlock.java index 666df38a50..e100a166f8 100644 --- a/src/main/java/vazkii/quark/content/building/block/MyalitePillarBlock.java +++ b/src/main/java/vazkii/quark/content/building/block/MyalitePillarBlock.java @@ -1,14 +1,25 @@ package vazkii.quark.content.building.block; import net.minecraft.world.item.CreativeModeTab; +import org.jetbrains.annotations.Nullable; import vazkii.quark.base.block.QuarkPillarBlock; import vazkii.zeta.module.ZetaModule; -import vazkii.quark.content.world.block.IMyaliteColorProvider; +import vazkii.zeta.registry.IZetaBlockColorProvider; -public class MyalitePillarBlock extends QuarkPillarBlock implements IMyaliteColorProvider { +public class MyalitePillarBlock extends QuarkPillarBlock implements IZetaBlockColorProvider { public MyalitePillarBlock(String regname, ZetaModule module, CreativeModeTab creativeTab, Properties properties) { super(regname, module, creativeTab, properties); } + @Override + public @Nullable String getBlockColorProviderName() { + return "myalite"; + } + + @Override + public @Nullable String getItemColorProviderName() { + return "myalite"; + } + } diff --git a/src/main/java/vazkii/quark/content/building/block/VerticalSlabBlock.java b/src/main/java/vazkii/quark/content/building/block/VerticalSlabBlock.java index 2afc3a873d..7e47ec469b 100644 --- a/src/main/java/vazkii/quark/content/building/block/VerticalSlabBlock.java +++ b/src/main/java/vazkii/quark/content/building/block/VerticalSlabBlock.java @@ -1,7 +1,5 @@ package vazkii.quark.content.building.block; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; @@ -30,8 +28,6 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import vazkii.zeta.registry.IZetaBlockColorProvider; import vazkii.zeta.registry.IZetaItemColorProvider; @@ -173,15 +169,13 @@ public boolean isPathfindable(@Nonnull BlockState state, @Nonnull BlockGetter wo } @Override - @OnlyIn(Dist.CLIENT) - public BlockColor getBlockColor() { - return parent.get() instanceof IZetaBlockColorProvider provider ? provider.getBlockColor() : null; + public @Nullable String getBlockColorProviderName() { + return parent.get() instanceof IZetaBlockColorProvider prov ? prov.getBlockColorProviderName() : null; } @Override - @OnlyIn(Dist.CLIENT) - public ItemColor getItemColor() { - return parent.get() instanceof IZetaItemColorProvider provider ? provider.getItemColor() : null; + public @Nullable String getItemColorProviderName() { + return parent.get() instanceof IZetaItemColorProvider prov ? prov.getItemColorProviderName() : null; } public enum VerticalSlabType implements StringRepresentable { diff --git a/src/main/java/vazkii/quark/content/building/module/HedgesModule.java b/src/main/java/vazkii/quark/content/building/module/HedgesModule.java index 2319aff5da..58d07daa62 100644 --- a/src/main/java/vazkii/quark/content/building/module/HedgesModule.java +++ b/src/main/java/vazkii/quark/content/building/module/HedgesModule.java @@ -6,8 +6,10 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import vazkii.quark.base.Quark; -import vazkii.quark.base.module.LoadModule; -import vazkii.quark.base.module.ModuleLoader; +import vazkii.zeta.client.AlikeColorHandler; +import vazkii.zeta.client.event.ZAddBlockColorHandlers; +import vazkii.zeta.client.event.ZAddItemColorHandlers; +import vazkii.zeta.module.ZetaLoadModule; import vazkii.zeta.module.ZetaModule; import vazkii.quark.base.util.VanillaWoods; import vazkii.quark.base.util.VanillaWoods.Wood; @@ -19,7 +21,7 @@ import vazkii.zeta.event.ZRegister; import vazkii.zeta.event.bus.LoadEvent; -@LoadModule(category = "building") +@ZetaLoadModule(category = "building") public class HedgesModule extends ZetaModule { public static TagKey hedgesTag; @@ -38,12 +40,27 @@ public void postRegister(ZRegister.Post e) { for (BlossomTree tree : BlossomTreesModule.trees.keySet()) new HedgeBlock(this, BlossomTreesModule.woodSet.fence, tree.leaf.getBlock()).setCondition(tree.sapling::isEnabled); - new HedgeBlock(this, AncientWoodModule.woodSet.fence, AncientWoodModule.ancient_leaves).setCondition(() -> ModuleLoader.INSTANCE.isModuleEnabled(AncientWoodModule.class)); + new HedgeBlock(this, AncientWoodModule.woodSet.fence, AncientWoodModule.ancient_leaves).setCondition(() -> Quark.ZETA.modules.isEnabled(AncientWoodModule.class)); } @LoadEvent public final void setup(ZCommonSetup event) { hedgesTag = BlockTags.create(new ResourceLocation(Quark.MOD_ID, "hedges")); } - + + @ZetaLoadModule(clientReplacement = true) + public static class Client extends HedgesModule { + + @LoadEvent + public void blockColorProviders(ZAddBlockColorHandlers event) { + event.registerNamed(b -> new AlikeColorHandler((HedgeBlock) b, HedgeBlock::getLeaf), "hedge"); + } + + @LoadEvent + public void itemColorProviders(ZAddItemColorHandlers event) { + event.registerNamed(i -> new AlikeColorHandler(i, HedgeBlock::getLeaf), "hedge"); + } + + } + } diff --git a/src/main/java/vazkii/quark/content/building/module/LeafCarpetModule.java b/src/main/java/vazkii/quark/content/building/module/LeafCarpetModule.java index e5b0e3f1cb..a6ffd69b0b 100644 --- a/src/main/java/vazkii/quark/content/building/module/LeafCarpetModule.java +++ b/src/main/java/vazkii/quark/content/building/module/LeafCarpetModule.java @@ -7,8 +7,11 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.ComposterBlock; import vazkii.quark.base.block.IQuarkBlock; -import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.ModuleLoader; +import vazkii.zeta.client.AlikeColorHandler; +import vazkii.zeta.client.event.ZAddBlockColorHandlers; +import vazkii.zeta.client.event.ZAddItemColorHandlers; +import vazkii.zeta.module.ZetaLoadModule; import vazkii.zeta.module.ZetaModule; import vazkii.quark.base.util.VanillaWoods; import vazkii.quark.base.util.VanillaWoods.Wood; @@ -20,7 +23,7 @@ import vazkii.zeta.event.ZRegister; import vazkii.zeta.event.bus.LoadEvent; -@LoadModule(category = "building", antiOverlap = { "woodworks", "immersive_weathering" }) +@ZetaLoadModule(category = "building", antiOverlap = { "woodworks", "immersive_weathering" }) public class LeafCarpetModule extends ZetaModule { public static List carpets = new LinkedList<>(); @@ -65,4 +68,19 @@ private LeafCarpetBlock carpetBlock(Block base) { return carpet; } + @ZetaLoadModule(clientReplacement = true) + public static class Client extends LeafCarpetModule { + + @LoadEvent + public void blockColorHandlers(ZAddBlockColorHandlers event) { + event.registerNamed(b -> new AlikeColorHandler((LeafCarpetBlock) b, LeafCarpetBlock::getBaseState), "leaf_carpet"); + } + + @LoadEvent + public void itemColorHandlers(ZAddItemColorHandlers event) { + event.registerNamed(i -> new AlikeColorHandler(i, LeafCarpetBlock::getBaseState), "leaf_carpet"); + } + + } + } diff --git a/src/main/java/vazkii/quark/content/building/module/ShearVinesModule.java b/src/main/java/vazkii/quark/content/building/module/ShearVinesModule.java index 664cd046ca..48c788324b 100644 --- a/src/main/java/vazkii/quark/content/building/module/ShearVinesModule.java +++ b/src/main/java/vazkii/quark/content/building/module/ShearVinesModule.java @@ -20,6 +20,7 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraftforge.common.ToolActions; import vazkii.quark.base.handler.MiscUtil; +import vazkii.zeta.client.AlikeColorHandler; import vazkii.zeta.module.ZetaModule; import vazkii.quark.base.module.hint.Hint; import vazkii.quark.content.building.block.CutVineBlock; @@ -82,16 +83,17 @@ public void onRightClick(ZRightClickBlock event) { @ZetaLoadModule(clientReplacement = true) public static class Client extends ShearVinesModule { + + private final AlikeColorHandler LIKE_VINE = new AlikeColorHandler(Blocks.VINE.defaultBlockState()); + @LoadEvent public void blockColors(ZAddBlockColorHandlers event) { - BlockState vineState = Blocks.VINE.defaultBlockState(); - event.register((state, world, pos, tintIndex) -> Minecraft.getInstance().getBlockColors().getColor(vineState, world, pos, tintIndex), cut_vine); + event.registerNamed(b -> LIKE_VINE, "vine"); } @LoadEvent public void itemColors(ZAddItemColorHandlers event) { - ItemStack vineStack = new ItemStack(Items.VINE); - event.register((stack, tintIndex) -> Minecraft.getInstance().getItemColors().getColor(vineStack, tintIndex), cut_vine); + event.registerNamed(i -> LIKE_VINE, "vine"); } } } diff --git a/src/main/java/vazkii/quark/content/client/module/LongRangePickBlockModule.java b/src/main/java/vazkii/quark/content/client/module/LongRangePickBlockModule.java index 90415f2e8e..87d6215495 100644 --- a/src/main/java/vazkii/quark/content/client/module/LongRangePickBlockModule.java +++ b/src/main/java/vazkii/quark/content/client/module/LongRangePickBlockModule.java @@ -23,6 +23,7 @@ public HitResult transformHitResult(HitResult orig) { @ZetaLoadModule(clientReplacement = true) public static class Client extends LongRangePickBlockModule { + @Override public HitResult transformHitResult(HitResult hitResult) { if(!enabled) return hitResult; diff --git a/src/main/java/vazkii/quark/content/tools/item/PathfindersQuillItem.java b/src/main/java/vazkii/quark/content/tools/item/PathfindersQuillItem.java index 6b21887dcb..eaa849c0ec 100644 --- a/src/main/java/vazkii/quark/content/tools/item/PathfindersQuillItem.java +++ b/src/main/java/vazkii/quark/content/tools/item/PathfindersQuillItem.java @@ -35,7 +35,7 @@ import vazkii.quark.content.tools.module.PathfinderMapsModule; import vazkii.quark.content.tools.module.PathfinderMapsModule.TradeInfo; import vazkii.quark.content.world.module.GlimmeringWealdModule; -import vazkii.zeta.registry.IZetaItemColorProvider; +import vazkii.zeta.registry.IZetaItemColorProvider_OLD; import javax.annotation.Nullable; import java.util.List; @@ -45,7 +45,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -public class PathfindersQuillItem extends QuarkItem implements IZetaItemColorProvider { +public class PathfindersQuillItem extends QuarkItem implements IZetaItemColorProvider_OLD { private static final Direction[] DIRECTIONS = new Direction[]{Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.NORTH}; diff --git a/src/main/java/vazkii/quark/content/tools/module/PathfinderMapsModule.java b/src/main/java/vazkii/quark/content/tools/module/PathfinderMapsModule.java index 403308a350..76ced242eb 100644 --- a/src/main/java/vazkii/quark/content/tools/module/PathfinderMapsModule.java +++ b/src/main/java/vazkii/quark/content/tools/module/PathfinderMapsModule.java @@ -45,6 +45,7 @@ import vazkii.zeta.event.ZRegister; import vazkii.zeta.event.bus.LoadEvent; import vazkii.zeta.client.event.ZClientSetup; +import vazkii.zeta.module.ZetaLoadModule; import vazkii.zeta.util.ItemNBTHelper; import vazkii.quark.base.Quark; import vazkii.quark.base.handler.advancement.QuarkAdvancementHandler; diff --git a/src/main/java/vazkii/quark/content/world/block/IMyaliteColorProvider.java b/src/main/java/vazkii/quark/content/world/block/IMyaliteColorProvider.java deleted file mode 100644 index 8a23cfce08..0000000000 --- a/src/main/java/vazkii/quark/content/world/block/IMyaliteColorProvider.java +++ /dev/null @@ -1,73 +0,0 @@ -package vazkii.quark.content.world.block; - -import com.google.common.collect.ImmutableList; -import net.minecraft.client.Minecraft; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; -import net.minecraft.core.BlockPos; -import net.minecraft.util.Mth; -import net.minecraft.world.level.levelgen.LegacyRandomSource; -import net.minecraft.world.level.levelgen.synth.PerlinSimplexNoise; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.HitResult; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import vazkii.zeta.registry.IZetaBlockColorProvider; - -import java.awt.*; - -public interface IMyaliteColorProvider extends IZetaBlockColorProvider { - - PerlinSimplexNoise NOISE = new PerlinSimplexNoise(new LegacyRandomSource(4543543), - ImmutableList.of(-4, -3, -2, -1, 0, 1, 2, 3, 4)); - - @Override - @OnlyIn(Dist.CLIENT) - default BlockColor getBlockColor() { - return (state, world, pos, tintIndex) -> getColor(pos, myaliteS(), myaliteB()); - } - - @Override - @OnlyIn(Dist.CLIENT) - default ItemColor getItemColor() { - return (stack, tintIndex) -> { - Minecraft mc = Minecraft.getInstance(); - if(mc.player == null) - return getColor(BlockPos.ZERO, myaliteS(), myaliteB()); - - BlockPos pos = mc.player.blockPosition(); - HitResult res = mc.hitResult; - if(res != null && res.getType() == HitResult.Type.BLOCK) - pos = ((BlockHitResult) res).getBlockPos(); - - return getColor(pos, myaliteS(), myaliteB()); - }; - } - - default float myaliteS() { return 0.7F; } - default float myaliteB() { return 0.8F; } - - static int getColor(BlockPos pos, float s, float b) { - final float sp = 0.15f; - final double range = 0.3; - final double shift = 0.05; - - if(pos == null) - pos = BlockPos.ZERO; - - float x = pos.getX() * sp; - float y = pos.getY() * sp; - float z = pos.getZ() * sp; - - double xv = x + Mth.sin(z) * 2; - double zv = z + Mth.cos(x) * 2; - double yv = y + Mth.sin(y + Mth.PI / 4) * 2; - - double noise = NOISE.getValue(xv + yv, zv + (yv * 2), false); - - double h = noise * (range / 2) - range + shift; - - return Color.HSBtoRGB((float) h, s, b); - } - -} diff --git a/src/main/java/vazkii/quark/content/world/block/MyaliteBlock.java b/src/main/java/vazkii/quark/content/world/block/MyaliteBlock.java index a9717c7e6b..2a416b4409 100644 --- a/src/main/java/vazkii/quark/content/world/block/MyaliteBlock.java +++ b/src/main/java/vazkii/quark/content/world/block/MyaliteBlock.java @@ -1,13 +1,25 @@ package vazkii.quark.content.world.block; import net.minecraft.world.item.CreativeModeTab; +import org.jetbrains.annotations.Nullable; import vazkii.quark.base.block.QuarkBlock; import vazkii.zeta.module.ZetaModule; +import vazkii.zeta.registry.IZetaBlockColorProvider; -public class MyaliteBlock extends QuarkBlock implements IMyaliteColorProvider { +public class MyaliteBlock extends QuarkBlock implements IZetaBlockColorProvider { public MyaliteBlock(String regname, ZetaModule module, CreativeModeTab creativeTab, Properties properties) { super(regname, module, creativeTab, properties); } + @Override + public @Nullable String getBlockColorProviderName() { + return "myalite"; + } + + @Override + public @Nullable String getItemColorProviderName() { + return "myalite"; + } + } diff --git a/src/main/java/vazkii/quark/content/world/block/MyaliteColorLogic.java b/src/main/java/vazkii/quark/content/world/block/MyaliteColorLogic.java new file mode 100644 index 0000000000..7abd1e639c --- /dev/null +++ b/src/main/java/vazkii/quark/content/world/block/MyaliteColorLogic.java @@ -0,0 +1,39 @@ +package vazkii.quark.content.world.block; + +import java.awt.*; +import java.util.List; + +import net.minecraft.core.BlockPos; +import net.minecraft.util.Mth; +import net.minecraft.world.level.levelgen.LegacyRandomSource; +import net.minecraft.world.level.levelgen.synth.PerlinSimplexNoise; + +public class MyaliteColorLogic { + protected static final float s = 0.7f; + protected static final float b = 0.8f; + protected static final PerlinSimplexNoise noise = new PerlinSimplexNoise(new LegacyRandomSource(4543543), List.of(-4, -3, -2, -1, 0, 1, 2, 3, 4)); + + public static int getColor(BlockPos pos) { + final float sp = 0.15f; + final double range = 0.3; + final double shift = 0.05; + + if(pos == null) + pos = BlockPos.ZERO; + + float x = pos.getX() * sp; + float y = pos.getY() * sp; + float z = pos.getZ() * sp; + + double xv = x + Mth.sin(z) * 2; + double zv = z + Mth.cos(x) * 2; + double yv = y + Mth.sin(y + Mth.PI / 4) * 2; + + double noiseVal = noise.getValue(xv + yv, zv + (yv * 2), false); + + double h = noiseVal * (range / 2) - range + shift; + + return Color.HSBtoRGB((float) h, s, b); + } + +} diff --git a/src/main/java/vazkii/quark/content/world/block/MyaliteCrystalBlock.java b/src/main/java/vazkii/quark/content/world/block/MyaliteCrystalBlock.java index 9494b25f05..30bd1bf920 100644 --- a/src/main/java/vazkii/quark/content/world/block/MyaliteCrystalBlock.java +++ b/src/main/java/vazkii/quark/content/world/block/MyaliteCrystalBlock.java @@ -1,7 +1,5 @@ package vazkii.quark.content.world.block; -import javax.annotation.Nullable; - import net.minecraft.core.BlockPos; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.level.LevelReader; @@ -10,10 +8,12 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; +import org.jetbrains.annotations.Nullable; import vazkii.quark.base.block.QuarkGlassBlock; import vazkii.zeta.module.ZetaModule; +import vazkii.zeta.registry.IZetaBlockColorProvider; -public class MyaliteCrystalBlock extends QuarkGlassBlock implements IMyaliteColorProvider { +public class MyaliteCrystalBlock extends QuarkGlassBlock implements IZetaBlockColorProvider { public MyaliteCrystalBlock(ZetaModule module) { super("myalite_crystal", module, CreativeModeTab.TAB_DECORATIONS, true, @@ -36,7 +36,16 @@ private static float[] decompColor(int color) { @Nullable @Override public float[] getBeaconColorMultiplier(BlockState state, LevelReader world, BlockPos pos, BlockPos beaconPos) { - return decompColor(IMyaliteColorProvider.getColor(pos, myaliteS(), myaliteB())); + return decompColor(MyaliteColorLogic.getColor(pos)); + } + + @Override + public @Nullable String getBlockColorProviderName() { + return "myalite"; + } + + @Override + public @Nullable String getItemColorProviderName() { + return "myalite"; } - } diff --git a/src/main/java/vazkii/quark/content/world/module/NewStoneTypesModule.java b/src/main/java/vazkii/quark/content/world/module/NewStoneTypesModule.java index 4683131480..0b0b781ce2 100644 --- a/src/main/java/vazkii/quark/content/world/module/NewStoneTypesModule.java +++ b/src/main/java/vazkii/quark/content/world/module/NewStoneTypesModule.java @@ -7,16 +7,28 @@ import com.google.common.collect.Maps; +import net.minecraft.client.Minecraft; +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.color.item.ItemColor; +import net.minecraft.core.BlockPos; import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; import vazkii.quark.base.block.IQuarkBlock; import vazkii.quark.base.block.QuarkBlock; import vazkii.quark.base.block.QuarkBlockWrapper; import vazkii.quark.base.handler.VariantHandler; import vazkii.quark.base.module.ModuleLoader; +import vazkii.quark.content.world.block.MyaliteColorLogic; +import vazkii.zeta.client.event.ZAddBlockColorHandlers; +import vazkii.zeta.client.event.ZAddItemColorHandlers; import vazkii.zeta.module.ZetaModule; import vazkii.quark.base.module.config.Config; import vazkii.quark.base.module.config.type.DimensionConfig; @@ -116,4 +128,44 @@ public final void setup(ZCommonSetup event) { defers.poll().run(); } + @ZetaLoadModule(clientReplacement = true) + public static class Client extends NewStoneTypesModule { + + @LoadEvent + public void blockColorProviders(ZAddBlockColorHandlers event) { + event.registerNamed(block -> MyaliteColorHandler.INSTANCE, "myalite"); + } + + @LoadEvent + public void itemColorProviders(ZAddItemColorHandlers event) { + event.registerNamed(item -> MyaliteColorHandler.INSTANCE, "myalite"); + } + + private static class MyaliteColorHandler implements BlockColor, ItemColor { + + static final MyaliteColorHandler INSTANCE = new MyaliteColorHandler(); + + @Override + public int getColor(BlockState state, BlockAndTintGetter level, BlockPos pos, int tintIndex) { + return MyaliteColorLogic.getColor(pos); + } + + @Override + public int getColor(ItemStack stack, int tintIndex) { + Minecraft mc = Minecraft.getInstance(); + if(mc.player == null) + return MyaliteColorLogic.getColor(BlockPos.ZERO); + + BlockPos pos = mc.player.blockPosition(); + HitResult res = mc.hitResult; + if(res != null && res.getType() == HitResult.Type.BLOCK) + pos = ((BlockHitResult) res).getBlockPos(); + + return MyaliteColorLogic.getColor(pos); + } + + } + + } + } diff --git a/src/main/java/vazkii/zeta/client/AlikeColorHandler.java b/src/main/java/vazkii/zeta/client/AlikeColorHandler.java new file mode 100644 index 0000000000..c732d13349 --- /dev/null +++ b/src/main/java/vazkii/zeta/client/AlikeColorHandler.java @@ -0,0 +1,54 @@ +package vazkii.zeta.client; + +import java.util.function.Function; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.color.item.ItemColor; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +/** + * A BlockColor and ItemColor that just mimics another block. + */ +public class AlikeColorHandler implements BlockColor, ItemColor { + private final BlockState likeState; + private final ItemStack likeItem; + + public AlikeColorHandler(BlockState likeState, ItemStack likeItem) { + this.likeState = likeState; + this.likeItem = likeItem; + } + + public AlikeColorHandler(BlockState likeState) { + this(likeState, new ItemStack(likeState.getBlock())); + } + + /** + * construction convenience, for when the BlockState to mimic is derived from the block + */ + public AlikeColorHandler(B block, Function stateExtractor) { + this.likeState = stateExtractor.apply(block); + this.likeItem = new ItemStack(likeState.getBlock()); + } + + @SuppressWarnings("unchecked") + public AlikeColorHandler(Item item, Function stateExtractor) { + this((B) Block.byItem(item), stateExtractor); + } + + @Override + public int getColor(BlockState state, @Nullable BlockAndTintGetter level, @Nullable BlockPos pos, int tintIndex) { + return Minecraft.getInstance().getBlockColors().getColor(likeState, level, pos, tintIndex); + } + + @Override + public int getColor(ItemStack stack, int tintIndex) { + return Minecraft.getInstance().getItemColors().getColor(likeItem, tintIndex); + } +} diff --git a/src/main/java/vazkii/zeta/client/ClientRegistryExtension.java b/src/main/java/vazkii/zeta/client/ClientRegistryExtension.java new file mode 100644 index 0000000000..63f8b675be --- /dev/null +++ b/src/main/java/vazkii/zeta/client/ClientRegistryExtension.java @@ -0,0 +1,47 @@ +package vazkii.zeta.client; + +import java.util.function.Function; + +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.color.item.ItemColor; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import vazkii.zeta.Zeta; +import vazkii.zeta.client.event.ZAddBlockColorHandlers; +import vazkii.zeta.client.event.ZAddItemColorHandlers; +import vazkii.zeta.event.bus.LoadEvent; +import vazkii.zeta.registry.ZetaRegistry; + +public class ClientRegistryExtension { + protected final Zeta z; + protected final ZetaRegistry registry; + + public ClientRegistryExtension(Zeta z) { + this.z = z; + this.registry = z.registry; + + z.loadBus.subscribe(this); + } + + @LoadEvent + public void registerBlockColors(ZAddBlockColorHandlers.Post event) { + registry.submitBlockColors((block, name) -> { + Function blockColorCreator = event.getNamedBlockColors().get(name); + if(blockColorCreator == null) + z.log.error("Unknown block color creator {} used on block {}", name, block); + else + event.register(blockColorCreator.apply(block), block); + }); + } + + @LoadEvent + public void registerItemColors(ZAddItemColorHandlers.Post event) { + registry.submitItemColors((item, name) -> { + Function itemColorCreator = event.getNamedItemColors().get(name); + if(itemColorCreator == null) + z.log.error("Unknown item color creator {} used on item {}", name, item); + else + event.register(itemColorCreator.apply(item), item); + }); + } +} diff --git a/src/main/java/vazkii/zeta/client/ZetaClient.java b/src/main/java/vazkii/zeta/client/ZetaClient.java index ca849bcf1e..92771723ab 100644 --- a/src/main/java/vazkii/zeta/client/ZetaClient.java +++ b/src/main/java/vazkii/zeta/client/ZetaClient.java @@ -23,9 +23,10 @@ public ZetaClient(Zeta zeta) { //this.ticker = new ClientTicker(); this.ticker = zeta.ticker_SHOULD_NOT_BE_HERE; //TODO, move ClientTicker into actual client code - this.clientConfigManager = new ClientConfigManager(); - this.topLayerTooltipHandler = new TopLayerTooltipHandler(); - this.clientDyeablesRegistry = zeta.dyeables.new Client(this); + this.clientConfigManager = createClientConfigManager(); + this.topLayerTooltipHandler = createTopLayerTooltipHandler(); + this.clientDyeablesRegistry = createClientDyeablesRegistry(); + this.clientRegistryExtension = createClientRegistryExtension(); playBus.subscribe(topLayerTooltipHandler); } @@ -40,6 +41,23 @@ public ZetaClient(Zeta zeta) { public final ClientConfigManager clientConfigManager; public final TopLayerTooltipHandler topLayerTooltipHandler; public final DyeablesRegistry.Client clientDyeablesRegistry; + public final ClientRegistryExtension clientRegistryExtension; + + public ClientConfigManager createClientConfigManager() { + return new ClientConfigManager(); + } + + public TopLayerTooltipHandler createTopLayerTooltipHandler() { + return new TopLayerTooltipHandler(); + } + + public DyeablesRegistry.Client createClientDyeablesRegistry() { + return zeta.dyeables.new Client(this); + } + + public ClientRegistryExtension createClientRegistryExtension() { + return new ClientRegistryExtension(this.zeta); + } //forge makes these weird public abstract @Nullable BlockColor getBlockColor(BlockColors bcs, Block block); diff --git a/src/main/java/vazkii/zeta/client/event/ZAddBlockColorHandlers.java b/src/main/java/vazkii/zeta/client/event/ZAddBlockColorHandlers.java index 66326d1620..b0d7f52701 100644 --- a/src/main/java/vazkii/zeta/client/event/ZAddBlockColorHandlers.java +++ b/src/main/java/vazkii/zeta/client/event/ZAddBlockColorHandlers.java @@ -1,5 +1,8 @@ package vazkii.zeta.client.event; +import java.util.Map; +import java.util.function.Function; + import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.block.BlockColors; import net.minecraft.world.level.block.Block; @@ -7,5 +10,11 @@ public interface ZAddBlockColorHandlers extends IZetaLoadEvent { void register(BlockColor c, Block... blocks); + void registerNamed(Function c, String... names); BlockColors getBlockColors(); + + Post makePostEvent(); + interface Post extends ZAddBlockColorHandlers { + Map> getNamedBlockColors(); + } } diff --git a/src/main/java/vazkii/zeta/client/event/ZAddItemColorHandlers.java b/src/main/java/vazkii/zeta/client/event/ZAddItemColorHandlers.java index 2d301b6775..b87e7263a1 100644 --- a/src/main/java/vazkii/zeta/client/event/ZAddItemColorHandlers.java +++ b/src/main/java/vazkii/zeta/client/event/ZAddItemColorHandlers.java @@ -1,11 +1,21 @@ package vazkii.zeta.client.event; +import java.util.Map; +import java.util.function.Function; + import net.minecraft.client.color.item.ItemColor; import net.minecraft.client.color.item.ItemColors; +import net.minecraft.world.item.Item; import net.minecraft.world.level.ItemLike; import vazkii.zeta.event.bus.IZetaLoadEvent; public interface ZAddItemColorHandlers extends IZetaLoadEvent { void register(ItemColor c, ItemLike... items); + void registerNamed(Function c, String... names); ItemColors getItemColors(); + + Post makePostEvent(); + interface Post extends ZAddItemColorHandlers { + Map> getNamedItemColors(); + } } diff --git a/src/main/java/vazkii/zeta/event/bus/ZetaEventBus.java b/src/main/java/vazkii/zeta/event/bus/ZetaEventBus.java index 8007849142..71dbdd6954 100644 --- a/src/main/java/vazkii/zeta/event/bus/ZetaEventBus.java +++ b/src/main/java/vazkii/zeta/event/bus/ZetaEventBus.java @@ -113,7 +113,7 @@ public T fire(@NotNull T event, Class firedAs) { Listeners subs = listenerMap.get(firedAs); if(subs != null) { if(logSpam != null) - logSpam.info("Dispatching {} (as {}) to {} listeners", logspamSimpleName(event.getClass()), logspamSimpleName(firedAs), subs.size(), subs.size() > 1 ? "s" : ""); + logSpam.info("Dispatching {} (as {}) to {} listener{}", logspamSimpleName(event.getClass()), logspamSimpleName(firedAs), subs.size(), subs.size() > 1 ? "s" : ""); subs.doFire(event); } diff --git a/src/main/java/vazkii/zeta/module/ZetaModuleManager.java b/src/main/java/vazkii/zeta/module/ZetaModuleManager.java index a5df0648f7..613670b514 100644 --- a/src/main/java/vazkii/zeta/module/ZetaModuleManager.java +++ b/src/main/java/vazkii/zeta/module/ZetaModuleManager.java @@ -51,6 +51,10 @@ public Optional getOptional(Class keyClass) { return Optional.ofNullable(get(keyClass)); } + public boolean isEnabled(Class keyClass) { + return get(keyClass).enabled; + } + // Categories // public ZetaCategory getCategory(String id) { diff --git a/src/main/java/vazkii/zeta/registry/IZetaBlockColorProvider.java b/src/main/java/vazkii/zeta/registry/IZetaBlockColorProvider.java index bffb1abc03..6309a4389d 100644 --- a/src/main/java/vazkii/zeta/registry/IZetaBlockColorProvider.java +++ b/src/main/java/vazkii/zeta/registry/IZetaBlockColorProvider.java @@ -1,13 +1,7 @@ package vazkii.zeta.registry; -import net.minecraft.client.color.block.BlockColor; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import org.jetbrains.annotations.Nullable; -@Deprecated //not side-safe public interface IZetaBlockColorProvider extends IZetaItemColorProvider { - - @OnlyIn(Dist.CLIENT) - public BlockColor getBlockColor(); - -} \ No newline at end of file + @Nullable String getBlockColorProviderName(); +} diff --git a/src/main/java/vazkii/zeta/registry/IZetaItemColorProvider.java b/src/main/java/vazkii/zeta/registry/IZetaItemColorProvider.java index 2a27223dc4..b91aeb6d9f 100644 --- a/src/main/java/vazkii/zeta/registry/IZetaItemColorProvider.java +++ b/src/main/java/vazkii/zeta/registry/IZetaItemColorProvider.java @@ -1,13 +1,7 @@ package vazkii.zeta.registry; -import net.minecraft.client.color.item.ItemColor; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; +import org.jetbrains.annotations.Nullable; -@Deprecated //not side-safe public interface IZetaItemColorProvider { - - @OnlyIn(Dist.CLIENT) - public ItemColor getItemColor(); - -} \ No newline at end of file + @Nullable String getItemColorProviderName(); +} diff --git a/src/main/java/vazkii/zeta/registry/IZetaItemColorProvider_OLD.java b/src/main/java/vazkii/zeta/registry/IZetaItemColorProvider_OLD.java new file mode 100644 index 0000000000..c8f4318953 --- /dev/null +++ b/src/main/java/vazkii/zeta/registry/IZetaItemColorProvider_OLD.java @@ -0,0 +1,18 @@ +package vazkii.zeta.registry; + +import net.minecraft.client.color.item.ItemColor; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +/** + * @deprecated zeta - This API relies on OnlyIn stripping to be side-safe, so has been stubbed. + * Please use IZetaItemColorProvider, and register "named" color provider creators in + * ZAddItemColorHandlers event. + */ +@Deprecated(forRemoval = true) +public interface IZetaItemColorProvider_OLD { + + @OnlyIn(Dist.CLIENT) + public ItemColor getItemColor(); + +} \ No newline at end of file diff --git a/src/main/java/vazkii/zeta/registry/ZetaRegistry.java b/src/main/java/vazkii/zeta/registry/ZetaRegistry.java index f996aa4dec..4ce84327bc 100644 --- a/src/main/java/vazkii/zeta/registry/ZetaRegistry.java +++ b/src/main/java/vazkii/zeta/registry/ZetaRegistry.java @@ -1,6 +1,7 @@ package vazkii.zeta.registry; import java.util.Collection; +import java.util.HashMap; import java.util.IdentityHashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -9,8 +10,6 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -30,8 +29,8 @@ public abstract class ZetaRegistry { //the keys of this are things like "minecraft:block", "minecraft:item" and so on private final Multimap> defers = ArrayListMultimap.create(); private final Map internalNames = new IdentityHashMap<>(); - private final Map itemColors = new IdentityHashMap<>(); - private final Map blockColors = new IdentityHashMap<>(); + private final Map itemsToColorProviderName = new HashMap<>(); + private final Map blocksToColorProviderName = new HashMap<>(); private final Map groups = new LinkedHashMap<>(); public ZetaRegistry(Zeta z) { @@ -53,18 +52,20 @@ public ResourceLocation getInternalName(Object obj) { return internalNames.get(obj); } - public void register(T obj, String resloc, ResourceKey> registry) { - register(obj, newResourceLocation(resloc), registry); - } - + //Root registration method public void register(T obj, ResourceLocation id, ResourceKey> registry) { if(obj == null) throw new IllegalArgumentException("Can't register null object."); + handleColors(obj, obj); setInternalName(obj, id); defers.put(registry.location(), () -> obj); } + public void register(T obj, String resloc, ResourceKey> registry) { + register(obj, newResourceLocation(resloc), registry); + } + //You know how `new ResourceLocation(String)` prepends "minecraft" if there's no prefix? //This method is like that, except it prepends *your* modid public ResourceLocation newResourceLocation(String in) { @@ -79,14 +80,11 @@ public void register(T obj, ResourceKey> registry) { if(getInternalName(obj) == null) throw new IllegalArgumentException("Can't register object without registry name."); - defers.put(registry.location(), () -> obj); + register(obj, getInternalName(obj), registry); } public void registerItem(Item item, String resloc) { register(item, resloc, Registry.ITEM_REGISTRY); - - if(item instanceof IZetaItemColorProvider) - itemColors.put(item, (IZetaItemColorProvider) item); } public void registerBlock(Block block, String resloc) { @@ -98,12 +96,8 @@ public void registerBlock(Block block, String resloc, boolean hasBlockItem) { //TODO: this supplier is mostly a load-bearing way to defer calling groups.get(registryName), // until after CreativeTabHandler.finalizeTabs is called - if(hasBlockItem) { + if(hasBlockItem) defers.put(Registry.ITEM_REGISTRY.location(), () -> createItemBlock(block)); - } - - if(block instanceof IZetaBlockColorProvider) - blockColors.put(block, (IZetaBlockColorProvider) block); } public void setCreativeTab(Block block, CreativeModeTab group) { @@ -130,13 +124,25 @@ private Item createItemBlock(Block block) { blockitem = ((IZetaBlockItemProvider) block).provideItemBlock(block, props); else blockitem = new BlockItem(block, props); - if(block instanceof IZetaItemColorProvider) - itemColors.put(blockitem, (IZetaItemColorProvider) block); - + handleColors(blockitem, block); setInternalName(blockitem, registryName); return blockitem; } + private void handleColors(Object thing, Object prov) { + if(thing instanceof Block block && prov instanceof IZetaBlockColorProvider provider) { + String blockColorProviderName = provider.getBlockColorProviderName(); + if(blockColorProviderName != null) + blocksToColorProviderName.put(block, blockColorProviderName); + } + + if(thing instanceof Item item && prov instanceof IZetaItemColorProvider provider) { + String itemColorProviderName = provider.getItemColorProviderName(); + if(itemColorProviderName != null) + itemsToColorProviderName.put(item, itemColorProviderName); + } + } + /// performing registration /// public Collection> getDefers(ResourceLocation registryId) { @@ -147,15 +153,13 @@ public void clearDeferCache(ResourceLocation resourceLocation) { defers.removeAll(resourceLocation); } - //TODO: sided woes - public void submitBlockColors(BiConsumer consumer) { - blockColors.forEach((k, v) -> consumer.accept(v.getBlockColor(), k)); - blockColors.clear(); + public void submitBlockColors(BiConsumer consumer) { + blocksToColorProviderName.forEach(consumer); + blocksToColorProviderName.clear(); } - //TODO: sided woes - public void submitItemColors(BiConsumer consumer) { - itemColors.forEach((k, v) -> consumer.accept(v.getItemColor(), k)); - itemColors.clear(); + public void submitItemColors(BiConsumer consumer) { + itemsToColorProviderName.forEach(consumer); + itemsToColorProviderName.clear(); } } diff --git a/src/main/java/vazkii/zetaimplforge/client/ForgeZetaClient.java b/src/main/java/vazkii/zetaimplforge/client/ForgeZetaClient.java index 8cab78d949..88a9a22ff6 100644 --- a/src/main/java/vazkii/zetaimplforge/client/ForgeZetaClient.java +++ b/src/main/java/vazkii/zetaimplforge/client/ForgeZetaClient.java @@ -141,13 +141,13 @@ public void start() { } public void registerBlockColors(RegisterColorHandlersEvent.Block event) { - loadBus.fire(new ForgeZAddBlockColorHandlers(event), ZAddBlockColorHandlers.class); - zeta.registry.submitBlockColors(event::register); //TODO: can be removed if IZetaBlockColorProvider goes + ZAddBlockColorHandlers e = loadBus.fire(new ForgeZAddBlockColorHandlers(event), ZAddBlockColorHandlers.class); + loadBus.fire(e.makePostEvent(), ZAddBlockColorHandlers.Post.class); } public void registerItemColors(RegisterColorHandlersEvent.Item event) { - loadBus.fire(new ForgeZAddItemColorHandlers(event), ZAddItemColorHandlers.class); - zeta.registry.submitItemColors(event::register); //TODO: can be removed if IZetaItemColorProvider goes + ZAddItemColorHandlers e = loadBus.fire(new ForgeZAddItemColorHandlers(event), ZAddItemColorHandlers.class); + loadBus.fire(e.makePostEvent(), ZAddItemColorHandlers.Post.class); } public void clientSetup(FMLClientSetupEvent event) { diff --git a/src/main/java/vazkii/zetaimplforge/event/client/ForgeZAddBlockColorHandlers.java b/src/main/java/vazkii/zetaimplforge/event/client/ForgeZAddBlockColorHandlers.java index 6eea0ea977..494c0f2fd8 100644 --- a/src/main/java/vazkii/zetaimplforge/event/client/ForgeZAddBlockColorHandlers.java +++ b/src/main/java/vazkii/zetaimplforge/event/client/ForgeZAddBlockColorHandlers.java @@ -1,19 +1,57 @@ package vazkii.zetaimplforge.event.client; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.block.BlockColors; import net.minecraft.world.level.block.Block; import net.minecraftforge.client.event.RegisterColorHandlersEvent; import vazkii.zeta.client.event.ZAddBlockColorHandlers; -public record ForgeZAddBlockColorHandlers(RegisterColorHandlersEvent.Block e) implements ZAddBlockColorHandlers { +public class ForgeZAddBlockColorHandlers implements ZAddBlockColorHandlers { + protected final RegisterColorHandlersEvent.Block e; + protected final Map> namedBlockColors; + + public ForgeZAddBlockColorHandlers(RegisterColorHandlersEvent.Block e) { + this(e, new HashMap<>()); + } + + protected ForgeZAddBlockColorHandlers(RegisterColorHandlersEvent.Block e, Map> namedBlockColors) { + this.e = e; + this.namedBlockColors = namedBlockColors; + } + @Override public void register(BlockColor blockColor, Block... blocks) { e.register(blockColor, blocks); } + @Override + public void registerNamed(Function c, String... names) { + for(String name : names) + namedBlockColors.put(name, c); + } + @Override public BlockColors getBlockColors() { return e.getBlockColors(); } + + @Override + public ZAddBlockColorHandlers.Post makePostEvent() { + return new Post(e, namedBlockColors); + } + + public static class Post extends ForgeZAddBlockColorHandlers implements ZAddBlockColorHandlers.Post { + public Post(RegisterColorHandlersEvent.Block e, Map> namedBlockColors) { + super(e, namedBlockColors); + } + + @Override + public Map> getNamedBlockColors() { + return namedBlockColors; + } + } } diff --git a/src/main/java/vazkii/zetaimplforge/event/client/ForgeZAddItemColorHandlers.java b/src/main/java/vazkii/zetaimplforge/event/client/ForgeZAddItemColorHandlers.java index cd2783b8e2..e3a43b4bad 100644 --- a/src/main/java/vazkii/zetaimplforge/event/client/ForgeZAddItemColorHandlers.java +++ b/src/main/java/vazkii/zetaimplforge/event/client/ForgeZAddItemColorHandlers.java @@ -1,19 +1,58 @@ package vazkii.zetaimplforge.event.client; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + import net.minecraft.client.color.item.ItemColor; import net.minecraft.client.color.item.ItemColors; +import net.minecraft.world.item.Item; import net.minecraft.world.level.ItemLike; import net.minecraftforge.client.event.RegisterColorHandlersEvent; import vazkii.zeta.client.event.ZAddItemColorHandlers; -public record ForgeZAddItemColorHandlers(RegisterColorHandlersEvent.Item e) implements ZAddItemColorHandlers { +public class ForgeZAddItemColorHandlers implements ZAddItemColorHandlers { + protected final RegisterColorHandlersEvent.Item e; + protected final Map> namedItemColors; + + public ForgeZAddItemColorHandlers(RegisterColorHandlersEvent.Item e) { + this(e, new HashMap<>()); + } + + public ForgeZAddItemColorHandlers(RegisterColorHandlersEvent.Item e, Map> namedItemColors) { + this.e = e; + this.namedItemColors = namedItemColors; + } + @Override public void register(ItemColor c, ItemLike... items) { e.register(c, items); } + @Override + public void registerNamed(Function c, String... names) { + for(String name : names) + namedItemColors.put(name, c); + } + @Override public ItemColors getItemColors() { return e.getItemColors(); } + + @Override + public Post makePostEvent() { + return new Post(e, namedItemColors); + } + + public static class Post extends ForgeZAddItemColorHandlers implements ZAddItemColorHandlers.Post { + public Post(RegisterColorHandlersEvent.Item e, Map> namedItemColors) { + super(e, namedItemColors); + } + + @Override + public Map> getNamedItemColors() { + return namedItemColors; + } + } }