Skip to content

Commit

Permalink
Re-enable Jade compatibility
Browse files Browse the repository at this point in the history
- Add HudProvider enum for Jade/TOP provider IDs
  - TOP compatibility will be updated if/when TOP is updated
- Update ItemTooltipModNameRemover implementation to match current Jade code
- Clean up code slightly
  • Loading branch information
Choonster committed Nov 4, 2023
1 parent 695b2a2 commit 628ac0b
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 43 deletions.
7 changes: 7 additions & 0 deletions src/generated/resources/assets/testmod3/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@
"commands.testmod3.rotatevector.result": "Rotated vector: [%s, %s, %s]",
"commands.testmod3.runtests.tests_failed": "Tests failed. See log for more details.",
"commands.testmod3.runtests.tests_passed": "All tests passed.",
"config.jade.plugin_testmod3.chest_facing": "Mod Chest Facing",
"config.jade.plugin_testmod3.colored_multi_rotatable_block_face_rotation": "Colored Multi-Rotatable",
"config.jade.plugin_testmod3.colored_rotatable_block_facing": "Colored Rotatable Block Facing",
"config.jade.plugin_testmod3.plane_horizontal_rotation": "Plane Horizontal Rotation",
"config.jade.plugin_testmod3.plane_vertical_rotation": "Plane Vertical Rotation",
"config.jade.plugin_testmod3.restricted_fluid_tank_enabled_facings": "Restricted Fluid Tank Enabled Facings",
"config.jade.plugin_testmod3.rotatable_lamp_facing": "Rotatable Lamp Facing",
"container.testmod3.chest": "Mod Chest",
"effect.testmod3.test": "Test",
"entity.testmod3.block_detection_arrow": "Block Detection Arrow",
Expand Down
1 change: 0 additions & 1 deletion src/main/java/choonster/testmod3/TestMod3.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class TestMod3 {
private static final Logger LOGGER = LogUtils.getLogger();

public static final String MODID = "testmod3";
public static final String NAME = "Test Mod 3";

public static final SimpleChannel network = ModNetwork.getNetworkChannel();

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/choonster/testmod3/compat/HudProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package choonster.testmod3.compat;

import choonster.testmod3.TestMod3;
import net.minecraft.resources.ResourceLocation;

/**
* IDs for Jade and The One Probe providers.
*
* @author Choonster
*/
public enum HudProvider {
COLORED_ROTATABLE_BLOCK_FACING("colored_rotatable_block_facing"),
COLORED_MULTI_ROTATABLE_BLOCK_FACE_ROTATION("colored_multi_rotatable_block_face_rotation"),
ROTATABLE_LAMP_FACING("rotatable_lamp_facing"),
CHEST_FACING("chest_facing"),
PLANE_HORIZONTAL_ROTATION("plane_horizontal_rotation"),
PLANE_VERTICAL_ROTATION("plane_vertical_rotation"),
RESTRICTED_FLUID_TANK_ENABLED_FACINGS("restricted_fluid_tank_enabled_facings"),

;

private final String name;
private final ResourceLocation id;

HudProvider(final String name) {
this.name = name;
id = new ResourceLocation(TestMod3.MODID, name);
}

public String getName() {
return name;
}

public ResourceLocation getId() {
return id;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package choonster.testmod3.compat.waila;

import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.level.block.state.properties.Property;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
import snownee.jade.api.ITooltip;
import snownee.jade.api.config.IPluginConfig;

/**
* Adds a line to the Waila tooltip body displaying the current value of an enum property.
*
* @author Choonster
*/
/*
public class EnumPropertyProvider<T extends Enum<T> & StringRepresentable> implements IBlockComponentProvider {
protected final ResourceLocation uid;
protected final int defaultPriority;
Expand Down Expand Up @@ -33,12 +41,11 @@ public int getDefaultPriority() {

@Override
public void appendTooltip(final ITooltip tooltip, final BlockAccessor accessor, final IPluginConfig config) {
final BlockState state = accessor.getBlockState();
final var state = accessor.getBlockState();

final T value = state.getValue(property);
final String valueTranslationKey = valueTranslationKeyPrefix + "." + value.getSerializedName();
final var value = state.getValue(property);
final var valueTranslationKey = valueTranslationKeyPrefix + "." + value.getSerializedName();

tooltip.add(Component.translatable(tooltipTranslationKey, Component.translatable(valueTranslationKey)));
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package choonster.testmod3.compat.waila;

import choonster.testmod3.TestMod3;
import choonster.testmod3.init.ModItems;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import snownee.jade.Jade;

import java.util.function.Supplier;

/**
* Removes the mod name added by Waila to the tooltip of {@link ModItems#NO_MOD_NAME}.
Expand All @@ -10,15 +22,26 @@
*
* @author Choonster
*/
/*
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = TestMod3.MODID)
public class ItemTooltipModNameRemover {
@SubscribeEvent(priority = EventPriority.LOW)
private static final Supplier<String> MOD_NAME = Lazy.of(() ->
ModList.get()
.getModContainerById(TestMod3.MODID)
.map(c -> c.getModInfo().getDisplayName())
.orElseThrow()
);

@SubscribeEvent(priority = EventPriority.MONITOR)
public static void itemTooltip(final ItemTooltipEvent event) {
if (event.getItemStack().getItem() == ModItems.NO_MOD_NAME.get() && ModList.get().isLoaded("waila")) {
final String name = String.format(Jade.CONFIG.get().getFormatting().getModName(), TestMod3.NAME);
event.getToolTip().remove(Component.literal(name));
if (event.getItemStack().getItem() == ModItems.NO_MOD_NAME.get() && ModList.get().isLoaded("jade")) {
final var name = Component.literal(MOD_NAME.get())
.withStyle(
Jade.CONFIG.get()
.getFormatting()
.getItemModNameStyle()
);

event.getToolTip().remove(name);
}
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package choonster.testmod3.compat.waila;

import choonster.testmod3.text.TestMod3Lang;
import choonster.testmod3.util.EnumFaceRotation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.properties.Property;
import snownee.jade.api.TooltipPosition;

/**
* Adds a line to the Waila tooltip body displaying the current value of an {@link EnumFaceRotation} property.
*
* @author Choonster
*/
/*
public class MultiRotatableProvider extends EnumPropertyProvider<EnumFaceRotation> {
public MultiRotatableProvider(final ResourceLocation uid, final Property<EnumFaceRotation> property) {
super(
Expand All @@ -19,4 +22,3 @@ public MultiRotatableProvider(final ResourceLocation uid, final Property<EnumFac
);
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package choonster.testmod3.compat.waila;

import choonster.testmod3.text.TestMod3Lang;
import choonster.testmod3.world.level.block.RestrictedFluidTankBlock;
import choonster.testmod3.world.level.block.entity.RestrictedFluidTankBlockEntity;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
import snownee.jade.api.ITooltip;
import snownee.jade.api.TooltipPosition;
import snownee.jade.api.config.IPluginConfig;

/**
* Adds a line to the Waila tooltip body displaying the enabled facings of a {@link RestrictedFluidTankBlockEntity}.
*
* @author Choonster
*/
/*
public class RestrictedFluidTankEnabledFacingsProvider implements IBlockComponentProvider {
private final ResourceLocation uid;

Expand All @@ -27,14 +35,10 @@ public int getDefaultPriority() {

@Override
public void appendTooltip(final ITooltip tooltip, final BlockAccessor accessor, final IPluginConfig config) {
final var blockEntity = accessor.getBlockEntity();
if (blockEntity instanceof RestrictedFluidTankBlockEntity) {
final var enabledFacingsString = ((RestrictedFluidTankBlock) accessor.getBlock())
.getEnabledFacingsString(accessor.getLevel(), accessor.getPosition());
if (accessor.getBlock() instanceof final RestrictedFluidTankBlock block) {
final var enabledFacingsString = block.getEnabledFacingsString(accessor.getLevel(), accessor.getPosition());

tooltip.add(Component.translatable(TestMod3Lang.BLOCK_DESC_FLUID_TANK_RESTRICTED_ENABLED_FACINGS.getTranslationKey(), enabledFacingsString));
}
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package choonster.testmod3.compat.waila;

import choonster.testmod3.text.TestMod3Lang;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.properties.Property;
import snownee.jade.api.TooltipPosition;

/**
* Adds a line to the Waila tooltip body displaying the current value of a {@link Direction} property.
*
* @author Choonster
*/
/*
public class RotatableProvider extends EnumPropertyProvider<Direction> {
public RotatableProvider(final ResourceLocation uid, final Property<Direction> property) {
this(uid, property, TestMod3Lang.DESC_ROTATABLE_FACING.getTranslationKey());
Expand All @@ -23,4 +26,3 @@ public RotatableProvider(final ResourceLocation uid, final Property<Direction> p
);
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package choonster.testmod3.compat.waila;

import choonster.testmod3.text.TestMod3Lang;
import choonster.testmod3.world.level.block.PlaneBlock;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.properties.Property;
import snownee.jade.api.TooltipPosition;

/**
* Adds a line to the Waila tooltip body displaying the current value of an {@link PlaneBlock.VerticalRotation} property.
*
* @author Choonster
*/
/*
public class VerticalRotatableProvider extends EnumPropertyProvider<PlaneBlock.VerticalRotation> {
public VerticalRotatableProvider(final ResourceLocation uid, final Property<PlaneBlock.VerticalRotation> property) {
super(
Expand All @@ -19,4 +22,3 @@ public VerticalRotatableProvider(final ResourceLocation uid, final Property<Plan
);
}
}
*/
28 changes: 15 additions & 13 deletions src/main/java/choonster/testmod3/compat/waila/WailaCompat.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@
package choonster.testmod3.compat.waila;

import choonster.testmod3.compat.HudProvider;
import choonster.testmod3.text.TestMod3Lang;
import choonster.testmod3.world.level.block.*;
import snownee.jade.api.IBlockComponentProvider;
import snownee.jade.api.IWailaClientRegistration;
import snownee.jade.api.IWailaPlugin;
import snownee.jade.api.WailaPlugin;

/**
* Waila compatibility.
*
* @author Choonster
*/
/*
@WailaPlugin
public class WailaCompat implements IWailaPlugin {
public static final IBlockComponentProvider COLORED_ROTATABLE_BLOCK_FACING = new RotatableProvider(
uid("colored_rotatable_block_facing"),
HudProvider.COLORED_ROTATABLE_BLOCK_FACING.getId(),
ColoredRotatableBlock.FACING
);

public static final IBlockComponentProvider COLORED_MULTI_ROTATABLE_BLOCK_FACE_ROTATION = new MultiRotatableProvider(
uid("colored_multi_rotatable_block_face_rotation"),
HudProvider.COLORED_MULTI_ROTATABLE_BLOCK_FACE_ROTATION.getId(),
ColoredMultiRotatableBlock.FACE_ROTATION
);

public static final IBlockComponentProvider ROTATABLE_LAMP_FACING = new RotatableProvider(
uid("rotatable_lamp_facing"),
HudProvider.ROTATABLE_LAMP_FACING.getId(),
RotatableLampBlock.FACING
);

public static final IBlockComponentProvider CHEST_FACING = new RotatableProvider(
uid("chest_facing"),
HudProvider.CHEST_FACING.getId(),
ModChestBlock.FACING
);

public static final IBlockComponentProvider PLANE_HORIZONTAL_ROTATION = new RotatableProvider(
uid("plane_horizontal_rotation"),
HudProvider.PLANE_HORIZONTAL_ROTATION.getId(),
PlaneBlock.HORIZONTAL_ROTATION,
TestMod3Lang.BLOCK_DESC_PLANE_HORIZONTAL_ROTATION.getTranslationKey()
);

public static final IBlockComponentProvider PLANE_VERTICAL_ROTATION = new VerticalRotatableProvider(
uid("plane_vertical_rotation"),
HudProvider.PLANE_VERTICAL_ROTATION.getId(),
PlaneBlock.VERTICAL_ROTATION
);

public static final IBlockComponentProvider RESTRICTED_FLUID_TANK_ENABLED_FACINGS = new RestrictedFluidTankEnabledFacingsProvider(
uid("restricted_fluid_tank_enabled_facings")
HudProvider.RESTRICTED_FLUID_TANK_ENABLED_FACINGS.getId()
);

@Override
Expand All @@ -56,9 +63,4 @@ public void registerClient(final IWailaClientRegistration registration) {

registration.registerBlockComponent(RESTRICTED_FLUID_TANK_ENABLED_FACINGS, RestrictedFluidTankBlock.class);
}
private static ResourceLocation uid(final String name) {
return new ResourceLocation(TestMod3.MODID, name);
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package choonster.testmod3.data;

import choonster.testmod3.TestMod3;
import choonster.testmod3.compat.waila.WailaCompat;
import choonster.testmod3.fluid.group.FluidGroup;
import choonster.testmod3.init.*;
import choonster.testmod3.text.TestMod3Lang;
Expand All @@ -24,6 +25,7 @@
import net.minecraftforge.common.data.LanguageProvider;
import net.minecraftforge.fluids.FluidType;
import org.apache.commons.lang3.StringUtils;
import snownee.jade.api.IJadeProvider;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -56,7 +58,7 @@ protected void addTranslations() {
addConfig();
addChatMessages();
addSubtitles();
// addJadeProviders();
addJadeProviders();
addMisc();
}

Expand Down Expand Up @@ -329,7 +331,6 @@ private void addSubtitles() {
add(TestMod3Lang.SUBTITLE_ACTION_SADDLE, "Mod saddle equips");
}

/*
private void addJadeProviders() {
add(WailaCompat.COLORED_ROTATABLE_BLOCK_FACING, "Colored Rotatable Block Facing");
add(WailaCompat.COLORED_MULTI_ROTATABLE_BLOCK_FACE_ROTATION, "Colored Multi-Rotatable");
Expand All @@ -339,7 +340,6 @@ private void addJadeProviders() {
add(WailaCompat.PLANE_VERTICAL_ROTATION, "Plane Vertical Rotation");
add(WailaCompat.RESTRICTED_FLUID_TANK_ENABLED_FACINGS, "Restricted Fluid Tank Enabled Facings");
}
*/

private void addMisc() {
add("itemGroup." + TestMod3.MODID, "TestMod3");
Expand Down Expand Up @@ -404,12 +404,10 @@ private String getPotionItemTranslationKey(final Supplier<? extends Potion> poti
return stack.getItem().getDescriptionId(stack);
}

/*
private void add(final IJadeProvider provider, final String name) {
final var uid = provider.getUid();
add("config.jade.plugin_%s.%s".formatted(uid.getNamespace(), uid.getPath()), name);
}
*/

private void add(final TestMod3Lang lang, final String value) {
add(lang.getTranslationKey(), value);
Expand Down

0 comments on commit 628ac0b

Please sign in to comment.