Skip to content

Commit

Permalink
Fix block colors not being found correctly on forge
Browse files Browse the repository at this point in the history
Fix sink not being colored correctly
  • Loading branch information
UnlikePaladin committed Nov 22, 2024
1 parent 3ddfca5 commit a2dd4f6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
public class ColorRegistry {
public static void registerBlockColors(){
List<Block> sinks = new ArrayList<>();
KitchenSinkBlock.streamStoneSinks().map(FurnitureBlock::getBlock).forEach(sinks::add);
KitchenSinkBlock.streamWoodSinks().map(FurnitureBlock::getBlock).forEach(sinks::add);
BasicSinkBlock.streamSinks().forEach(sinks::add);
sinks.forEach(block -> registerBlockColor(block, addWaterColor()));
registerBlockColor(PaladinFurnitureModBlocksItems.BASIC_TOILET, addToiletColor());
registerBlockColor(PaladinFurnitureModBlocksItems.BASIC_BATHTUB, addWaterColor());
registerBlockColor(PaladinFurnitureModBlocksItems.BASIC_LAMP, (state, world, pos, tintIndex) -> {
Expand All @@ -55,14 +51,36 @@ public static void registerBlockColors(){
PaladinFurnitureModBlocksItems.furnitureEntryMap.forEach((key, value) -> {
value.getVariantToBlockMap().forEach((variantBase, block) -> {
BlockColorProvider blockColorProvider = getBlockColor(variantBase.getBaseBlock());
if (blockColorProvider != null) {
registerBlockColor(block, blockColorProvider);
if (key.isAssignableFrom(KitchenSinkBlock.class)) {
registerBlockColor(block, ((state, world, pos, tintIndex) -> {
if (tintIndex == 1) {
return addWaterColor().getColor(state, world, pos, tintIndex);
} else if (blockColorProvider == null) {
return 0xFFFFFFF;
}
return blockColorProvider.getColor(state, world, pos, tintIndex);
}));
} else {
if (blockColorProvider != null) {
registerBlockColor(block, blockColorProvider);
}
}
});
value.getVariantToBlockMapNonBase().forEach((variantBase, block) -> {
BlockColorProvider blockColorProvider = getBlockColor(variantBase.getSecondaryBlock());
if (blockColorProvider != null) {
registerBlockColor(block, blockColorProvider);
BlockColorProvider blockColorProvider = getBlockColor(variantBase.getBaseBlock());
if (key.isAssignableFrom(KitchenSinkBlock.class)) {
registerBlockColor(block, ((state, world, pos, tintIndex) -> {
if (tintIndex == 1) {
return addWaterColor().getColor(state, world, pos, tintIndex);
} else if (blockColorProvider == null) {
return 0xFFFFFFF;
}
return blockColorProvider.getColor(state, world, pos, tintIndex);
}));
} else {
if (blockColorProvider != null) {
registerBlockColor(block, blockColorProvider);
}
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@
"from": [14, 14, 0],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [14, 0, 16, 2], "texture": "#legs", "cullface": "north"},
"east": {"uv": [0, 0, 16, 2], "texture": "#legs", "cullface": "east"},
"south": {"uv": [0, 0, 2, 2], "texture": "#legs", "cullface": "south"},
"up": {"uv": [14, 0, 16, 16], "texture": "#legs", "cullface": "up"},
"down": {"uv": [0, 0, 2, 16], "texture": "#legs"}
"north": {"uv": [14, 0, 16, 2], "texture": "#legs", "cullface": "north", "tintindex": 0},
"east": {"uv": [0, 0, 16, 2], "texture": "#legs", "cullface": "east", "tintindex": 0},
"south": {"uv": [0, 0, 2, 2], "texture": "#legs", "cullface": "south", "tintindex": 0},
"up": {"uv": [14, 0, 16, 16], "texture": "#legs", "cullface": "up", "tintindex": 0},
"down": {"uv": [0, 0, 2, 16], "texture": "#legs", "tintindex": 0}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
"from": [14, 14, 0],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [14, 0, 16, 2], "texture": "#legs", "cullface": "north"},
"north": {"uv": [14, 0, 16, 2], "texture": "#legs", "cullface": "north", "tintindex": 0},
"east": {"uv": [0, 0, 16, 2], "texture": "#legs", "cullface": "east", "tintindex": 0},
"south": {"uv": [0, 0, 2, 2], "texture": "#legs", "cullface": "south", "tintindex": 0},
"up": {"uv": [14, 0, 16, 16], "texture": "#legs", "cullface": "up", "tintindex": 0},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

import com.unlikepaladin.pfm.client.ColorRegistry;
import net.minecraft.client.render.RenderLayers;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = "pfm", bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ColorRegistryForge {
@SubscribeEvent
public static void registerBlockColors(ColorHandlerEvent.Block event){
public static void registerBlockColors(ColorHandlerEvent.Item event){
ColorRegistryImpl.blockColors = event.getBlockColors();
ColorRegistry.registerBlockColors();
ColorRegistryImpl.BLOCK_COLOR_PROVIDER_MAP.forEach((block, blockColorProvider) -> event.getBlockColors().registerColorProvider(blockColorProvider, block));
}
@SubscribeEvent
public static void registerItemColors(ColorHandlerEvent.Item event){
ColorRegistryImpl.itemColors = event.getItemColors();
ColorRegistry.registerItemColors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.item.Item;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.bridge.game.PackType;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.client.PathPackRPWrapper;
import com.unlikepaladin.pfm.client.forge.ColorRegistryForge;
import com.unlikepaladin.pfm.config.PaladinFurnitureModConfig;
import com.unlikepaladin.pfm.registry.dynamic.forge.LateBlockRegistryForge;
import com.unlikepaladin.pfm.registry.forge.*;
Expand All @@ -20,6 +21,7 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AddPackFindersEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
Expand Down Expand Up @@ -50,11 +52,14 @@ public PaladinFurnitureModForge() {
MinecraftForge.EVENT_BUS.register(BlockEntityRegistryForge.class);
MinecraftForge.EVENT_BUS.register(SoundRegistryForge.class);
MinecraftForge.EVENT_BUS.register(NetworkRegistryForge.class);
FMLJavaModLoadingContext.get().getModEventBus().addListener(EventPriority.LOW, ColorRegistryForge::registerBlockColors);
FMLJavaModLoadingContext.get().getModEventBus().addListener(EventPriority.LOWEST, ColorRegistryForge::registerItemColors);
NetworkRegistryForge.registerPackets();
LateBlockRegistryForge.addDynamicBlockRegistration(Block.class);
LateBlockRegistryForge.addDynamicBlockRegistration(Item.class);
PaladinFurnitureMod.isClient = FMLEnvironment.dist == Dist.CLIENT;
FMLJavaModLoadingContext.get().getModEventBus().addListener(PaladinFurnitureModForge::generateResources);

}

@SubscribeEvent
Expand Down

0 comments on commit a2dd4f6

Please sign in to comment.