Jump to content

Recommended Posts

Posted

I'm trying the spawn in an arrow and this is the error:

 

 

  Reveal hidden contents

 

 

Here is the method:

 

@Override
public void onKeyPress(EntityPlayer player) {
	if(!player.worldObj.isRemote){
		EntityArrow arrow = new EntityArrow(player.worldObj, player, 2);
		player.worldObj.spawnEntityInWorld(arrow);
	}

}

 

This method is called by my KeyEventHandler which provides an EntityPlayerMP for the player. What am I doing wrong?

 

 

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Ok I have a key handler that sends a packet to the server and the server receives that packet and calls the onKeyPress method. This keyPress method is part of the module classes we were talking about earlier

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Ok did some testing it turns out that when I press the key (only once) the method is called a LOT and keeps getting called over and over. What could make this happen?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted
  On 11/17/2015 at 1:36 AM, Asweez said:

Ok did some testing it turns out that when I press the key (only once) the method is called a LOT and keeps getting called over and over. What could make this happen?

Hard to say without seeing your code, but I bet you're doing something like setting a field saying the key was pressed, then sending a packet as long as that is true.

 

What are you using to handle key presses? KeyInputEvent or one of the TickEvents? Show your whole class (or at least every piece of it related to handling keys) and any related classes.

Posted
  On 11/17/2015 at 1:36 AM, Asweez said:

Ok did some testing it turns out that when I press the key (only once) the method is called a LOT and keeps getting called over and over. What could make this happen?

 

Depending on what keyboard event your listening to, you're likely asking

isKeyDown(key)

which will be true for the entire duration that the key is pressed.  Which as the code runs 60+ times a second* and a press lasts a tenth of a second...that's at least 6 calls.

 

*Pretty much as fast as the program runs, not tied to game ticks in any way.

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.

Posted

Code:

package com.apmods.hta.handler;

import com.apmods.hta.key.HTAKeys;
import com.apmods.hta.network.AttackKeyPackage;
import com.apmods.hta.network.HTANetwork;

import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;

public class HTAKeyHandler {
@SubscribeEvent
public void keyDown(KeyInputEvent event){
	if(HTAKeys.attack1.isPressed()){
		if(Minecraft.getMinecraft().inGameHasFocus){
			HTANetwork.net.sendToServer(new AttackKeyPackage.KeyMessage(1));
		}
	}
	else if(HTAKeys.attack2.isPressed()){
		if(Minecraft.getMinecraft().inGameHasFocus){
			HTANetwork.net.sendToServer(new AttackKeyPackage.KeyMessage(2));
		}
	}
}
}

 

And when I press it and let go of the key, it just keeps calling the method

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

KeyInputEvent fires both when a key is pressed and when it is released, AND it fires for every single key on the keyboard, not just ones you may want to listen to.

 

You need to check Keyboard.getEventKey() and compare it to the keyCodes of your KeyBindings, and also check Keyboard.getEventState() which is true when the key is pressed.

Posted

Ok this is really weird. When I press the key, even with your code:

if(Keyboard.getEventKey() == HTAKeys.attack1.getKeyCode() && Keyboard.getEventKeyState()){
		if(Minecraft.getMinecraft().inGameHasFocus){
			HTANetwork.net.sendToServer(new AttackKeyPackage.KeyMessage(1));
		}
	}

 

It will constantly put out "key pressed" in the console, even when I quit the world it keeps going. What is going on?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Posted

Oh wow all it was was that there was a for loop that was making it run multiple times. My bad. Thank you for helping, though.

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hey! I noticed you're trying to register your alexandrite item and possibly set its resource location manually with setId(...). I wanted to help clarify a few things that might simplify your code and avoid errors. ✅ The issue: You're using setId(...) inside the item registration like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties().useItemDescriptionPrefix() .setId(ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(TutorialMod.MOD_ID, "alexandrite"))))); But: Item.Properties does not have a setId(...) method — this line will either fail or do nothing meaningful. useItemDescriptionPrefix() is mostly used for translation keys (like "item.modid.name") but isn't needed unless you have a very specific reason. 🛠 The fix: You only need to register your item like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties())); Forge automatically handles the ResourceLocation (modid:alexandrite) based on the name passed into .register(...), so there’s no need to manually assign it. 📝 For the texture: Make sure you have this file in your resources: src/main/resources/assets/tutorialmod/models/item/alexandrite.json { "parent": "item/generated", "textures": { "layer0": "tutorialmod:item/alexandrite" } } And your texture PNG goes here: src/main/resources/assets/tutorialmod/textures/item/alexandrite.png 🌍 For the name in-game: Add this to your en_us.json under: src/main/resources/assets/tutorialmod/lang/en_us.json { "item.tutorialmod.alexandrite": "Alexandrite" }   Note: if im wrong about the issues you are encountering, i apologize.
    • 🛠️ Fix for Transparent or Clipping Item Render Issues When Held in First Person (Forge 1.20+) Hey everyone! I recently ran into a frustrating bug while making a custom item (a rocket) for my Forge mod, and I’m sharing the fix because it’s a bit obscure — and it worked wonders. 💥 The Problem: My item rendered semi-transparent and see-through — but only in first person. It also clipped through nearby blocks when held, unlike default items like swords or leads. The texture file was confirmed to be fully opaque (alpha 255), so the issue wasn’t the PNG itself. Interestingly, when no texture was present and the default purple-black checkerboard appeared, the clipping issue disappeared. ✅ The Fix: I ended up resolving it by randomly trying something I found on a Forge forum post about block rendering. I added this property to my item's model JSON — even though it's typically only used for blocks: { "parent": "item/generated", "textures": { "layer0": "farbeyond:item/rocket_item" }, "render_type": "minecraft:cutout" } Boom. That single line forced the item to render using a proper opaque (cutout) layer, removing all the unwanted transparency and clipping behavior in first person. 🙌 Credit: I originally found the "render_type" trick mentioned here, in a block rendering context: 👉 https://forums.minecraftforge.net/topic/149644-1201-help-with-transparent-blocks/ Even though it was meant for blocks, I thought, why not try it on an item? And it worked! Big thanks to the poster — this fix wouldn’t have happened without that tip. Hopefully this helps anyone else stuck on a weird rendering bug like I was. This isn’t a common item solution, so feel free to share it further. I’d love to know if it works for you too.
    • Use Java 21 instead of Java 24   Also make a test without modernfix
    • Ive been on this world for 2 days now, my computer blue screens pretty often so maybe that has something to do with it. maybe just incompatible mods like a lot of people so im hoping someone more knowledgeable can help me find what i need to get rid of. thank you! paste bin
    • Should probably say that i am running minecraft 1.21.1 and with quite a lot of mods (many of which im unsure should even be on the server side)
  • Topics

×
×
  • Create New...

Important Information

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