-
Notifications
You must be signed in to change notification settings - Fork 81
/
WorldClientEvents.java
70 lines (57 loc) · 2.76 KB
/
WorldClientEvents.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
package com.progwml6.natura.world;
import com.progwml6.natura.Natura;
import com.progwml6.natura.common.ClientEventBase;
import com.progwml6.natura.world.block.TreeType;
import com.progwml6.natura.world.client.LeavesColorizer;
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.util.math.BlockPos;
import net.minecraft.world.IBlockDisplayReader;
import net.minecraft.world.biome.BiomeColors;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import javax.annotation.Nullable;
@SuppressWarnings("unused")
@Mod.EventBusSubscriber(modid = Natura.modID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class WorldClientEvents extends ClientEventBase {
@SubscribeEvent
static void clientSetup(FMLClientSetupEvent event) {
for (TreeType type : TreeType.values()) {
RenderTypeLookup.setRenderLayer(NaturaWorld.leaves.get(type), RenderType.getCutoutMipped());
RenderTypeLookup.setRenderLayer(NaturaWorld.sapling.get(type), RenderType.getCutout());
}
RenderTypeLookup.setRenderLayer(NaturaWorld.redwood_leaves.get(), RenderType.getCutoutMipped());
RenderTypeLookup.setRenderLayer(NaturaWorld.redwood_sapling.get(), RenderType.getCutout());
}
@SubscribeEvent
static void registerColorHandlers(ColorHandlerEvent.Item event) {
BlockColors blockColors = event.getBlockColors();
ItemColors itemColors = event.getItemColors();
for (TreeType type : TreeType.values()) {
blockColors.register(
(state, reader, pos, index) -> getLeavesColorByPos(reader, pos, type),
NaturaWorld.leaves.get(type)
);
}
blockColors.register((state, reader, pos, index) -> getLeavesColorByPos(reader, pos), NaturaWorld.redwood_leaves.get());
registerBlockItemColorAlias(blockColors, itemColors, NaturaWorld.leaves);
registerBlockItemColorAlias(blockColors, itemColors, NaturaWorld.redwood_leaves);
}
private static int getLeavesColorByPos(@Nullable IBlockDisplayReader reader, @Nullable BlockPos pos, TreeType type) {
if (pos == null || reader == null) {
return LeavesColorizer.getColorStatic(type);
}
return LeavesColorizer.getColorForPos(reader, pos, type);
}
private static int getLeavesColorByPos(@Nullable IBlockDisplayReader reader, @Nullable BlockPos pos) {
if (pos == null || reader == null) {
return LeavesColorizer.leaves2Color;
}
return BiomeColors.getFoliageColor(reader, pos);
}
}