Skip to content

Commit

Permalink
Add color stuff on Neo
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Oct 13, 2024
1 parent 46c5d47 commit 2439d56
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.unlikepaladin.pfm.client.neoforge;

import net.minecraft.block.Block;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.registry.entry.RegistryEntry;

import java.util.Map;

public interface BlockColorsExtension {
Map<Block, BlockColorProvider> getColorMap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import net.minecraft.block.Block;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColorProvider;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.item.Item;

Expand All @@ -14,6 +16,8 @@ public class ColorRegistryImpl {
public static final Map<Block, RenderLayer> BLOCK_RENDER_LAYER_MAP = new HashMap<>();
public static final Map<Item, ItemColorProvider> ITEM_COLOR_PROVIDER_MAP = new HashMap<>();

public static BlockColors blockColors;
public static ItemColors itemColors;

public static void registerBlockColor(Block block, BlockColorProvider blockColorProvider) {
BLOCK_COLOR_PROVIDER_MAP.put(block, blockColorProvider);
Expand All @@ -26,4 +30,18 @@ public static void registerBlockToRenderLayer(Block block, RenderLayer renderLay
public static void registerItemColor(Item item, ItemColorProvider colorProvider) {
ITEM_COLOR_PROVIDER_MAP.put(item, colorProvider);
}

public static BlockColorProvider getBlockColor(Block block) {
if (BLOCK_COLOR_PROVIDER_MAP.containsKey(block)) {
return BLOCK_COLOR_PROVIDER_MAP.get(block);
}
return ((BlockColorsExtension) blockColors).getColorMap().get(block);
}

public static ItemColorProvider getItemColor(Item item) {
if (ITEM_COLOR_PROVIDER_MAP.containsKey(item)) {
return ITEM_COLOR_PROVIDER_MAP.get(item);
}
return ((ItemColorsExtension) itemColors).getColorMap().get(item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
public class ColorRegistryNeoForge {
@SubscribeEvent
public static void registerBlockColors(RegisterColorHandlersEvent.Block 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(RegisterColorHandlersEvent.Item event){
ColorRegistryImpl.itemColors = event.getItemColors();
ColorRegistry.registerItemColors();
ColorRegistryImpl.ITEM_COLOR_PROVIDER_MAP.forEach((item, colorProvider) -> event.getItemColors().register(colorProvider, item));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.unlikepaladin.pfm.client.neoforge;

import net.minecraft.client.color.item.ItemColorProvider;
import net.minecraft.item.Item;
import net.minecraft.registry.entry.RegistryEntry;

import java.util.Map;

public interface ItemColorsExtension {
Map<Item, ItemColorProvider> getColorMap();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.unlikepaladin.pfm.mixin.neoforge;

import com.unlikepaladin.pfm.client.neoforge.BlockColorsExtension;
import net.minecraft.block.Block;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.registry.entry.RegistryEntry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.HashMap;
import java.util.Map;

@Mixin(BlockColors.class)
public class BlockColorsAccessor implements BlockColorsExtension {

@Shadow
private final Map<Block, BlockColorProvider> providers = new HashMap<>();

@Override
public Map<Block, BlockColorProvider> getColorMap() {
return providers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.unlikepaladin.pfm.mixin.neoforge;

import com.unlikepaladin.pfm.client.neoforge.ItemColorsExtension;
import net.minecraft.client.color.item.ItemColorProvider;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.item.Item;
import net.minecraft.registry.entry.RegistryEntry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.HashMap;
import java.util.Map;

@Mixin(ItemColors.class)
public class ItemColorsAccessor implements ItemColorsExtension {

@Shadow
private final Map<Item, ItemColorProvider> providers = new HashMap<>();

@Override
public Map<Item, ItemColorProvider> getColorMap() {
return providers;
}
}
6 changes: 4 additions & 2 deletions neoforge/src/main/resources/pfm.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
"package": "com.unlikepaladin.pfm.mixin.neoforge",
"compatibilityLevel": "JAVA_8",
"client": [
"BlockColorsAccessor",
"ItemColorsAccessor",
"ItemRendererMixin",
"PFMModelLoaderMixin",
"PFMRenderLayersNeoForgeMixin"
],
"mixins": [
"PFMCookingPotBlockEntityMixin",
"PFMMinecraftServerMixin",
"PFMSaveLoaderMixin",
"PFMItemEntryAccessor",
"PFMLootPool$BuilderMixin",
"PFMMinecraftServerMixin",
"PFMReloadableResourceManagerImplMixin",
"PFMSaveLoaderMixin",
"SimpleRegistryAccessor"
],
"injectors": {
Expand Down

0 comments on commit 2439d56

Please sign in to comment.