Skip to content

Commit

Permalink
Re-add basic JADE support
Browse files Browse the repository at this point in the history
  • Loading branch information
robotgryphon committed Mar 24, 2024
1 parent 94a7d07 commit 146056d
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 23 deletions.
33 changes: 18 additions & 15 deletions neoforge-main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,38 @@ repositories {
name = "Jared's maven"
}

maven("https://www.cursemaven.com") {
content {
includeGroup("curse.maven")
}
}

maven("https://modmaven.dev") {
// location of a maven mirror for JEI files, as a fallback
name = "ModMaven"
}
}

dependencies {
implementation(libraries.neoforge)

implementation(libraries.jnanoid)
jarJar(libraries.jnanoid)
// Core Projects and Libraries
this {
implementation(libraries.neoforge)

compileOnly(core)
compileOnly(coreApi)
compileOnly(roomApi)
compileOnly(roomUpgradeApi)
implementation(libraries.jnanoid)
jarJar(libraries.jnanoid)

testCompileOnly(core)
testCompileOnly(coreApi)
testCompileOnly(roomApi)
testCompileOnly(roomUpgradeApi)
listOf(core, coreApi, roomApi, roomUpgradeApi).forEach {
compileOnly(it)
testCompileOnly(it)
}

implementation(libraries.feather)
jarJar(libraries.feather) {
isTransitive = false
implementation(libraries.feather)
jarJar(libraries.feather) { isTransitive = false }
}

// Mods
compileOnly(mods.bundles.jei)
compileOnly(mods.jade)
}

tasks.withType<ProcessResources> {
Expand Down
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) {
}
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);
}

}
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);
}
}
}
13 changes: 5 additions & 8 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ dependencyResolutionManagement {
}

versionCatalogs.create("mods") {
this.library("jei-common", "mezz.jei", "jei-1.20.4-common-api")
.versionRef("jei")

this.library("jei-neo", "mezz.jei", "jei-1.20.4-neoforge-api")
.versionRef("jei");

this.bundle("jei", listOf("jei-common", "jei-neo"))

this.library("jei-common", "mezz.jei", "jei-1.20.4-common-api").versionRef("jei")
this.library("jei-neo", "mezz.jei", "jei-1.20.4-neoforge-api").versionRef("jei");
this.bundle("jei", listOf("jei-common", "jei-neo"))
this.version("jei", "17.3.0.49")

this.library("jade", "curse.maven", "jade-324717").version("5109393")
}
}

Expand Down

0 comments on commit 146056d

Please sign in to comment.