Jump to content

Custom code crashes the game whenever run


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:


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();
        player.setItemStackToSlot(EquipmentSlotType.MAINHAND, stack);
        ItemEntity item = new ItemEntity(EntityType.ITEM, world);
        stack.setCount(count - 1);
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.

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.