Skip to content

Commit

Permalink
split off into common and client sided plugin entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Aug 12, 2024
1 parent d8a4345 commit b2846a4
Show file tree
Hide file tree
Showing 85 changed files with 1,958 additions and 1,223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.nio.file.Path;
import java.util.Optional;

import mcp.mobius.waila.api.IPluginInfo;
import mcp.mobius.waila.api.WailaConstants;
import mcp.mobius.waila.plugin.PluginSide;
import mcp.mobius.waila.service.ICommonService;
import mcp.mobius.waila.util.ModInfo;
import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -40,10 +40,10 @@ public boolean isDev() {
}

@Override
public IPluginInfo.Side getSide() {
public PluginSide getSide() {
return switch (FabricLoader.getInstance().getEnvironmentType()) {
case CLIENT -> IPluginInfo.Side.CLIENT;
case SERVER -> IPluginInfo.Side.SERVER;
case CLIENT -> PluginSide.CLIENT;
case SERVER -> PluginSide.DEDICATED_SERVER;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import com.google.common.collect.Streams;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import mcp.mobius.waila.api.IPluginInfo;
import mcp.mobius.waila.plugin.PluginInfo;
import mcp.mobius.waila.plugin.PluginLoader;
import mcp.mobius.waila.plugin.PluginSide;
import mcp.mobius.waila.util.Log;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -81,26 +81,26 @@ protected void gatherPlugins() {
var initializer = plugin.get("initializer").getAsString();

var sideStr = plugin.containsKey("environment") ? plugin.get("environment").getAsString() : "both";
IPluginInfo.Side side;
PluginSide side;
switch (sideStr) {
case "client" -> side = IPluginInfo.Side.CLIENT;
case "server" -> side = IPluginInfo.Side.SERVER;
case "both" -> side = IPluginInfo.Side.BOTH;
case "client" -> side = PluginSide.CLIENT;
case "server" -> side = PluginSide.DEDICATED_SERVER;
case "both" -> side = PluginSide.COMMON;
default -> {
LOG.error("Environment for plugin {} is not valid, must be one of [client, server, both].", id);
continue;
}
}

if (side == IPluginInfo.Side.CLIENT && FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) {
if (side == PluginSide.CLIENT && FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) {
continue;
}

if (side == IPluginInfo.Side.SERVER && FabricLoader.getInstance().getEnvironmentType() != EnvType.SERVER) {
if (side == PluginSide.DEDICATED_SERVER && FabricLoader.getInstance().getEnvironmentType() != EnvType.SERVER) {
continue;
}

PluginInfo.register(mod.getMetadata().getId(), id, side, initializer, requiredDeps, true, true);
PluginInfo.registerDeprecated(mod.getMetadata().getId(), id, side, initializer, requiredDeps, true, true);
}
}
}
Expand Down
29 changes: 23 additions & 6 deletions platform/fabric/src/main/resources/waila_plugins.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
{
"waila:core" : {
"initializer": "mcp.mobius.waila.plugin.core.WailaPluginCore",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.core.CoreCommonPlugin",
"client": "mcp.mobius.waila.plugin.core.CoreClientPlugin"
},
"side" : "*",
"required" : []
},

"waila:vanilla" : {
"initializer": "mcp.mobius.waila.plugin.vanilla.WailaPluginVanilla",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.vanilla.VanillaCommonPlugin",
"client": "mcp.mobius.waila.plugin.vanilla.VanillaClientPlugin"
},
"side" : "*",
"required" : ["minecraft"]
},

"waila:harvest" : {
"initializer": "mcp.mobius.waila.plugin.harvest.WailaPluginHarvest",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.harvest.HarvestCommonPlugin",
"client": "mcp.mobius.waila.plugin.harvest.HarvestClientPlugin"
},
"side" : "*",
"required" : []
},

"waila:extra" : {
"initializer": "mcp.mobius.waila.plugin.extra.WailaPluginExtra",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.extra.ExtraPlugin",
"client": "mcp.mobius.waila.plugin.extra.ExtraPlugin"
},
"side" : "*",
"required" : []
},

"waila:fabric" : {
"initializer": "mcp.mobius.waila.plugin.fabric.WailaPluginFabric",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.fabric.FabricCommonPlugin",
"client": "mcp.mobius.waila.plugin.fabric.FabricClientPlugin"
},
"side" : "*",
"required" : ["fabric-api"]
},

