Skip to content

Commit 035e5a1

Browse files
committed
more codec stuff
1 parent 73cfd45 commit 035e5a1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/main/java/net/anawesomguy/wsmlmb/block/CustomCraftingTableBlock.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package net.anawesomguy.wsmlmb.block;
22

3+
import com.mojang.serialization.MapCodec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
import net.anawesomguy.wsmlmb.util.WSMLMBUtil;
36
import net.minecraft.block.BlockState;
47
import net.minecraft.block.CraftingTableBlock;
58
import net.minecraft.entity.player.PlayerEntity;
@@ -8,6 +11,7 @@
811
import net.minecraft.screen.ScreenHandlerContext;
912
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
1013
import net.minecraft.text.Text;
14+
import net.minecraft.text.TextCodecs;
1115
import net.minecraft.util.math.BlockPos;
1216
import net.minecraft.world.World;
1317

@@ -17,6 +21,13 @@
1721
* So, you can just use this to create a functional custom crafting table.
1822
*/
1923
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+
2031
protected final Text titleText;
2132

2233
/**
@@ -33,7 +44,7 @@ public CustomCraftingTableBlock(Settings settings) {
3344
* @param titleTextLangKey the lang key of this block's screen's title.
3445
*/
3546
public CustomCraftingTableBlock(Settings settings, String titleTextLangKey) {
36-
this(settings, Text.translatable(titleTextLangKey));
47+
this(settings, WSMLMBUtil.toTranslatable(titleTextLangKey));
3748
}
3849

3950
/**
@@ -64,4 +75,9 @@ public boolean canUse(PlayerEntity player) {
6475
}, titleText
6576
);
6677
}
78+
79+
@Override
80+
public MapCodec<? extends CraftingTableBlock> getCodec() {
81+
return CODEC;
82+
}
6783
}

0 commit comments

Comments
 (0)