Curios API (Forge/NeoForge)

Curios API (Forge/NeoForge)

140M Downloads

Server compatable when icons added

TheShadowModsUK opened this issue ยท 1 comments

commented

You have been so helpful so far, but I would like to ask your help again, when you have a moment this works fine local player but I need to make it work on a server I have tried checking if the world is remote but I can't seem to get it to complie since the player event isn't ready yet and all the examples I see entry = event.player, world = entry.world, well that's the idea.

What do I need to do to stop the server loading the textureStitch and creating it to creash?

package mypackage.mymod;

import top.theillusivec4.curios.api.SlotTypeMessage;
import top.theillusivec4.curios.api.CuriosApi;

import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraft.util.ResourceLocation;
import net.minecraft.entity.LivingEntity;

import javax.annotation.Nullable;

@Mod.EventBusSubscriber(modid = "mymod", bus = Mod.EventBusSubscriber.Bus.MOD)
public class CuriosBelt {
	private static final ResourceLocation ICON_THIS = new ResourceLocation("memod", "items/icon_this");

	@OnlyIn(Dist.CLIENT)
	private void textureStitch(TextureStitchEvent.Pre event) {
		event.addSprite(ICON_THIS);
	}

	public CuriosBelt() {
		if (ModList.get().isLoaded("curios")) {
			IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
			eventBus.addListener(this::setup);
			eventBus.addListener(this::enqueue);
			FMLJavaModLoadingContext.get().getModEventBus().addListener(this::textureStitch);
		}
	}

	private void setup(final FMLCommonSetupEvent evt) {
		MinecraftForge.EVENT_BUS.register(this);
	}

	@Nullable //not used or triggered anywhere
	public static IItemHandler getAll(LivingEntity living) {
		return CuriosApi.getCuriosHelper().getEquippedCurios(living).resolve().orElse(null);
	}

	public void enqueue(final InterModEnqueueEvent evt) {
		InterModComms.sendTo(CuriosApi.MODID, SlotTypeMessage.REGISTER_TYPE, () -> new SlotTypeMessage.Builder("TAGS").icon(ICONS_THIS).build());
	}

	@SubscribeEvent
	public static void init(FMLCommonSetupEvent event) {
		new CuriosBelt();
	}
}
commented

While I'll still try to help you, please note for future reference that this is more of a general modding question than a Curios question and isn't really appropriate for the issue tracker. If you need further support in this regard, please join the Discord and ask there instead.

You need to create a separate proxy class for the event instead of putting it in the same class as your common code. And then you can annotate it with

@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = "mymod", bus = Mod.EventBusSubscriber.Bus.MOD)

to make it only subscribe client-side.