Jump to content

Recommended Posts

Posted

Hey, I've been searching for a solution for a few days now but haven't been able to find anything that fixes my problem. My keybindings crash the server version of the mod, and setting them up in my client proxy doesn't seem to fix it. Help?

 

Client Proxy:

package blfngl.fallout.proxy;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelSpider;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.EventBus;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import blfngl.fallout.Fallout;
import blfngl.fallout.entity.EntityAnt;
import blfngl.fallout.entity.EntityFeralGhoul;
import blfngl.fallout.entity.EntityGhoulReaver;
import blfngl.fallout.entity.EntityGhoulRoamer;
import blfngl.fallout.entity.projectile.EntityGrenade;
import blfngl.fallout.gui.GuiRadBar;
import blfngl.fallout.render.RenderAnt;
import blfngl.fallout.render.RenderFeralGhoul;
import blfngl.fallout.render.RenderGhoulReaver;
import blfngl.fallout.render.RenderGhoulRoamer;
import blfngl.fallout.util.FalloutKeyBinding;

public class ClientProxy extends CommonProxy
{
@Override
@SideOnly(Side.CLIENT)
public void initRender()
{
	EventBus eventBus = FMLCommonHandler.instance().bus();
	eventBus.register(new FalloutKeyBinding());

	//FMLCommonHandler.instance().bus().register(new KeyInputHandler());

	MinecraftForge.EVENT_BUS.register(new GuiRadBar(Minecraft.getMinecraft()));
	RenderingRegistry.registerEntityRenderingHandler(EntityGrenade.class, new RenderSnowball(Minecraft.getMinecraft().getRenderManager(), Fallout.grenade, Minecraft.getMinecraft().getRenderItem()));

	RenderingRegistry.registerEntityRenderingHandler(EntityFeralGhoul.class, new RenderFeralGhoul(Minecraft.getMinecraft().getRenderManager(), new ModelBiped(), 0.5F));
	RenderingRegistry.registerEntityRenderingHandler(EntityGhoulRoamer.class, new RenderGhoulRoamer(Minecraft.getMinecraft().getRenderManager(), new ModelBiped(), 0.5F));
	RenderingRegistry.registerEntityRenderingHandler(EntityGhoulReaver.class, new RenderGhoulReaver(Minecraft.getMinecraft().getRenderManager(), new ModelBiped(), 0.5F));
	RenderingRegistry.registerEntityRenderingHandler(EntityAnt.class, new RenderAnt(Minecraft.getMinecraft().getRenderManager(), new ModelSpider(), 0.5F));

	/**RenderingRegistry.registerEntityRenderingHandler(EntityBullet.class, new RenderSnowball(Fallout.emptySyringe));
	LanguageRegistry.instance().addStringLocalization("entity.bullet.fallout.name", "fallout");

	RenderingRegistry.registerEntityRenderingHandler(EntityMissile.class, new RenderSnowball(Fallout.emptySyringe));
	LanguageRegistry.instance().addStringLocalization("entity.rocket.fallout.name", "fallout");

	RenderingRegistry.registerEntityRenderingHandler(EntityLaser.class, new RenderSnowball(Fallout.emptySyringe));
	LanguageRegistry.instance().addStringLocalization("entity.missile.fallout.name", "fallout");

	RenderingRegistry.registerEntityRenderingHandler(EntityPellet.class, new RenderSnowball(Fallout.emptySyringe));
	LanguageRegistry.instance().addStringLocalization("entity.pellet.fallout.name", "fallout");

	RenderingRegistry.registerEntityRenderingHandler(EntitySpear.class, new RenderSnowball(Items.arrow));
	LanguageRegistry.instance().addStringLocalization("entity.spear.fallout.name", "fallout");

	RenderingRegistry.registerEntityRenderingHandler(EntityPlasma.class, new RenderSnowball(Items.slime_ball));*/
}
}

 

 

FalloutKeyBinding:

package blfngl.fallout.util;

import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import org.lwjgl.input.Keyboard;

import blfngl.fallout.player.FalloutPlayer;

public class FalloutKeyBinding
{
public static int keyReload = Keyboard.KEY_R;

@SideOnly(Side.CLIENT)
public KeyBinding reloadKey = new KeyBinding("Reload", keyReload, "key.categories.fallout");

public FalloutKeyBinding()
{
	ClientRegistry.registerKeyBinding(reloadKey);
}

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void KeyInputEvent(KeyInputEvent event)
{
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;

	if (reloadKey.isKeyDown())
	{
		FalloutPlayer props = FalloutPlayer.get(player);
		props.setReloadingState(1);
		System.out.println(player.getName() + " is reloading!");
	}
}
}

 

 

I also register my client proxy in the event bus within the preInit method of my main file.

 

preInit()

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	System.out.println("Blfngl's Fallout mod loading...");

	FMLCommonHandler.instance().bus().register(new FalloutConfig());
	config = new Configuration(event.getSuggestedConfigurationFile());
	config.load();
	FalloutConfig.syncConfig();
	FalloutConfig.createModInfo(event);

	ChemEffectHandler.init();

	MinecraftForge.EVENT_BUS.register(new FalloutEventHandler());
	MinecraftForge.EVENT_BUS.register(new VanillaBlockDrops());
	FMLCommonHandler.instance().bus().register(new FalloutEventHandler());
	FMLCommonHandler.instance().bus().register(new VanillaBlockDrops());

	FMLCommonHandler.instance().bus().register(new ClientProxy());
	Entities.init();
}

 

Posted

You can ONLY ever access client input (keyboard, mouse, etc.) on the CLIENT side - ANY attempt to do so on the server, i.e. when the world is not remote, will crash your game.

 

This includes things like inline initializations:

@SideOnly(Side.CLIENT)
public KeyBinding reloadKey = new KeyBinding("Reload", keyReload, "key.categories.fallout");

It doesn't matter that you put @SideOnly there, because that can only remove the reference, but you also try to assign it and that part is not removed, thus it crashes.

 

You CAN, however, put the @SideOnly annotation above your entire KeyBinding class, and that's what you should do, as well as make sure you only ever reference it on the client side.

Posted

Found some leftover unused keybinding variables at the top of my main mod file too, removed that and added your fix, problem solved. Thanks!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.