Jump to content

[1.10.2] Special effect on button press.


Phonixe

Recommended Posts

Hello, I created a custom chestplate and i'd like to make the chestplate provide a special effect when a certain button is pressed, I'm not sure how could i do this..

 

KeyBindings Class:

package phonixe.phoenixcraft.network;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.client.registry.ClientRegistry;

public class PhoenixCraftKeyBindings {
    public static KeyBinding flyWings;
    public static void init() {
    flyWings = new KeyBinding("key.flyWings", Keyboard.KEY_R, "key.categories.phoenixcraft");
    ClientRegistry.registerKeyBinding(flyWings);
    }
}

 

InputHandler:

package phonixe.phoenixcraft.network;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemArmor;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import phonixe.phoenixcraft.items.RedFirePhoenix_Chestplate;

public class PhoenixCraftKeyInputHandler {
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
	if(PhoenixCraftKeyBindings.flyWings.isPressed()) {
	}
}
}

Link to comment
Share on other sites

There are two things that much be true for your keybind to do anything.

 

1) The key needs to be pressed

2) The player needs to be wearing the armor

3) the server needs to know about it

 

You've got #1 at the moment, now do #2 and #3.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You could also try a method more like this. It works with items, but I don't know about armor.

 

 

@Override

public void onUpdate (ItemStack stack, World world, Entity entity, int par4, boolean par5){

super.onUpdate(stack, world, entity, par4, par5);

{

 

EntityPlayer player = (EntityPlayer) entity;

ItemStack equipped = player.getCurrentEquippedItem();

 

 

 

if (Keyboard.isKeyDown(Keyboard.KEY_F)) {

 

player.supercoolthingyouwantyourarmortodo;

   

 

}

 

Link to comment
Share on other sites

You could also try a method more like this. It works with items, but I don't know about armor.

 

 

@Override

public void onUpdate (ItemStack stack, World world, Entity entity, int par4, boolean par5){

super.onUpdate(stack, world, entity, par4, par5);

{

 

EntityPlayer player = (EntityPlayer) entity;

ItemStack equipped = player.getCurrentEquippedItem();

 

 

 

if (Keyboard.isKeyDown(Keyboard.KEY_F)) {

 

player.supercoolthingyouwantyourarmortodo;

   

 

}

 

 

This will not work on the dedicated server.  The server doesn't necessarily know what a "keyboard" is, much less which player is pressing it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Well here's my current InputHandler, I'm pretty sure i'm messing this up royally as i'm not sure how to do this. Also how could i let the server know of this?

 

package phonixe.phoenixcraft.network;

import javax.annotation.Nullable;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import phonixe.phoenixcraft.init.PhoenixCraftItems;
import phonixe.phoenixcraft.items.RedFirePhoenix_Chestplate;

public class PhoenixCraftKeyInputHandler {
private ItemStack ItemStack;
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
	ItemStack itemstack = this.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
	if(PhoenixCraftKeyBindings.flyWings.isPressed()) {
		if (itemstack.getItem() == PhoenixCraftItems.redfirephoenix_chestplate){

		}
	}
}

public ItemStack getItemStackFromSlot(EntityEquipmentSlot slotIn) {
	return ItemStack;
}

public void setItemStackToSlot(EntityEquipmentSlot slotIn, @Nullable ItemStack stack) {
}
}

Link to comment
Share on other sites

private ItemStack ItemStack;

The fuck?

	public ItemStack getItemStackFromSlot(EntityEquipmentSlot slotIn) {
	return ItemStack;
}

Double da-fuck?

 

Also how could i let the server know of this?

 

The magic of packets.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

When the key is pressed: tell the server

The server then checks if the player is wearing the armor.

And if so, activates the effect.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.