1
1
package net .anawesomguy .wsmlmb .block ;
2
2
3
+ import com .mojang .serialization .MapCodec ;
4
+ import com .mojang .serialization .codecs .RecordCodecBuilder ;
5
+ import net .anawesomguy .wsmlmb .util .WSMLMBUtil ;
3
6
import net .minecraft .block .BlockState ;
4
7
import net .minecraft .block .CraftingTableBlock ;
5
8
import net .minecraft .entity .player .PlayerEntity ;
8
11
import net .minecraft .screen .ScreenHandlerContext ;
9
12
import net .minecraft .screen .SimpleNamedScreenHandlerFactory ;
10
13
import net .minecraft .text .Text ;
14
+ import net .minecraft .text .TextCodecs ;
11
15
import net .minecraft .util .math .BlockPos ;
12
16
import net .minecraft .world .World ;
13
17
17
21
* So, you can just use this to create a functional custom crafting table.
18
22
*/
19
23
public class CustomCraftingTableBlock extends CraftingTableBlock {
24
+ public static final MapCodec <CustomCraftingTableBlock > CODEC = RecordCodecBuilder .mapCodec (
25
+ instance -> instance .group (
26
+ createSettingsCodec (),
27
+ TextCodecs .CODEC .optionalFieldOf ("title_text" , Text .translatable ("container.crafting" )).forGetter (CustomCraftingTableBlock ::getTitleText )
28
+ ).apply (instance , CustomCraftingTableBlock ::new )
29
+ );
30
+
20
31
protected final Text titleText ;
21
32
22
33
/**
@@ -33,7 +44,7 @@ public CustomCraftingTableBlock(Settings settings) {
33
44
* @param titleTextLangKey the lang key of this block's screen's title.
34
45
*/
35
46
public CustomCraftingTableBlock (Settings settings , String titleTextLangKey ) {
36
- this (settings , Text . translatable (titleTextLangKey ));
47
+ this (settings , WSMLMBUtil . toTranslatable (titleTextLangKey ));
37
48
}
38
49
39
50
/**
@@ -64,4 +75,9 @@ public boolean canUse(PlayerEntity player) {
64
75
}, titleText
65
76
);
66
77
}
78
+
79
+ @ Override
80
+ public MapCodec <? extends CraftingTableBlock > getCodec () {
81
+ return CODEC ;
82
+ }
67
83
}
0 commit comments