1- //package dev.compactmods.machines.compat.jade;
2- //
3- //import com.mojang.authlib.GameProfile;
4- //import dev.compactmods.machines.api.CompactMachinesApi;
5- //import dev.compactmods.machines.i18n.MachineTranslations;
6- //import dev.compactmods.machines.api.room.CompactMachines.roomApi();
7- //import dev.compactmods.machines.machine.block.BoundCompactMachineBlockEntity;
8- //import net.minecraft.ChatFormatting;
9- //import net.minecraft.Util;
10- //import net.minecraft.nbt.CompoundTag;
11- //import net.minecraft.network.chat.Component;
12- //import net.minecraft.resources.ResourceLocation;
13- //import snownee.jade.api.BlockAccessor;
14- //import snownee.jade.api.IBlockComponentProvider;
15- //import snownee.jade.api.IServerDataProvider;
16- //import snownee.jade.api.ITooltip;
17- //import snownee.jade.api.config.IPluginConfig;
18- //
19- //public class BoundMachineProviders {
20- //
21- // public static final ResourceLocation UID = CompactMachinesApi.modRL("bound_machine");
22- //
23- // public static final IBlockComponentProvider COMPONENT_PROVIDER = new IBlockComponentProvider() {
24- // @Override
25- // public void appendTooltip(ITooltip tooltip, BlockAccessor blockAccessor, IPluginConfig config) {
26- // final var serverData = blockAccessor.getServerData();
27- //
28- // if (config.get(CompactMachinesApi.modRL("show_owner")) && serverData.contains("owner")) {
29- // final var owner = blockAccessor.getLevel().getPlayerByUUID(serverData.getUUID("owner"));
30- // if (owner != null) {
31- // GameProfile ownerProfile = owner.getGameProfile();
32- // tooltip.add(Component
33- // .translatable(MachineTranslations.IDs.OWNER, ownerProfile.getName())
34- // .withStyle(ChatFormatting.GRAY));
35- // }
36- // }
37- //
38- // if (serverData.contains("room_code")) {
39- // tooltip.add(Component
40- // .translatable(MachineTranslations.IDs.BOUND_TO, serverData.getString("room_code"))
41- // .withStyle(ChatFormatting.DARK_GRAY));
42- // }
43- // }
44- //
45- // @Override
46- // public ResourceLocation getUid() {
47- // return UID;
48- // }
49- // };
50- //
51- // public static final IServerDataProvider<BlockAccessor> SERVER_DATA = new IServerDataProvider<>() {
52- // @Override
53- // public void appendServerData(CompoundTag tag, BlockAccessor blockAccessor) {
54- // final var player = blockAccessor.getPlayer();
55- // if (blockAccessor.getBlockEntity() instanceof BoundCompactMachineBlockEntity machine) {
56- // var owner = machine.getOwnerUUID().orElse(Util.NIL_UUID);
57- // tag.putUUID("owner", owner);
58- //
59- // CompactMachines.roomApi().room(machine.connectedRoom()).ifPresent(inst -> {
60- // tag.putString("room_code", inst.code());
61- // });
62- // }
63- // }
64- //
65- // @Override
66- // public ResourceLocation getUid() {
67- // return UID;
68- // }
69- // };
70- //}
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+ }
0 commit comments