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);
}
}