#My game crash when i run my mincraft mod

16 messages · Page 1 of 1 (latest)

uncut prism
#

public class ArnorMod implements ModInitializer {
public static final String MODID = "armorermod";

@Override
public void onInitialize() {

UseEntityCallback.EVENT.register(this::onPlayerInteract);

}

private ActionResult onPlayerInteract(PlayerEntity player, World world, Hand hand, Entity entity, EntityHitResult hitResult) {
if (entity instanceof VillagerEntity) {
VillagerEntity villager = (VillagerEntity) entity;
if (villager.getVillagerData().getProfession() == VillagerProfession.ARMORER) {

    rotatePlayerCamera(player);

    
    boolean hasMoreTrades;
    do {
      hasMoreTrades = false;
      for (TradeOffer trade : villager.getOffers()) {
        ItemStack tradeItem = trade.getSellItem();

        
        if (EnchantmentHelper.hasEnchantments(tradeItem) && trade.getDisplayedFirstBuyItem().getCount() == 1) {
         
          if (player.getInventory().count(Items.EMERALD) >= 1) {
            
            player.getInventory().removeStack(player.getInventory().getSlotWithStack(new ItemStack(Items.EMERALD)), 1);
            player.giveItemStack(tradeItem.copy());
          
            player.dropItem(tradeItem, false);

        
            hasMoreTrades = true;
          }
        }
      }
    } while (hasMoreTrades); 
    
    rotatePlayerCamera(player);
  }
}
return ActionResult.PASS;

}

private void rotatePlayerCamera(PlayerEntity player) {
player.setYaw(player.getYaw() + 180); // چرخش 180 درجه
player.setHeadYaw(player.getHeadYaw() + 180); // چرخش سر بازیکن
}
}

acoustic saffronBOT
#

This post has been reserved for your question.

Hey @uncut prism! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

acoustic saffronBOT
uncut prism
#

Its my mincraft mod code
It suppose to drop all the diamond arrmor that villiger sell for 1 emerald and rotate player 180 degrees when right click on a armorer villiger
And also rotate again when i close the traid
But when i right click on a villager my game crash

rich swan
#
 } while (hasMoreTrades); 

        rotatePlayerCamera(player);
      }
    }
    return ActionResult.PASS;
  }

  private void rotatePlayerCamera(PlayerEntity player) {
    player.setYaw(player.getYaw() + 180); // چرخش 180 درجه
    player.setHeadYaw(player.getHeadYaw() + 180); // چرخش سر بازیکن
  }
#

are you sure this loop isnt crashing the game

uncut prism
rich swan
#

i added thread sleep 1000

#

add it too

#

and try it

#

if you dont crash then that means the problem is with the loop

#

if you crash anyway the problem is somewhere else

uncut prism
#

I'll try it

uncut prism
#

It didn't worked