Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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()) {
	}
}
}

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.

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;

   

 

}

 

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.

  • Author

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) {
}
}

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.

  • Author

Alright i got the effect to activate when the button is pressed, but i'm still unsure how i could make sure that the player is wearing the chestplate ._.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.