"waila:team_reborn_energy": {
"initializer": "mcp.mobius.waila.plugin.trenergy.WailaPluginTeamRebornEnergy",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.trenergy.TeamRebornCommonPlugin"
},
"side" : "*",
"required" : ["team_reborn_energy"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mcp.mobius.waila.plugin.fabric;

import mcp.mobius.waila.plugin.textile.TextileClientPlugin;

public class FabricClientPlugin extends TextileClientPlugin {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mcp.mobius.waila.plugin.fabric;

import mcp.mobius.waila.plugin.textile.TextileCommonPlugin;

public class FabricCommonPlugin extends TextileCommonPlugin {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.jetbrains.annotations.ApiStatus;

/**
* @deprecated use {@code waila_plugins.json} file, see {@link IWailaPlugin} javadocs for more info.
* @deprecated use {@code waila_plugins.json} file, see {@link mcp.mobius.waila.api} javadocs for more info.
*/
@Deprecated
@Documented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.nio.file.Path;
import java.util.Optional;

import mcp.mobius.waila.api.IPluginInfo;
import mcp.mobius.waila.api.WailaConstants;
import mcp.mobius.waila.plugin.PluginSide;
import mcp.mobius.waila.service.ICommonService;
import mcp.mobius.waila.util.ModInfo;
import net.minecraftforge.fml.ModContainer;
Expand Down Expand Up @@ -43,10 +43,10 @@ public boolean isDev() {
}

@Override
public IPluginInfo.Side getSide() {
public PluginSide getSide() {
return switch (FMLLoader.getDist()) {
case CLIENT -> IPluginInfo.Side.CLIENT;
case DEDICATED_SERVER -> IPluginInfo.Side.SERVER;
case CLIENT -> PluginSide.CLIENT;
case DEDICATED_SERVER -> PluginSide.DEDICATED_SERVER;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mcp.mobius.waila.api.WailaPlugin;
import mcp.mobius.waila.plugin.PluginInfo;
import mcp.mobius.waila.plugin.PluginLoader;
import mcp.mobius.waila.plugin.PluginSide;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.loading.FMLLoader;
Expand All @@ -30,23 +31,27 @@ protected void gatherPlugins() {
if (annotation.annotationType().getClassName().equals(WAILA_PLUGIN)) {
var id = (String) annotation.annotationData().get("id");
var required = (String[]) annotation.annotationData().getOrDefault("required", new String[0]);
var side = (IPluginInfo.Side) annotation.annotationData().get("side");
var side = switch ((IPluginInfo.Side) annotation.annotationData().get("side")) {
case CLIENT -> PluginSide.CLIENT;
case SERVER -> PluginSide.DEDICATED_SERVER;
case BOTH -> PluginSide.COMMON;
};

var satisfied = true;
for (var dep : required) {
satisfied = satisfied && ModList.get().isLoaded(dep);
}

if (side == IPluginInfo.Side.CLIENT && FMLLoader.getDist() != Dist.CLIENT) {
if (side == PluginSide.CLIENT && FMLLoader.getDist() != Dist.CLIENT) {
satisfied = false;
}

if (side == IPluginInfo.Side.SERVER && FMLLoader.getDist() != Dist.DEDICATED_SERVER) {
if (side == PluginSide.DEDICATED_SERVER && FMLLoader.getDist() != Dist.DEDICATED_SERVER) {
satisfied = false;
}

if (satisfied) {
PluginInfo.register(modFile.getMods().get(0).getModId(), id, side, annotation.memberName(), Arrays.asList(required), true, true);
PluginInfo.registerDeprecated(modFile.getMods().get(0).getModId(), id, side, annotation.memberName(), Arrays.asList(required), true, true);
}
}
}
Expand Down
25 changes: 20 additions & 5 deletions platform/forge/src/main/resources/waila_plugins.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
{
"waila:core" : {
"initializer": "mcp.mobius.waila.plugin.core.WailaPluginCore",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.core.CoreCommonPlugin",
"client": "mcp.mobius.waila.plugin.core.CoreClientPlugin"
},
"side" : "*",
"required" : []
},

"waila:vanilla": {
"initializer": "mcp.mobius.waila.plugin.vanilla.WailaPluginVanilla",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.vanilla.VanillaCommonPlugin",
"client": "mcp.mobius.waila.plugin.vanilla.VanillaClientPlugin"
},
"side" : "*",
"required" : ["minecraft"]
},

"waila:harvest": {
"initializer": "mcp.mobius.waila.plugin.harvest.WailaPluginHarvest",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.harvest.HarvestCommonPlugin",
"client": "mcp.mobius.waila.plugin.harvest.HarvestClientPlugin"
},
"side" : "*",
"required" : []
},

"waila:extra" : {
"initializer": "mcp.mobius.waila.plugin.extra.WailaPluginExtra",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.extra.ExtraPlugin",
"client": "mcp.mobius.waila.plugin.extra.ExtraPlugin"
},
"side" : "*",
"required" : []
},

"waila:forge" : {
"initializer": "mcp.mobius.waila.plugin.forge.WailaPluginForge",
"entrypoints": {
"common": "mcp.mobius.waila.plugin.forge.ForgeCommonPlugin",
"client": "mcp.mobius.waila.plugin.forge.ForgeClientPlugin"
},
"side" : "*",
"required" : ["forge"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
package mcp.mobius.waila.plugin.forge;

import mcp.mobius.waila.api.IRegistrar;
import mcp.mobius.waila.api.IClientRegistrar;
import mcp.mobius.waila.api.IToolType;
import mcp.mobius.waila.api.IWailaPlugin;
import mcp.mobius.waila.api.IWailaClientPlugin;
import mcp.mobius.waila.api.data.FluidData;
import mcp.mobius.waila.plugin.forge.fluid.ForgeFluidDescriptor;
import mcp.mobius.waila.plugin.forge.provider.EnergyCapabilityProvider;
import mcp.mobius.waila.plugin.forge.provider.FluidCapabilityProvider;
import mcp.mobius.waila.plugin.forge.provider.ItemCapabilityProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.DoublePlantBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.material.Fluid;
import net.minecraftforge.common.IForgeShearable;
import net.minecraftforge.common.ToolActions;

public class WailaPluginForge implements IWailaPlugin {
public class ForgeClientPlugin implements IWailaClientPlugin {

@Override
public void register(IRegistrar registrar) {
public void register(IClientRegistrar registrar) {
FluidData.describeFluid(Fluid.class, ForgeFluidDescriptor.INSTANCE);
registrar.addBlockData(EnergyCapabilityProvider.INSTANCE, BlockEntity.class, 2000);
registrar.addBlockData(ItemCapabilityProvider.INSTANCE, BlockEntity.class, 2000);
registrar.addBlockData(FluidCapabilityProvider.INSTANCE, BlockEntity.class, 2000);

registrar.addToolType(ResourceLocation.withDefaultNamespace("pickaxe"), IToolType.builder()
.lowestTierItem(Items.WOODEN_PICKAXE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package mcp.mobius.waila.plugin.forge;

import mcp.mobius.waila.api.ICommonRegistrar;
import mcp.mobius.waila.api.IWailaCommonPlugin;
import mcp.mobius.waila.plugin.forge.provider.EnergyCapabilityProvider;
import mcp.mobius.waila.plugin.forge.provider.FluidCapabilityProvider;
import mcp.mobius.waila.plugin.forge.provider.ItemCapabilityProvider;
import net.minecraft.world.level.block.entity.BlockEntity;

public class ForgeCommonPlugin implements IWailaCommonPlugin {

@Override
public void register(ICommonRegistrar registrar) {
registrar.addBlockData(EnergyCapabilityProvider.INSTANCE, BlockEntity.class, 2000);
registrar.addBlockData(ItemCapabilityProvider.INSTANCE, BlockEntity.class, 2000);
registrar.addBlockData(FluidCapabilityProvider.INSTANCE, BlockEntity.class, 2000);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.nio.file.Path;
import java.util.Optional;

import mcp.mobius.waila.api.IPluginInfo;
import mcp.mobius.waila.api.WailaConstants;
import mcp.mobius.waila.plugin.PluginSide;
import mcp.mobius.waila.service.ICommonService;
import mcp.mobius.waila.util.ModInfo;
import net.neoforged.fml.ModContainer;
Expand Down Expand Up @@ -43,10 +43,10 @@ public boolean isDev() {
}

@Override
public IPluginInfo.Side getSide() {
public PluginSide getSide() {
return switch (FMLLoader.getDist()) {
case CLIENT -> IPluginInfo.Side.CLIENT;
case DEDICATED_SERVER -> IPluginInfo.Side.SERVER;
case CLIENT -> PluginSide.CLIENT;
case DEDICATED_SERVER -> PluginSide.DEDICATED_SERVER;
};
}

Expand Down
Loading

0 comments on commit b2846a4

Please sign in to comment.