Jump to content

[1.5.2] [Forge] TickHandler any example on how to do that??


lorizz

Recommended Posts

Hi guys, I wanted to make a special armour that it charge and then ask you to press F for release the Fury Mode.

I created it in my ItemClass, it worked good but the problem is, the server is not registering this.

So I asked to my friend that can make mod and said to me:

"You need to register a new TickHandler for this thing" but the problem is, I can't figure out :S

 

I tried doing this:

 

TickHandler class:

 

package mods.exoworld.handler;

import java.util.EnumSet;

import mods.exoworld.Main;
import mods.exoworld.item.ExoTNTHelmet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ExoServerTickHandler implements ITickHandler {

public ExoTNTHelmet event;
public World world;
public EntityPlayer player;

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub

}

public void onTickArmor(EntityPlayer player, World world,
		ItemStack itemStack, ExoTNTHelmet event) {
	ItemStack helmet = player.inventory.armorItemInSlot(3);
	ItemStack chestplate = player.inventory.armorItemInSlot(2);
	ItemStack leggings = player.inventory.armorItemInSlot(1);
	ItemStack boots = player.inventory.armorItemInSlot(0);
	if (helmet.itemID == Main.ExoTNTHelmet.itemID
			&& chestplate.itemID == Main.ExoTNTChestplate.itemID
			&& leggings.itemID == Main.ExoTNTLeggings.itemID
			&& boots.itemID == Main.ExoTNTBoots.itemID) {
		event.counter += 0.021F;
		System.out.println(event.counter);
		if(event.counter > 50F) {
			event.powerupIsAvailable = true;
		}
		if (event.powerupIsAvailable == true) {
			event.counter -= 5F;
			if (event.counter < 0F) {
				event.counter = 0F;
			}
		}
	}
}

public void onPowerupActivated() {
	while (event.counter < 0F) {
		// I want that every 5 ticks the function do this code below
		if (event.powerupIsAvailable == true)
			world.createExplosion(null, player.posX + 5, player.posY,
					player.posZ, 5.0F, false);
		world.createExplosion(null, player.posX - 5, player.posY,
				player.posZ, 5.0F, false);
		world.createExplosion(null, player.posX, player.posY,
				player.posZ + 5, 5.0F, false);
		world.createExplosion(null, player.posX, player.posY,
				player.posZ - 5, 5.0F, false);
		event.powerupIsAvailable = false;
	}
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
	// TODO Auto-generated method stub

}

@Override
public EnumSet<TickType> ticks() {
	// TODO Auto-generated method stub
	return EnumSet.of(TickType.CLIENT, TickType.RENDER);
}

@Override
public String getLabel() {
	// TODO Auto-generated method stub
	return null;
}

}

 

My KeyHandler code:

package mods.exoworld.handler;

import java.util.EnumSet;

import mods.exoworld.item.ExoTNTHelmet;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;

public class ExoKeyHandler extends KeyHandler {
public ExoServerTickHandler tickHandler;
public static KeyBinding armorPowerup = new KeyBinding(
		"Armor Powerup", Keyboard.KEY_F);
public static KeyBinding[] arrayOfKeys = new KeyBinding[] { armorPowerup };
public static boolean[] areRepeating = new boolean[] { false };

public ExoKeyHandler() {
	super(arrayOfKeys, areRepeating);
}

@Override
public String getLabel() {
	return "ExoWorld's KeyHandler";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb,
		boolean tickEnd, boolean isRepeat) {
	if (tickEnd) {
		if (kb.keyCode == armorPowerup.keyCode) {
			tickHandler.onPowerupActivated();
		}
	}
}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {
}

@Override
public EnumSet<TickType> ticks() {
	return EnumSet.of(TickType.CLIENT);
}
}

 

P.S.: Never used TickHandler in my life, no tutorials, no examples = never use this sh@t again

Link to comment
Share on other sites

Nooooo you don't say? xD:

*pretend i didnt see anything.............*

 

in your frirst post you talk about registerng with the server yet your tickhabdler return a tick type of client and render, 2 type which dont exists server side.

 

you want this tick handler server side or client side ?

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Nooooo you don't say? xD:

*pretend i didnt see anything.............*

 

in your frirst post you talk about registerng with the server yet your tickhabdler return a tick type of client and render, 2 type which dont exists server side.

 

you want this tick handler server side or client side ?

Bold word are just wtf? xD

 

Anyway Server side

Link to comment
Share on other sites

typing answer on a phone, im sure you can still read "first" "registering" "tickhandler"

 

return a tick type of server then, because server side doesnt call tickhandler of type client and render

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

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.