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

I'm trying to make a musket, but while working on the loading logic I ran into some trouble - the item gets used in a loop, making onPlayerStoppedUsing get called with a bad time left in the use. Since I based my code on the Crossbow, I tried to subclass the Crossbow directly to see if I was doing something wrong. But I can't subclass a crossbow and still get the same loading behaviour as a crossbow - here's my code for the subclassed crossbow:

 

package ca.zootron.totalwar.common.item;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.CrossbowItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class MyCrossbow extends CrossbowItem {
    private static final Logger LOGGER = LogManager.getLogger();

    public MyCrossbow(Properties propertiesIn) {
        super(propertiesIn);
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        LOGGER.debug("MyCrossbow#onItemRightClick");
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }
}

 

Why does this not have the same behaviour as a normal crossbow?

38 minutes ago, JHPrime said:

Why does this not have the same behaviour as a normal crossbow?

It does have the same behavior as the normal crossbow, you're just assuming it doesn't because you cannot visually see the change. For that, you would need to add some properties using ItemModelProperties and handle the arm pose within PlayerRenderer using the RenderHandEvent and client setup.

  • Author
On 11/27/2020 at 5:01 PM, poopoodice said:

You also need to override isCrossbow in your item class.

Thanks, that worked!

 

For future askers:

 

The signature to override is public boolean isCrossbow(ItemStack stack)

This needs to be overridden because Minecraft's Item class checks if an itemStack is a crossbow by asking if the stack's Item is the Crossbow.

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.