/
RecipesClientProxy.java
79 lines (67 loc) · 2.64 KB
/
RecipesClientProxy.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
package knightminer.inspirations.recipes;
import knightminer.inspirations.common.ClientProxy;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.library.Util;
import knightminer.inspirations.library.client.NameStateMapper;
import knightminer.inspirations.recipes.tileentity.TileCauldron;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class RecipesClientProxy extends ClientProxy {
private static final ResourceLocation POTION_MODEL = new ResourceLocation("bottle_drinkable");
public static final ResourceLocation CAULDRON_MODEL = Util.getResource("cauldron");
@SubscribeEvent
public void registerModels(ModelRegistryEvent event) {
setModelStateMapper(InspirationsRecipes.cauldron, new NameStateMapper(CAULDRON_MODEL));
if(Config.enableCauldronDyeing) {
registerItemModel(InspirationsRecipes.dyedWaterBottle, POTION_MODEL);
}
}
@SubscribeEvent
public void registerBlockColors(ColorHandlerEvent.Block event) {
BlockColors blockColors = event.getBlockColors();
// coloring of liquid inside, either for potions or dyes
registerBlockColors(blockColors, (state, world, pos, tintIndex) -> {
if(tintIndex == 1) {
TileEntity te = world.getTileEntity(pos);
if(te instanceof TileCauldron) {
return ((TileCauldron) te).getColor();
}
}
return -1;
}, InspirationsRecipes.cauldron);
}
@SubscribeEvent
public void registerItemColors(ColorHandlerEvent.Item event) {
ItemColors itemColors = event.getItemColors();
// dyed water bottles
registerItemColors(itemColors, (stack, tintIndex) -> {
if(tintIndex == 0) {
return InspirationsRecipes.dyedWaterBottle.getColor(stack);
}
return -1;
}, InspirationsRecipes.dyedWaterBottle);
}
/**
* Replaces the bookshelf models with the dynamic texture model, which also handles books
*/
@SubscribeEvent
public void onModelBake(ModelBakeEvent event) {
if(InspirationsRecipes.cauldron == null) {
return;
}
boolean boiling = false;
do {
for(int i = 1; i <= 3; i++) {
replaceTexturedModel(event, new ModelResourceLocation(CAULDRON_MODEL, String.format("boiling=%s,contents=fluid,level=%s", boiling, i)), "water", false);
}
boiling = !boiling;
} while(boiling);
}
}