1- //package dev.compactmods.machines.compat.jade;
2- //
3- //import com.mojang.authlib.GameProfile;
4- //import com.mojang.serialization.Codec;
5- //import dev.compactmods.machines.api.CompactMachines;
6- //import dev.compactmods.machines.api.attachment.CMDataAttachments;
7- //import dev.compactmods.machines.i18n.MachineTranslations;
8- //import dev.compactmods.machines.machine.block.BoundCompactMachineBlockEntity;
9- //import dev.compactmods.machines.room.Rooms;
10- //import net.minecraft.ChatFormatting;
11- //import net.minecraft.core.UUIDUtil;
12- //import net.minecraft.nbt.CompoundTag;
13- //import net.minecraft.network.chat.Component;
14- //import net.minecraft.resources.ResourceLocation;
15- //import net.minecraft.util.Mth;
16- //import net.minecraft.world.item.ItemStack;
17- //import net.minecraft.world.phys.Vec2;
18- //import snownee.jade.api.BlockAccessor;
19- //import snownee.jade.api.IBlockComponentProvider;
20- //import snownee.jade.api.IServerDataProvider;
21- //import snownee.jade.api.ITooltip;
22- //import snownee.jade.api.config.IPluginConfig;
23- //import snownee.jade.api.ui.BoxStyle;
24- //import snownee.jade.api.ui.IBoxElement;
25- //import snownee.jade.api.ui.IElement;
26- //import snownee.jade.api.ui.IElementHelper;
27- //import snownee.jade.api.ui.ScreenDirection;
28- //import snownee.jade.impl.ui.ElementHelper;
29- //
30- //public class BoundMachineProviders {
31- //
32- // public static final ResourceLocation UID = CompactMachines.modRL("bound_machine");
33- //
34- // public static final IBlockComponentProvider COMPONENT_PROVIDER = new IBlockComponentProvider() {
35- // @Override
36- // public void appendTooltip(ITooltip tooltip, BlockAccessor blockAccessor, IPluginConfig config) {
37- // final var serverData = blockAccessor.getServerData();
38- //
39- // final var el = IElementHelper.get();
40- //
41- // if (serverData.contains("room_code")) {
42- // final var boundTxt = el.text(Component
43- // .literal(serverData.getString("room_code"))
44- // .withStyle(ChatFormatting.DARK_GRAY));
45- //
46- // tooltip.add(boundTxt);
47- // }
48- //
49- // if (config.get(CompactMachines.modRL("show_owner")) && serverData.contains("owner")) {
50- // final var owner = blockAccessor.getLevel().getPlayerByUUID(serverData.getUUID("owner"));
51- // if (owner != null) {
52- // GameProfile ownerProfile = owner.getGameProfile();
53- //
54- // final var face = new PlayerFaceElement(ownerProfile)
55- // .size(new Vec2(12, 12))
56- // .message(null);
57- //
58- // var ownerName = el.text(Component
59- // .translatable(MachineTranslations.IDs.OWNER, ownerProfile.getName())
60- // .withStyle(ChatFormatting.DARK_GRAY));
61- //
62- // int sizeDiffY = Mth.floor(face.getSize().y - ownerName.getSize().y) / 2;
63- // ownerName.translate(new Vec2(0, sizeDiffY));
64- //
65- // var ownerTT = el.tooltip();
66- // ownerTT.add(face);
67- // ownerTT.append(el.spacer(4, 0));
68- // ownerTT.append(ownerName);
69- //
70- // var box = el.box(ownerTT, BoxStyle.getTransparent());
71- // tooltip.add(box);
72- // }
73- // }
74- // }
75- //
76- // @Override
77- // public ResourceLocation getUid() {
78- // return UID;
79- // }
80- // };
81- //
82- // public static final IServerDataProvider<BlockAccessor> SERVER_DATA = new IServerDataProvider<>() {
83- // @Override
84- // public void appendServerData(CompoundTag tag, BlockAccessor blockAccessor) {
85- // final var player = blockAccessor.getPlayer();
86- // if (blockAccessor.getBlockEntity() instanceof BoundCompactMachineBlockEntity machine) {
87- // CompactMachines.room(machine.connectedRoom()).ifPresent(inst -> {
88- // tag.store("room_code", Codec.STRING, inst.code());
89- // inst.getExistingData(CMDataAttachments.ROOM_OWNER).ifPresent(owner -> {
90- // tag.store("owner", UUIDUtil.CODEC, owner);
91- // });
92- // });
93- // }
94- // }
95- //
96- // @Override
97- // public ResourceLocation getUid() {
98- // return UID;
99- // }
100- // };
101- //}
1+ package dev .compactmods .machines .compat .jade ;
2+
3+ import com .mojang .authlib .GameProfile ;
4+ import com .mojang .serialization .Codec ;
5+ import dev .compactmods .machines .api .CompactMachines ;
6+ import dev .compactmods .machines .api .attachment .CMDataAttachments ;
7+ import dev .compactmods .machines .i18n .MachineTranslations ;
8+ import dev .compactmods .machines .machine .block .BoundCompactMachineBlockEntity ;
9+ import net .minecraft .ChatFormatting ;
10+ import net .minecraft .core .UUIDUtil ;
11+ import net .minecraft .nbt .CompoundTag ;
12+ import net .minecraft .network .chat .Component ;
13+ import net .minecraft .resources .ResourceLocation ;
14+ import net .minecraft .util .Mth ;
15+ import snownee .jade .api .BlockAccessor ;
16+ import snownee .jade .api .IBlockComponentProvider ;
17+ import snownee .jade .api .IServerDataProvider ;
18+ import snownee .jade .api .ITooltip ;
19+ import snownee .jade .api .config .IPluginConfig ;
20+ import snownee .jade .api .ui .BoxStyle ;
21+ import snownee .jade .api .ui .JadeUI ;
22+
23+ public class BoundMachineProviders {
24+
25+ public static final ResourceLocation UID = CompactMachines .modRL ("bound_machine" );
26+
27+ public static final IBlockComponentProvider COMPONENT_PROVIDER = new IBlockComponentProvider () {
28+ @ Override
29+ public void appendTooltip (ITooltip tooltip , BlockAccessor blockAccessor , IPluginConfig config ) {
30+ final var serverData = blockAccessor .getServerData ();
31+
32+ serverData .getString ("room_code" ).ifPresent (roomCode -> {
33+ final var boundTxt = JadeUI .text (Component
34+ .literal (roomCode )
35+ .withStyle (ChatFormatting .DARK_GRAY ));
36+
37+ tooltip .add (boundTxt );
38+ });
39+
40+ if (config .get (CompactMachines .modRL ("show_owner" ))) {
41+ serverData .read ("owner" , UUIDUtil .CODEC ).ifPresent (ownerID -> {
42+
43+ final var owner = blockAccessor .getLevel ().getPlayerByUUID (ownerID );
44+ if (owner != null ) {
45+ GameProfile ownerProfile = owner .getGameProfile ();
46+
47+ final var face = new PlayerFaceElement (ownerProfile );
48+
49+ var ownerName = JadeUI .text (Component
50+ .translatable (MachineTranslations .IDs .OWNER , ownerProfile .getName ())
51+ .withStyle (ChatFormatting .DARK_GRAY ));
52+
53+ int sizeDiffY = Mth .floor (face .getHeight () - ownerName .getHeight ()) / 2 ;
54+ // ownerName.(new Vec2(0, sizeDiffY));
55+
56+ var ownerTT = JadeUI .tooltip ();
57+ ownerTT .add (face );
58+ ownerTT .append (JadeUI .spacer (2 , 0 ));
59+ ownerTT .append (ownerName );
60+
61+ var box = JadeUI .box (ownerTT , BoxStyle .transparent ());
62+ tooltip .add (box );
63+ }
64+ });
65+ }
66+ }
67+
68+ @ Override
69+ public ResourceLocation getUid () {
70+ return UID ;
71+ }
72+ };
73+
74+ public static final IServerDataProvider <BlockAccessor > SERVER_DATA = new IServerDataProvider <>() {
75+ @ Override
76+ public void appendServerData (CompoundTag tag , BlockAccessor blockAccessor ) {
77+ final var player = blockAccessor .getPlayer ();
78+ if (blockAccessor .getBlockEntity () instanceof BoundCompactMachineBlockEntity machine ) {
79+ CompactMachines .room (machine .connectedRoom ()).ifPresent (inst -> {
80+ tag .store ("room_code" , Codec .STRING , inst .code ());
81+ inst .getExistingData (CMDataAttachments .ROOM_OWNER ).ifPresent (owner -> {
82+ tag .store ("owner" , UUIDUtil .CODEC , owner );
83+ });
84+ });
85+ }
86+ }
87+
88+ @ Override
89+ public ResourceLocation getUid () {
90+ return UID ;
91+ }
92+ };
93+ }
0 commit comments