Jump to content

Custom code crashes the game whenever run


ZygZagGaming

Recommended Posts

I have an @SubscribeEvent method that is called whenever the AttackEntityEvent is called. Whenever it is called, the game crashes. Here is the code:

 

@SubscribeEvent
public static void onAttack(AttackEntityEvent event) {
    /*
    if the entity who attacked was a player and was holding a t3 core then it is set to t4
     */

    PlayerEntity player = event.getPlayer();
    int count = player.getHeldItemMainhand().getCount();
    ServerWorld world = (ServerWorld) event.getEntity().world;

    if (event.getPlayer().getHeldItemMainhand().getMaxDamage() >= 15) {
        ItemStack stack = ItemRegistryHandler.T4_CORE.get().getDefaultInstance();
        stack.setCount(1);
        player.setItemStackToSlot(EquipmentSlotType.MAINHAND, stack);
        ItemEntity item = new ItemEntity(EntityType.ITEM, world);
        stack.setCount(count - 1);
        item.setItem(stack);
        world.summonEntity(item);
    }
}
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.