-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94a7d07
commit 146056d
Showing
5 changed files
with
121 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
neoforge-main/src/main/java/dev/compactmods/machines/neoforge/compat/MachineOverview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.compactmods.machines.neoforge.compat; | ||
|
||
import dev.compactmods.machines.api.room.RoomInstance; | ||
|
||
import java.util.UUID; | ||
|
||
public record MachineOverview(UUID owner, RoomInstance connectedRoom) { | ||
} |
24 changes: 24 additions & 0 deletions
24
neoforge-main/src/main/java/dev/compactmods/machines/neoforge/compat/jade/CMJadePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dev.compactmods.machines.neoforge.compat.jade; | ||
|
||
import dev.compactmods.machines.neoforge.machine.block.BoundCompactMachineBlock; | ||
import dev.compactmods.machines.neoforge.machine.block.BoundCompactMachineBlockEntity; | ||
import snownee.jade.api.IWailaClientRegistration; | ||
import snownee.jade.api.IWailaCommonRegistration; | ||
import snownee.jade.api.IWailaPlugin; | ||
import snownee.jade.api.TooltipPosition; | ||
import snownee.jade.api.WailaPlugin; | ||
|
||
@WailaPlugin | ||
public class CMJadePlugin implements IWailaPlugin { | ||
|
||
@Override | ||
public void register(IWailaCommonRegistration registration) { | ||
registration.registerBlockDataProvider(CompactMachineJadeProvider.INSTANCE, BoundCompactMachineBlockEntity.class); | ||
} | ||
|
||
@Override | ||
public void registerClient(IWailaClientRegistration registration) { | ||
registration.registerBlockComponent(CompactMachineJadeProvider.INSTANCE, BoundCompactMachineBlock.class); | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...c/main/java/dev/compactmods/machines/neoforge/compat/jade/CompactMachineJadeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package dev.compactmods.machines.neoforge.compat.jade; | ||
|
||
import com.mojang.authlib.GameProfile; | ||
import dev.compactmods.machines.api.Tooltips; | ||
import dev.compactmods.machines.api.room.RoomApi; | ||
import dev.compactmods.machines.i18n.TranslationUtil; | ||
import dev.compactmods.machines.neoforge.CompactMachines; | ||
import dev.compactmods.machines.neoforge.machine.block.BoundCompactMachineBlockEntity; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.Util; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.resources.ResourceLocation; | ||
import snownee.jade.api.BlockAccessor; | ||
import snownee.jade.api.IBlockComponentProvider; | ||
import snownee.jade.api.IServerDataProvider; | ||
import snownee.jade.api.ITooltip; | ||
import snownee.jade.api.config.IPluginConfig; | ||
|
||
public class CompactMachineJadeProvider implements IBlockComponentProvider, IServerDataProvider<BlockAccessor> { | ||
|
||
public static final CompactMachineJadeProvider INSTANCE = new CompactMachineJadeProvider(); | ||
|
||
@Override | ||
public ResourceLocation getUid() { | ||
return CompactMachines.rl("bound_machine"); | ||
} | ||
|
||
@Override | ||
public void appendServerData(CompoundTag tag, BlockAccessor blockAccessor) { | ||
final var player = blockAccessor.getPlayer(); | ||
if (blockAccessor.getBlockEntity() instanceof BoundCompactMachineBlockEntity machine) { | ||
var owner = machine.getOwnerUUID().orElse(Util.NIL_UUID); | ||
tag.putUUID("owner", owner); | ||
|
||
RoomApi.room(machine.connectedRoom()).ifPresent(inst -> { | ||
tag.putString("room_code", inst.code()); | ||
}); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public void appendTooltip(ITooltip tooltip, BlockAccessor blockAccessor, IPluginConfig config) { | ||
final var serverData = blockAccessor.getServerData(); | ||
if (serverData.contains("owner")) { | ||
final var owner = blockAccessor.getLevel().getPlayerByUUID(serverData.getUUID("owner")); | ||
if (owner != null) { | ||
GameProfile ownerProfile = owner.getGameProfile(); | ||
MutableComponent ownerText = TranslationUtil | ||
.tooltip(Tooltips.Machines.OWNER, ownerProfile.getName()) | ||
.withStyle(ChatFormatting.GRAY); | ||
|
||
tooltip.add(ownerText); | ||
} | ||
} | ||
|
||
if (serverData.contains("room_code")) { | ||
final var connectedComponent = TranslationUtil | ||
.tooltip(Tooltips.Machines.BOUND_TO, serverData.getString("room_code")) | ||
.withStyle(ChatFormatting.DARK_GRAY); | ||
|
||
tooltip.add(connectedComponent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters