Skip to content

Commit

Permalink
document feature siding
Browse files Browse the repository at this point in the history
check client side before registering client only component
  • Loading branch information
deirn committed May 30, 2021
1 parent caf1c52 commit 78c66c4
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 35 deletions.
2 changes: 2 additions & 0 deletions common/src/main/java/mcp/mobius/waila/Waila.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public abstract class Waila {
public static WailaPlugins plugins;
public static Path configDir;

public static boolean clientSide = false;

public static Identifier id(String path) {
return new Identifier(WailaConstants.WAILA, path);
}
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/java/mcp/mobius/waila/api/IBlockAccessor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mcp.mobius.waila.api;

import mcp.mobius.waila.api.internal.ApiSide;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
Expand All @@ -11,8 +12,11 @@
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

@ApiSide.ClientOnly
@ApiStatus.NonExtendable
public interface IBlockAccessor {

World getWorld();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

import java.util.List;

import mcp.mobius.waila.api.internal.ApiSide;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;

/**
* Callback class interface used to provide Block/TileEntity tooltip informations to Waila.<br>
* All methods in this interface shouldn't to be called by the implementing mod. An instance of the class is to be
* registered to Waila via the {@link IRegistrar} instance provided in the original registration callback method
* (cf. {@link IRegistrar} documentation for more information).
*/
@ApiSide.ClientOnly
@ApiStatus.OverrideOnly
public interface IBlockComponentProvider {

/**
Expand All @@ -36,7 +40,7 @@ default BlockState getOverride(IBlockAccessor accessor, IPluginConfig config) {
* <p>
* This method is only called on the client side. If you require data from the server, you should also implement
* {@link IServerDataProvider#appendServerData(CompoundTag, ServerPlayerEntity, World, Object)} and add the data to the {@link CompoundTag}
* there, which can then be read back using {@link IBlockAccessor#getServerData()} ()}. If you rely on the client knowing
* there, which can then be read back using {@link IBlockAccessor#getServerData()}. If you rely on the client knowing
* the data you need, you are not guaranteed to have the proper values.
*
* @param accessor Contains most of the relevant information about the current environment.
Expand All @@ -56,7 +60,7 @@ default ItemStack getDisplayItem(IBlockAccessor accessor, IPluginConfig config)
* <p>
* This method is only called on the client side. If you require data from the server, you should also implement
* {@link IServerDataProvider#appendServerData(CompoundTag, ServerPlayerEntity, World, Object)} and add the data to the {@link CompoundTag}
* there, which can then be read back using {@link IBlockAccessor#getServerData()} ()}. If you rely on the client knowing
* there, which can then be read back using {@link IBlockAccessor#getServerData()}. If you rely on the client knowing
* the data you need, you are not guaranteed to have the proper values.
*
* @param tooltip Current list of tooltip lines (might have been processed by other providers and might be processed
Expand All @@ -75,7 +79,7 @@ default void appendHead(List<Text> tooltip, IBlockAccessor accessor, IPluginConf
* <p>
* This method is only called on the client side. If you require data from the server, you should also implement
* {@link IServerDataProvider#appendServerData(CompoundTag, ServerPlayerEntity, World, Object)} and add the data to the {@link CompoundTag}
* there, which can then be read back using {@link IBlockAccessor#getServerData()} ()}. If you rely on the client knowing
* there, which can then be read back using {@link IBlockAccessor#getServerData()}. If you rely on the client knowing
* the data you need, you are not guaranteed to have the proper values.
*
* @param tooltip Current list of tooltip lines (might have been processed by other providers and might be processed
Expand All @@ -97,7 +101,7 @@ default void appendBody(List<Text> tooltip, IBlockAccessor accessor, IPluginConf
* <p>
* This method is only called on the client side. If you require data from the server, you should also implement
* {@link IServerDataProvider#appendServerData(CompoundTag, ServerPlayerEntity, World, Object)} and add the data to the {@link CompoundTag}
* there, which can then be read back using {@link IBlockAccessor#getServerData()} ()}. If you rely on the client knowing
* there, which can then be read back using {@link IBlockAccessor#getServerData()}. If you rely on the client knowing
* the data you need, you are not guaranteed to have the proper values.
*
* @param tooltip Current list of tooltip lines (might have been processed by other providers and might be processed by other providers).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mcp.mobius.waila.api;

import mcp.mobius.waila.api.internal.ApiSide;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
Expand All @@ -11,6 +12,7 @@
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -19,6 +21,8 @@
* Common accessor for both Entity and Block/TileEntity.<br>
* Available data depends on what it is called upon (ie : getEntity() will return null if looking at a block, etc).<br>
*/
@ApiSide.ClientOnly
@ApiStatus.NonExtendable
public interface ICommonAccessor {

World getWorld();
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/java/mcp/mobius/waila/api/IDrawableText.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import java.awt.Dimension;

import mcp.mobius.waila.api.internal.ApiSide;
import mcp.mobius.waila.overlay.DrawableText;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.MutableText;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

/**
* A text that will be rendered as graphic instead.
*/
@ApiSide.ClientOnly
@ApiStatus.NonExtendable
public interface IDrawableText extends MutableText {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package mcp.mobius.waila.api;

import mcp.mobius.waila.api.internal.ApiSide;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

/**
* The Accessor is used to get some basic data out of the game without having to request direct access to the game engine.<br>
* It will also return things that are unmodified by the overriding systems (like getStack).<br>
* An instance of this interface is passed to most of Waila Entity callbacks.
*/
@ApiSide.ClientOnly
@ApiStatus.NonExtendable
public interface IEntityAccessor {

World getWorld();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

import java.util.List;

import mcp.mobius.waila.api.internal.ApiSide;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;

/**
* Callback class interface used to provide Entity tooltip information to Waila.<br>
* All methods in this interface shouldn't to be called by the implementing mod. An instance of the class is to be
* registered to Waila via the {@link IRegistrar} instance provided in the original registration callback method
* (cf. {@link IRegistrar} documentation for more information).
*/
@ApiSide.ClientOnly
@ApiStatus.OverrideOnly
public interface IEntityComponentProvider {

/**
Expand Down Expand Up @@ -51,7 +55,7 @@ default ItemStack getDisplayItem(IEntityAccessor accessor, IPluginConfig config)
* <p>
* This method is only called on the client side. If you require data from the server, you should also implement
* {@link IServerDataProvider#appendServerData(CompoundTag, ServerPlayerEntity, World, Object)} and add the data to the {@link CompoundTag}
* there, which can then be read back using {@link IEntityAccessor#getServerData()} ()}. If you rely on the client knowing
* there, which can then be read back using {@link IEntityAccessor#getServerData()}. If you rely on the client knowing
* the data you need, you are not guaranteed to have the proper values.
*
* @param tooltip Current list of tooltip lines (might have been processed by other providers and might be processed by other providers).
Expand All @@ -69,7 +73,7 @@ default void appendHead(List<Text> tooltip, IEntityAccessor accessor, IPluginCon
* <p>
* This method is only called on the client side. If you require data from the server, you should also implement
* {@link IServerDataProvider#appendServerData(CompoundTag, ServerPlayerEntity, World, Object)} and add the data to the {@link CompoundTag}
* there, which can then be read back using {@link IEntityAccessor#getServerData()} ()}. If you rely on the client knowing
* there, which can then be read back using {@link IEntityAccessor#getServerData()}. If you rely on the client knowing
* the data you need, you are not guaranteed to have the proper values.
*
* @param tooltip Current list of tooltip lines (might have been processed by other providers and might be processed by other providers).
Expand All @@ -87,7 +91,7 @@ default void appendBody(List<Text> tooltip, IEntityAccessor accessor, IPluginCon
* <p>
* This method is only called on the client side. If you require data from the server, you should also implement
* {@link IServerDataProvider#appendServerData(CompoundTag, ServerPlayerEntity, World, Object)} and add the data to the {@link CompoundTag}
* there, which can then be read back using {@link IEntityAccessor#getServerData()} ()}. If you rely on the client knowing
* there, which can then be read back using {@link IEntityAccessor#getServerData()}. If you rely on the client knowing
* the data you need, you are not guaranteed to have the proper values.
*
* @param tooltip Current list of tooltip lines (might have been processed by other providers and might be processed by other providers).
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/java/mcp/mobius/waila/api/IJsonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import java.nio.file.Path;
import java.util.function.ObjIntConsumer;
import java.util.function.Supplier;

import com.google.gson.Gson;

import java.util.function.ToIntFunction;

import com.google.gson.Gson;
import mcp.mobius.waila.utils.JsonConfig;
import org.jetbrains.annotations.ApiStatus;

/**
* An Interface for easy (de)serialization for config classes
*
* @param <T> the config class
*/
@ApiStatus.NonExtendable
public interface IJsonConfig<T> {

static <T> Builder0<T> of(Class<T> clazz) {
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/java/mcp/mobius/waila/api/IPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import java.util.Set;

import mcp.mobius.waila.api.internal.ApiSide;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

/**
* Read-only interface for Waila internal config storage.<br>
* An instance of this interface is passed to most of Waila callbacks as a way to change the behavior depending on client settings.
*/
@ApiSide.ClientOnly
@ApiStatus.NonExtendable
public interface IPluginConfig {

/**
Expand Down
19 changes: 19 additions & 0 deletions common/src/main/java/mcp/mobius/waila/api/IRegistrar.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package mcp.mobius.waila.api;

import mcp.mobius.waila.api.internal.ApiSide;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.NonExtendable
public interface IRegistrar {

/**
Expand All @@ -18,6 +21,7 @@ public interface IRegistrar {
* @param key the namespaced key
* @param defaultValue the default value
*/
@ApiSide.ClientOnly
void addConfig(Identifier key, boolean defaultValue);

/**
Expand All @@ -39,6 +43,7 @@ public interface IRegistrar {
*
* @see #DEFAULT_PRIORITY
*/
@ApiSide.ClientOnly
<T> void addOverride(IBlockComponentProvider provider, Class<T> clazz, int priority);

/**
Expand All @@ -50,6 +55,7 @@ public interface IRegistrar {
*
* @see #DEFAULT_PRIORITY
*/
@ApiSide.ClientOnly
default <T> void addOverride(IBlockComponentProvider provider, Class<T> clazz) {
addOverride(provider, clazz, DEFAULT_PRIORITY);
}
Expand All @@ -65,6 +71,7 @@ default <T> void addOverride(IBlockComponentProvider provider, Class<T> clazz) {
*
* @see #DEFAULT_PRIORITY
*/
@ApiSide.ClientOnly
<T> void addDisplayItem(IBlockComponentProvider provider, Class<T> clazz, int priority);

/**
Expand All @@ -75,6 +82,7 @@ default <T> void addOverride(IBlockComponentProvider provider, Class<T> clazz) {
* @param provider The data provider instance
* @param clazz The highest level class to apply to
*/
@ApiSide.ClientOnly
default <T> void addDisplayItem(IBlockComponentProvider provider, Class<T> clazz) {
addDisplayItem(provider, clazz, DEFAULT_PRIORITY);
}
Expand All @@ -90,6 +98,7 @@ default <T> void addDisplayItem(IBlockComponentProvider provider, Class<T> clazz
*
* @see #DEFAULT_PRIORITY
*/
@ApiSide.ClientOnly
<T> void addComponent(IBlockComponentProvider provider, TooltipPosition position, Class<T> clazz, int priority);

/**
Expand All @@ -100,6 +109,7 @@ default <T> void addDisplayItem(IBlockComponentProvider provider, Class<T> clazz
* @param position The position on the tooltip this applies to
* @param clazz The highest level class to apply to
*/
@ApiSide.ClientOnly
default <T> void addComponent(IBlockComponentProvider provider, TooltipPosition position, Class<T> clazz) {
addComponent(provider, position, clazz, DEFAULT_PRIORITY);
}
Expand All @@ -111,6 +121,7 @@ default <T> void addComponent(IBlockComponentProvider provider, TooltipPosition
* @param provider The data provider instance
* @param clazz The highest level class to apply to
*/
@ApiSide.ServerOnly
<T> void addBlockData(IServerDataProvider<BlockEntity> provider, Class<T> clazz);

/**
Expand All @@ -122,6 +133,7 @@ default <T> void addComponent(IBlockComponentProvider provider, TooltipPosition
*
* @see #DEFAULT_PRIORITY
*/
@ApiSide.ClientOnly
<T> void addOverride(IEntityComponentProvider provider, Class<T> clazz, int priority);

/**
Expand All @@ -132,6 +144,7 @@ default <T> void addComponent(IBlockComponentProvider provider, TooltipPosition
*
* @see #DEFAULT_PRIORITY
*/
@ApiSide.ClientOnly
default <T> void addOverride(IEntityComponentProvider provider, Class<T> clazz) {
addOverride(provider, clazz, DEFAULT_PRIORITY);
}
Expand All @@ -145,6 +158,7 @@ default <T> void addOverride(IEntityComponentProvider provider, Class<T> clazz)
*
* @see #DEFAULT_PRIORITY
*/
@ApiSide.ClientOnly
<T> void addDisplayItem(IEntityComponentProvider provider, Class<T> clazz, int priority);

/**
Expand All @@ -153,6 +167,7 @@ default <T> void addOverride(IEntityComponentProvider provider, Class<T> clazz)
* @param provider The data provider instance
* @param clazz The highest level class to apply to
*/
@ApiSide.ClientOnly
default <T> void addDisplayItem(IEntityComponentProvider provider, Class<T> clazz) {
addDisplayItem(provider, clazz, DEFAULT_PRIORITY);
}
Expand All @@ -167,6 +182,7 @@ default <T> void addDisplayItem(IEntityComponentProvider provider, Class<T> claz
*
* @see #DEFAULT_PRIORITY
*/
@ApiSide.ClientOnly
<T> void addComponent(IEntityComponentProvider provider, TooltipPosition position, Class<T> clazz, int priority);

/**
Expand All @@ -176,6 +192,7 @@ default <T> void addDisplayItem(IEntityComponentProvider provider, Class<T> claz
* @param position The position on the tooltip this applies to
* @param clazz The highest level class to apply to
*/
@ApiSide.ClientOnly
default <T> void addComponent(IEntityComponentProvider provider, TooltipPosition position, Class<T> clazz) {
addComponent(provider, position, clazz, DEFAULT_PRIORITY);
}
Expand All @@ -186,6 +203,7 @@ default <T> void addComponent(IEntityComponentProvider provider, TooltipPosition
* @param provider The data provider instance
* @param clazz The highest level class to apply to
*/
@ApiSide.ServerOnly
<T> void addEntityData(IServerDataProvider<Entity> provider, Class<T> clazz);

/**
Expand All @@ -195,6 +213,7 @@ default <T> void addComponent(IEntityComponentProvider provider, TooltipPosition
* @param id The identifier for lookup
* @param renderer The renderer instance
*/
@ApiSide.ClientOnly
void addRenderer(Identifier id, ITooltipRenderer renderer);

// TODO: Remove
Expand Down
Loading

0 comments on commit 78c66c4

Please sign in to comment.