My game crash when i run my mincraft mod

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); // چرخش سر بازیکن } }
8 Replies
JavaBot
JavaBot4w ago
This post has been reserved for your question.
Hey @Dangerboy25! 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.
JavaBot
JavaBot4w ago
Please format your code to make it more readable. For java, it should look like this:
​`​`​`​java
public void foo() {

}
​`​`​`​
​`​`​`​java
public void foo() {

}
​`​`​`​
Dangerboy25
Dangerboy25OP4w ago
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
ayylmao123xdd
ayylmao123xdd4w ago
} while (hasMoreTrades);

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

private void rotatePlayerCamera(PlayerEntity player) {
player.setYaw(player.getYaw() + 180); // چرخش 180 درجه
player.setHeadYaw(player.getHeadYaw() + 180); // چرخش سر بازیکن
}
} 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
Dangerboy25
Dangerboy25OP4w ago
Maybe how to fix it
ayylmao123xdd
ayylmao123xdd4w ago
do {
Thread.sleep(1000);
hasMoreTrades = false;
for (TradeOffer trade : villager.getOffers()) {
do {
Thread.sleep(1000);
hasMoreTrades = false;
for (TradeOffer trade : villager.getOffers()) {
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
Dangerboy25
Dangerboy25OP4w ago
I'll try it It didn't worked
JavaBot
JavaBot3w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?