5
5
import eu .midnightdust .visualoverhaul .block .renderer .FurnaceBlockEntityRenderer ;
6
6
import eu .midnightdust .visualoverhaul .block .renderer .JukeboxBlockEntityRenderer ;
7
7
import eu .midnightdust .visualoverhaul .config .VOConfig ;
8
- import me .sargunvohra .mcmods .autoconfig1u .AutoConfig ;
9
- import me .sargunvohra .mcmods .autoconfig1u .serializer .JanksonConfigSerializer ;
10
8
import net .fabricmc .api .ClientModInitializer ;
9
+ import net .fabricmc .fabric .api .client .event .lifecycle .v1 .ClientTickEvents ;
11
10
import net .fabricmc .fabric .api .client .rendereregistry .v1 .BlockEntityRendererRegistry ;
11
+ import net .fabricmc .fabric .api .client .rendering .v1 .ColorProviderRegistry ;
12
12
import net .fabricmc .fabric .api .object .builder .v1 .client .model .FabricModelPredicateProviderRegistry ;
13
13
import net .fabricmc .fabric .api .resource .ResourceManagerHelper ;
14
14
import net .fabricmc .fabric .impl .blockrenderlayer .BlockRenderLayerMapImpl ;
15
+ import net .fabricmc .fabric .impl .client .rendering .ColorProviderRegistryImpl ;
15
16
import net .fabricmc .fabric .impl .networking .ClientSidePacketRegistryImpl ;
16
17
import net .fabricmc .loader .api .FabricLoader ;
17
18
import net .minecraft .block .Block ;
23
24
import net .minecraft .client .MinecraftClient ;
24
25
import net .minecraft .client .render .RenderLayer ;
25
26
import net .minecraft .item .ItemStack ;
27
+ import net .minecraft .item .Items ;
26
28
import net .minecraft .item .MusicDiscItem ;
29
+ import net .minecraft .potion .PotionUtil ;
30
+ import net .minecraft .potion .Potions ;
27
31
import net .minecraft .util .Identifier ;
28
32
import net .minecraft .util .collection .DefaultedList ;
29
33
import net .minecraft .util .math .BlockPos ;
30
34
import net .minecraft .util .registry .Registry ;
35
+ import net .minecraft .world .biome .Biome ;
36
+ import net .minecraft .world .biome .BuiltinBiomes ;
37
+
38
+ import java .util .Objects ;
31
39
32
40
import static eu .midnightdust .visualoverhaul .VisualOverhaul .*;
33
41
42
+ @ SuppressWarnings ("deprecation" )
34
43
public class VisualOverhaulClient implements ClientModInitializer {
35
- public static VOConfig VO_CONFIG ;
36
- public static Block JukeBoxTop = new JukeboxTop ();
37
44
45
+ public static Block JukeBoxTop = new JukeboxTop ();
46
+ private final MinecraftClient client = MinecraftClient .getInstance ();
38
47
39
48
@ Override
40
49
public void onInitializeClient () {
41
- AutoConfig .register (VOConfig .class , JanksonConfigSerializer ::new );
42
- VO_CONFIG = AutoConfig .getConfigHolder (VOConfig .class ).getConfig ();
50
+ VOConfig .init ("visualoverhaul" , VOConfig .class );
43
51
44
52
// Block only registered on client, because it's just used for the renderer //
45
53
Registry .register (Registry .BLOCK , new Identifier ("visualoverhaul" ,"jukebox_top" ), JukeBoxTop );
@@ -58,7 +66,6 @@ public void onInitializeClient() {
58
66
}
59
67
});
60
68
61
-
62
69
ClientSidePacketRegistryImpl .INSTANCE .register (UPDATE_POTION_BOTTLES ,
63
70
(packetContext , attachedData ) -> {
64
71
BlockPos pos = attachedData .readBlockPos ();
@@ -67,21 +74,25 @@ public void onInitializeClient() {
67
74
inv .set (i , attachedData .readItemStack ());
68
75
}
69
76
packetContext .getTaskQueue ().execute (() -> {
70
- BrewingStandBlockEntity blockEntity = (BrewingStandBlockEntity ) MinecraftClient .getInstance ().world .getBlockEntity (pos );
71
- blockEntity .setStack (0 ,inv .get (0 ));
72
- blockEntity .setStack (1 ,inv .get (1 ));
73
- blockEntity .setStack (2 ,inv .get (2 ));
74
- blockEntity .setStack (3 ,inv .get (3 ));
75
- blockEntity .setStack (4 ,inv .get (4 ));
77
+ if (client .world != null && client .world .getBlockEntity (pos ) != null && client .world .getBlockEntity (pos ) instanceof BrewingStandBlockEntity ) {
78
+ BrewingStandBlockEntity blockEntity = (BrewingStandBlockEntity ) client .world .getBlockEntity (pos );
79
+ blockEntity .setStack (0 , inv .get (0 ));
80
+ blockEntity .setStack (1 , inv .get (1 ));
81
+ blockEntity .setStack (2 , inv .get (2 ));
82
+ blockEntity .setStack (3 , inv .get (3 ));
83
+ blockEntity .setStack (4 , inv .get (4 ));
84
+ }
76
85
});
77
86
});
78
87
ClientSidePacketRegistryImpl .INSTANCE .register (UPDATE_RECORD ,
79
88
(packetContext , attachedData ) -> {
80
89
BlockPos pos = attachedData .readBlockPos ();
81
90
ItemStack record = attachedData .readItemStack ();
82
91
packetContext .getTaskQueue ().execute (() -> {
83
- JukeboxBlockEntity blockEntity = (JukeboxBlockEntity )MinecraftClient .getInstance ().world .getBlockEntity (pos );
84
- blockEntity .setRecord (record );
92
+ if (client .world != null && client .world .getBlockEntity (pos ) != null && client .world .getBlockEntity (pos ) instanceof JukeboxBlockEntity ) {
93
+ JukeboxBlockEntity blockEntity = (JukeboxBlockEntity ) client .world .getBlockEntity (pos );
94
+ blockEntity .setRecord (record );
95
+ }
85
96
});
86
97
});
87
98
ClientSidePacketRegistryImpl .INSTANCE .register (UPDATE_FURNACE_ITEMS ,
@@ -92,16 +103,54 @@ public void onInitializeClient() {
92
103
inv .set (i , attachedData .readItemStack ());
93
104
}
94
105
packetContext .getTaskQueue ().execute (() -> {
95
- FurnaceBlockEntity blockEntity = (FurnaceBlockEntity )MinecraftClient .getInstance ().world .getBlockEntity (pos );
96
- blockEntity .setStack (0 ,inv .get (0 ));
97
- blockEntity .setStack (1 ,inv .get (1 ));
98
- blockEntity .setStack (2 ,inv .get (2 ));
106
+ if (client .world != null && client .world .getBlockEntity (pos ) != null && client .world .getBlockEntity (pos ) instanceof FurnaceBlockEntity ) {
107
+ FurnaceBlockEntity blockEntity = (FurnaceBlockEntity ) client .world .getBlockEntity (pos );
108
+ blockEntity .setStack (0 , inv .get (0 ));
109
+ blockEntity .setStack (1 , inv .get (1 ));
110
+ blockEntity .setStack (2 , inv .get (2 ));
111
+ }
99
112
});
100
113
});
101
114
115
+ // Register builtin resourcepacks
102
116
FabricLoader .getInstance ().getModContainer ("visualoverhaul" ).ifPresent (modContainer -> {
103
117
ResourceManagerHelper .registerBuiltinResourcePack (new Identifier ("visualoverhaul:nobottles" ), "resourcepacks/nobrewingbottles" , modContainer , true );
104
118
ResourceManagerHelper .registerBuiltinResourcePack (new Identifier ("visualoverhaul:fancyfurnace" ), "resourcepacks/fancyfurnace" , modContainer , true );
119
+ ResourceManagerHelper .registerBuiltinResourcePack (new Identifier ("visualoverhaul:coloredwaterbucket" ), "resourcepacks/coloredwaterbucket" , modContainer , true );
105
120
});
121
+
122
+ // Context Colored Items
123
+ if (VOConfig .coloredItems ) {
124
+ ClientTickEvents .END_CLIENT_TICK .register (client -> {
125
+ int waterColor ;
126
+ int foliageColor ;
127
+ if (client .world != null ) {
128
+ Biome biome = client .world .getBiome (client .player .getBlockPos ());
129
+ waterColor = biome .getWaterColor ();
130
+ foliageColor = biome .getFoliageColor ();
131
+ } else {
132
+ waterColor = BuiltinBiomes .PLAINS .getWaterColor ();
133
+ foliageColor = BuiltinBiomes .PLAINS .getFoliageColor ();
134
+ }
135
+ ColorProviderRegistry .ITEM .register ((stack , tintIndex ) -> waterColor , VisualOverhaul .Puddle );
136
+ ColorProviderRegistry .ITEM .register ((stack , tintIndex ) -> tintIndex == 0 ? -1 : waterColor , Items .WATER_BUCKET );
137
+ ColorProviderRegistry .ITEM .register ((stack , tintIndex ) -> foliageColor , Items .GRASS_BLOCK );
138
+ ColorProviderRegistry .ITEM .register ((stack , tintIndex ) -> foliageColor , Items .ACACIA_LEAVES );
139
+ ColorProviderRegistry .ITEM .register ((stack , tintIndex ) -> foliageColor , Items .DARK_OAK_LEAVES );
140
+ ColorProviderRegistry .ITEM .register ((stack , tintIndex ) -> foliageColor , Items .JUNGLE_LEAVES );
141
+ ColorProviderRegistry .ITEM .register ((stack , tintIndex ) -> foliageColor , Items .OAK_LEAVES );
142
+ ColorProviderRegistry .ITEM .register ((stack , tintIndex ) -> {
143
+ if (PotionUtil .getPotion (stack ) == Potions .WATER && tintIndex == 0 ) {
144
+ return waterColor ;
145
+ }
146
+ return tintIndex > 0 ? -1 : PotionUtil .getColor (stack );
147
+ }, Items .POTION );
148
+ });
149
+ }
150
+ // Else just register a static color for our puddle item
151
+ else {
152
+ ColorProviderRegistry .ITEM .register ((stack , tintIndex ) -> BuiltinBiomes .PLAINS .getWaterColor (), Puddle );
153
+ }
154
+ ColorProviderRegistry .BLOCK .register ((state , view , pos , tintIndex ) -> Objects .requireNonNull (ColorProviderRegistryImpl .BLOCK .get (Blocks .WATER )).getColor (state , view , pos , tintIndex ), Puddle );
106
155
}
107
156
}
0 commit comments