/
RecipesClientEvents.java
117 lines (105 loc) · 5.41 KB
/
RecipesClientEvents.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package knightminer.inspirations.recipes;
import knightminer.inspirations.Inspirations;
import knightminer.inspirations.common.ClientEvents;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.library.client.CustomTextureLoader;
import knightminer.inspirations.library.client.model.CauldronModel;
import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes;
import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents;
import knightminer.inspirations.recipes.client.BoilingParticle;
import knightminer.inspirations.recipes.item.MixedDyedBottleItem;
import knightminer.inspirations.recipes.tileentity.CauldronTileEntity;
import knightminer.inspirations.shared.SharedClientEvents;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.client.renderer.color.BlockColors;
import net.minecraft.client.renderer.color.ItemColors;
import net.minecraft.fluid.Fluids;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.resources.IResourceManager;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.biome.BiomeColors;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
@SuppressWarnings("unused")
@EventBusSubscriber(modid = Inspirations.modID, value = Dist.CLIENT, bus = Bus.MOD)
public class RecipesClientEvents extends ClientEvents {
/**
* Listener handling custom cauldron textures
*/
public static CustomTextureLoader cauldronTextures = new CustomTextureLoader(Inspirations.getResource("cauldron_textures"));
/** Called during mod construct to register early listeners */
public static void onConstruct() {
// listener to clear color cache from client utils
IResourceManager manager = Minecraft.getInstance().getResourceManager();
if (manager instanceof IReloadableResourceManager) {
((IReloadableResourceManager)manager).addReloadListener(cauldronTextures);
} else {
Inspirations.log.error("Failed to register resource reload listener, expected instance of IReloadableResourceManager but got {}", manager.getClass());
}
}
@SubscribeEvent
static void clientSetup(FMLClientSetupEvent event) {
RenderTypeLookup.setRenderLayer(InspirationsRecipes.honey, RenderType.getTranslucent());
RenderTypeLookup.setRenderLayer(InspirationsRecipes.honey.getFlowingFluid(), RenderType.getTranslucent());
if (Config.extendedCauldron.getAsBoolean()) {
RenderTypeLookup.setRenderLayer(Blocks.CAULDRON, RenderType.getCutout());
}
}
@SubscribeEvent
static void registerModelLoaders(ModelRegistryEvent event) {
ModelLoaderRegistry.registerLoader(Inspirations.getResource("cauldron"), CauldronModel.LOADER);
SharedClientEvents.configPack.addBlockstateReplacement(Config.extendedCauldron, Blocks.CAULDRON, "cauldron");
}
@SubscribeEvent
static void registerBlockColors(ColorHandlerEvent.Block event) {
BlockColors blockColors = event.getBlockColors();
// coloring of liquid inside, for fluids, potions, and dyes
registerBlockColors(blockColors, (state, world, pos, tintIndex) -> {
// skip tint index 0, that is particles
if (tintIndex > 0 && world != null && pos != null) {
// must be cauldron TE
TileEntity te = world.getTileEntity(pos);
if(te instanceof CauldronTileEntity) {
// if it contains water, run vanilla tinting
ICauldronContents contents = ((CauldronTileEntity) te).getContents();
if (!contents.matches(CauldronContentTypes.FLUID, Fluids.WATER)) {
return contents.getTintColor();
}
}
// water tinting if contains water or TE is missing
return BiomeColors.getWaterColor(world, pos);
}
return -1;
}, InspirationsRecipes.cauldron);
}
@SubscribeEvent
static void registerParticleFactories(ParticleFactoryRegisterEvent event) {
Minecraft.getInstance().particles.registerFactory(InspirationsRecipes.boilingParticle, BoilingParticle.Factory::new);
}
@SubscribeEvent
static void registerItemColors(ColorHandlerEvent.Item event) {
ItemColors itemColors = event.getItemColors();
// dyed water bottles
InspirationsRecipes.simpleDyedWaterBottle.forEach((color, bottle) -> itemColors.register((stack, index) -> index == 0 ? color.getColorValue() : -1, bottle));
registerItemColors(itemColors, (stack, index) -> index == 0 ? MixedDyedBottleItem.dyeFromBottle(stack) : -1, InspirationsRecipes.mixedDyedWaterBottle);
}
@SubscribeEvent
static void registerTextures(TextureStitchEvent.Pre event) {
if (PlayerContainer.LOCATION_BLOCKS_TEXTURE.equals(event.getMap().getTextureLocation())) {
event.addSprite(InspirationsRecipes.STILL_FLUID);
event.addSprite(InspirationsRecipes.FLOWING_FLUID);
}
}
}