-
Notifications
You must be signed in to change notification settings - Fork 18
/
ClientProxy.java
87 lines (77 loc) · 3.14 KB
/
ClientProxy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package knightminer.inspirations.common;
import knightminer.inspirations.Inspirations;
import knightminer.inspirations.shared.client.TextureModel;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.IUnbakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import java.util.function.BiFunction;
public class ClientProxy {
public ClientProxy() {
MinecraftForge.EVENT_BUS.register(this);
FMLJavaModLoadingContext.get().getModEventBus().register(this);
}
/*
* Item and block color handlers
*/
protected static void registerBlockColors(BlockColors blockColors, IBlockColor handler, Block ... blocks) {
for(Block block : blocks) {
if(block != null) {
blockColors.register(handler, block);
}
}
}
protected static void registerItemColors(ItemColors itemColors, IItemColor handler, Block ... blocks) {
for(Block block : blocks) {
if(block != null) {
Item item = Item.getItemFromBlock(block);
if(item != Items.AIR) {
itemColors.register(handler, item);
}
}
}
}
protected static void registerItemColors(ItemColors itemColors, IItemColor handler, Item ... items) {
for(Item item : items) {
if(item != null) {
itemColors.register(handler, item);
}
}
}
protected static void replaceModel(ModelBakeEvent event, ModelResourceLocation location, BiFunction<IBakedModel, IUnbakedModel, TextureModel> modelMaker) {
try {
// model to be retextured
IUnbakedModel model = ModelLoaderRegistry.getModel(location);
// model for rendering properties
IBakedModel standard = event.getModelRegistry().get(location);
// model to replace standard
TextureModel finalModel = modelMaker.apply(standard, model);
finalModel.fetchChildren(event.getModelLoader());
event.getModelRegistry().put(location, finalModel);
} catch(Exception e) {
Inspirations.log.error("Caught exception trying to replace model for " + location, e);
}
}
protected static void replaceTexturedModel(ModelBakeEvent event, ModelResourceLocation location, String key, boolean item) {
replaceModel(
event, location,
(orig, model) -> new TextureModel(orig, model, item ? DefaultVertexFormats.ITEM : DefaultVertexFormats.BLOCK, key, item)
);
}
protected static void replaceBothTexturedModels(ModelBakeEvent event, ResourceLocation loc, String key) {
replaceTexturedModel(event, new ModelResourceLocation(loc, ""), key, false);
replaceTexturedModel(event, new ModelResourceLocation(loc, "inventory"), key, true);
}
}