Jump to content

Recommended Posts

Posted (edited)

Hey so I'm new to forge 1.8 mod development and I was having some trouble registering a class with the event bus because for some reason it seems to work differently than 1.12.2. I tried registering my class under FMLInitializationEvent as well as FMLPreInitializationEvent and nothing seemed to work. For some reason, when I get into the game, I'm not able to trigger any actions within the class that I had registered. Here's the code for my main class, as well as the class that I'm trying to register. 

package com.Jewkake.destruct;

import org.apache.logging.log4j.Logger;
import com.Jewkake.destruct.CobbleG;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = main.MODID, name = main.NAME, version = main.VERSION)
public class main 
{
	public static final String MODID = "destruct";
	public static final String NAME = "Destruct";
	public static final String VERSION = "1.0.0";
	public static KeyBinding cobblegen = new KeyBinding("Cobble Generation", 21, "Destruct");
	private static Logger logger;
	
	@EventHandler
	public void preInit(FMLPreInitializationEvent event)
	{
		ClientRegistry.registerKeyBinding(cobblegen);
	}
	
	@EventHandler
	public void init(FMLInitializationEvent event)
	{
		MinecraftForge.EVENT_BUS.register(new CobbleG());
	}
	
	@EventHandler
	public void postInit(FMLPostInitializationEvent event)
	{
		
	}
}
package com.Jewkake.destruct;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.*;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;

public class CobbleG 
{
	private static KeyBinding cb = main.cobblegen;
	private static boolean isRunning = false;
	
	@SubscribeEvent
	public void start(InputEvent.KeyInputEvent event)
	{
		System.out.println("nohere");
		World world = Minecraft.getMinecraft().theWorld;
		if(world!=null)
		{
			if(cb.isPressed())
			{
				if(!isRunning)
				{
					privateChat("Cobble Generation Started");
					isRunning = true;
				}
				else
				{
					privateChat("Cobble Generation Stopped");
					isRunning = false;
				}
			}
		}
	}
	
	@SubscribeEvent
	public void run(ClientTickEvent event)
	{
		System.out.println("overhere");
		EntityPlayer player = Minecraft.getMinecraft().thePlayer;
		Minecraft mc = Minecraft.getMinecraft();
		if(isRunning || !isRunning)
		{
			System.out.println("here");
			player.setVelocity(0.2, 0.0, 0.0);
			player.rotationPitch = -90.0f;
			player.rotationYaw = -90.0f;
			if(mc.objectMouseOver != null)
			{
				if(mc.objectMouseOver.typeOfHit.ordinal() == 0)
				{
					BlockPos blockpos = mc.objectMouseOver.getBlockPos();
					if(mc.theWorld.getBlockState(blockpos).getBlock().getMaterial() != Material.air)
					{
						mc.playerController.func_180511_b(blockpos, mc.objectMouseOver.sideHit);
					}
				}
			}
		}
		
	}
	
	@SubscribeEvent
	public void leftServer(PlayerEvent.PlayerLoggedOutEvent event)
	{
		isRunning = false;
	}
	
	public void privateChat(String message)
	{
		Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(message));
	}
}

 

Edited by outflows
  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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