Skip to content

Commit

Permalink
New color provider system that's more side-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Oct 29, 2023
1 parent 08dcf17 commit 020350a
Show file tree
Hide file tree
Showing 35 changed files with 528 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/vazkii/quark/base/block/QuarkInheritedPaneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

}
14 changes: 4 additions & 10 deletions src/main/java/vazkii/quark/base/block/QuarkSlabBlock.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
17 changes: 6 additions & 11 deletions src/main/java/vazkii/quark/base/block/QuarkStairsBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

}
14 changes: 4 additions & 10 deletions src/main/java/vazkii/quark/base/block/QuarkWallBlock.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
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;
import net.minecraft.world.item.ItemStack;
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;
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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";
}
}
28 changes: 12 additions & 16 deletions src/main/java/vazkii/quark/content/building/block/HedgeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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) {
Expand All @@ -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)];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -175,17 +175,13 @@ protected void createBlockStateDefinition(@Nonnull StateDefinition.Builder<Block
}

@Override
@OnlyIn(Dist.CLIENT)
public BlockColor getBlockColor() {
final BlockState leafState = leaf.defaultBlockState();
return (state, world, pos, tintIndex) -> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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";
}

}
Original file line number Diff line number Diff line change
@@ -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";
}

}
Loading

0 comments on commit 020350a

Please sign in to comment.