Jump to content

Crossbow-like loading running in loop


JHPrime

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.

×
×
  • Create New...

Important Information

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