Крашится майнкрафт из-за события

Версия Minecraft
1.12.2
Написал событие для того, чтобы при добычи руды киркой, зачарованной на "Шелковое касание", выпадал блок руды, а не айтем. В коде события вроде никаких ошибок нет, но клиент крашится после захода в мир. Удалил строчку регистрации события и больше не крашило, значит проблема как раз таки кроется в этом событии.

Как решить эту проблему?

Код:
package com.torx.torxcraftmod.events;

import com.torx.torxcraftmod.registers.TorxBlocksRegister;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class TorxEventsHandler {

    @SubscribeEvent
    public void onBreak(BlockEvent.HarvestDropsEvent e) {
        IBlockState state = e.getState();
        EntityPlayer player = e.getHarvester();
        ItemStack itemmainhand1 = player.getHeldItemMainhand();
 
        if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemmainhand1) > 0) {
     
            if (state.getBlock() == TorxBlocksRegister.RUBY_ORE)
            {
                e.getDrops().clear();
                e.getDrops().add(new ItemStack(TorxBlocksRegister.RUBY_ORE));
            }
     
        }
 
    }
}

Код:
package com.torx.torxcraftmod.proxys;

import com.torx.torxcraftmod.events.TorxEventsHandler;
import com.torx.torxcraftmod.registers.TorxBlocksRegister;
import com.torx.torxcraftmod.registers.TorxFurnaceRegister;
import com.torx.torxcraftmod.registers.TorxItemsRegister;
import com.torx.torxcraftmod.registers.TorxRegisterGeneration;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

public class TorxCommonProxy {

    public void preInit(FMLPreInitializationEvent event)
    {
        TorxBlocksRegister.register();
        TorxItemsRegister.register();
        MinecraftForge.EVENT_BUS.register(new TorxEventsHandler());
    }

    public void init(FMLInitializationEvent event)
    {
        TorxRegisterGeneration.register();
        TorxFurnaceRegister.init();
    }

    public void postInit(FMLPostInitializationEvent event)
    {

    }

}
 
Краш-лог
---- Minecraft Crash Report ----
// This doesn't make any sense!

Time: 10/22/18 2:36 AM
Description: Ticking entity

java.lang.NullPointerException: Ticking entity
at com.torx.torxcraftmod.events.TorxEventsHandler.onBreak(TorxEventsHandler.java:18)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_12_TorxEventsHandler_onBreak_HarvestDropsEvent.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:321)
at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:721)
at net.minecraft.block.BlockCrops.dropBlockAsItemWithChance(BlockCrops.java:209)
at net.minecraft.block.BlockPotato.dropBlockAsItemWithChance(BlockPotato.java:31)
at net.minecraft.block.Block.dropBlockAsItem(Block.java:710)
at net.minecraft.world.World.destroyBlock(World.java:477)
at net.minecraft.entity.ai.EntityAIHarvestFarmland.updateTask(EntityAIHarvestFarmland.java:75)
at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(EntityAITasks.java:114)
at net.minecraft.entity.EntityLiving.updateEntityActionState(EntityLiving.java:843)
at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2582)
at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:647)
at net.minecraft.entity.EntityAgeable.onLivingUpdate(EntityAgeable.java:212)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2398)
at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:346)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2171)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871)
at net.minecraft.world.World.updateEntity(World.java:2130)
at net.minecraft.world.World.updateEntities(World.java:1931)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:842)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
at java.lang.Thread.run(Unknown Source)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
at com.torx.torxcraftmod.events.TorxEventsHandler.onBreak(TorxEventsHandler.java:18)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_12_TorxEventsHandler_onBreak_HarvestDropsEvent.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:321)
at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:721)
at net.minecraft.block.BlockCrops.dropBlockAsItemWithChance(BlockCrops.java:209)
at net.minecraft.block.BlockPotato.dropBlockAsItemWithChance(BlockPotato.java:31)
at net.minecraft.block.Block.dropBlockAsItem(Block.java:710)
at net.minecraft.world.World.destroyBlock(World.java:477)
at net.minecraft.entity.ai.EntityAIHarvestFarmland.updateTask(EntityAIHarvestFarmland.java:75)
at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(EntityAITasks.java:114)
at net.minecraft.entity.EntityLiving.updateEntityActionState(EntityLiving.java:843)
at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2582)
at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:647)
at net.minecraft.entity.EntityAgeable.onLivingUpdate(EntityAgeable.java:212)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2398)
at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:346)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2171)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871)
at net.minecraft.world.World.updateEntity(World.java:2130)

-- Entity being ticked --
Details:
Entity Type: minecraft:villager (net.minecraft.entity.passive.EntityVillager)
Entity ID: 80
Entity Name: Крестьянин
Entity's Exact location: -312.80, 63.94, -190.63
Entity's Block location: World: (-313,63,-191), Chunk: (at 7,3,1 in -20,-12; contains blocks -320,0,-192 to -305,255,-177), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
Entity's Momentum: -0.06, -0.08, 0.02
Entity's Passengers: []
Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:1931)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643)

-- Affected level --
Details:
Level name: Новый мир
All players: 0 total; []
Chunk stats: ServerChunkCache: 625 Drop: 0
Level seed: -1989401099763059530
Level generator: ID 00 - default, ver 1. Features enabled: true
Level generator options:
Level spawn location: World: (-252,64,-192), Chunk: (at 4,4,0 in -16,-12; contains blocks -256,0,-192 to -241,255,-177), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
Level time: 191 game time, 191 day time
Level dimension: 0
Level storage version: 0x04ABD - Anvil
Level weather: Rain time: 135467 (now: false), thunder time: 87267 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:842)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
at java.lang.Thread.run(Unknown Source)

-- System Details --
Details:
Minecraft Version: 1.12.2
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_181, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 308353640 bytes (294 MB) / 936378368 bytes (893 MB) up to 3786407936 bytes (3611 MB)
JVM Flags: 0 total;
IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
FML: MCP 9.42 Powered by Forge 14.23.5.2772 5 mods loaded, 5 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

| State | ID | Version | Source | Signature |
|:--------- |:------------ |:------------ |:-------------------------------- |:--------- |
| UCHIJAAAA | minecraft | 1.12.2 | minecraft.jar | None |
| UCHIJAAAA | mcp | 9.42 | minecraft.jar | None |
| UCHIJAAAA | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.5.2772.jar | None |
| UCHIJAAAA | forge | 14.23.5.2772 | forgeSrc-1.12.2-14.23.5.2772.jar | None |
| UCHIJAAAA | torxcraftmod | 1.0{version} | bin | None |

Loaded coremods (and transformers):
GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
Profiler Position: N/A (disabled)
Player Count: 0 / 8; []
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
Краш-лог:
---- Minecraft Crash Report ----
// This doesn't make any sense!

Time: 10/22/18 2:36 AM
Description: Ticking entity

java.lang.NullPointerException: Ticking entity
	at com.torx.torxcraftmod.events.TorxEventsHandler.onBreak(TorxEventsHandler.java:18)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_12_TorxEventsHandler_onBreak_HarvestDropsEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
	at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:321)
	at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:721)
	at net.minecraft.block.BlockCrops.dropBlockAsItemWithChance(BlockCrops.java:209)
	at net.minecraft.block.BlockPotato.dropBlockAsItemWithChance(BlockPotato.java:31)
	at net.minecraft.block.Block.dropBlockAsItem(Block.java:710)
	at net.minecraft.world.World.destroyBlock(World.java:477)
	at net.minecraft.entity.ai.EntityAIHarvestFarmland.updateTask(EntityAIHarvestFarmland.java:75)
	at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(EntityAITasks.java:114)
	at net.minecraft.entity.EntityLiving.updateEntityActionState(EntityLiving.java:843)
	at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2582)
	at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:647)
	at net.minecraft.entity.EntityAgeable.onLivingUpdate(EntityAgeable.java:212)
	at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2398)
	at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:346)
	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2171)
	at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871)
	at net.minecraft.world.World.updateEntity(World.java:2130)
	at net.minecraft.world.World.updateEntities(World.java:1931)
	at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:842)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
	at java.lang.Thread.run(Unknown Source)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
	at com.torx.torxcraftmod.events.TorxEventsHandler.onBreak(TorxEventsHandler.java:18)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_12_TorxEventsHandler_onBreak_HarvestDropsEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
	at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:321)
	at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:721)
	at net.minecraft.block.BlockCrops.dropBlockAsItemWithChance(BlockCrops.java:209)
	at net.minecraft.block.BlockPotato.dropBlockAsItemWithChance(BlockPotato.java:31)
	at net.minecraft.block.Block.dropBlockAsItem(Block.java:710)
	at net.minecraft.world.World.destroyBlock(World.java:477)
	at net.minecraft.entity.ai.EntityAIHarvestFarmland.updateTask(EntityAIHarvestFarmland.java:75)
	at net.minecraft.entity.ai.EntityAITasks.onUpdateTasks(EntityAITasks.java:114)
	at net.minecraft.entity.EntityLiving.updateEntityActionState(EntityLiving.java:843)
	at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2582)
	at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:647)
	at net.minecraft.entity.EntityAgeable.onLivingUpdate(EntityAgeable.java:212)
	at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2398)
	at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:346)
	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2171)
	at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871)
	at net.minecraft.world.World.updateEntity(World.java:2130)

-- Entity being ticked --
Details:
	Entity Type: minecraft:villager (net.minecraft.entity.passive.EntityVillager)
	Entity ID: 80
	Entity Name: Крестьянин
	Entity's Exact location: -312.80, 63.94, -190.63
	Entity's Block location: World: (-313,63,-191), Chunk: (at 7,3,1 in -20,-12; contains blocks -320,0,-192 to -305,255,-177), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
	Entity's Momentum: -0.06, -0.08, 0.02
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
	at net.minecraft.world.World.updateEntities(World.java:1931)
	at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643)

-- Affected level --
Details:
	Level name: Новый мир
	All players: 0 total; []
	Chunk stats: ServerChunkCache: 625 Drop: 0
	Level seed: -1989401099763059530
	Level generator: ID 00 - default, ver 1. Features enabled: true
	Level generator options: 
	Level spawn location: World: (-252,64,-192), Chunk: (at 4,4,0 in -16,-12; contains blocks -256,0,-192 to -241,255,-177), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
	Level time: 191 game time, 191 day time
	Level dimension: 0
	Level storage version: 0x04ABD - Anvil
	Level weather: Rain time: 135467 (now: false), thunder time: 87267 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:842)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
	at java.lang.Thread.run(Unknown Source)

-- System Details --
Details:
	Minecraft Version: 1.12.2
	Operating System: Windows 7 (amd64) version 6.1
	Java Version: 1.8.0_181, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 308353640 bytes (294 MB) / 936378368 bytes (893 MB) up to 3786407936 bytes (3611 MB)
	JVM Flags: 0 total; 
	IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
	FML: MCP 9.42 Powered by Forge 14.23.5.2772 5 mods loaded, 5 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

	| State     | ID           | Version      | Source                           | Signature |
	|:--------- |:------------ |:------------ |:-------------------------------- |:--------- |
	| UCHIJAAAA | minecraft    | 1.12.2       | minecraft.jar                    | None      |
	| UCHIJAAAA | mcp          | 9.42         | minecraft.jar                    | None      |
	| UCHIJAAAA | FML          | 8.0.99.99    | forgeSrc-1.12.2-14.23.5.2772.jar | None      |
	| UCHIJAAAA | forge        | 14.23.5.2772 | forgeSrc-1.12.2-14.23.5.2772.jar | None      |
	| UCHIJAAAA | torxcraftmod | 1.0{version} | bin                              | None      |

	Loaded coremods (and transformers): 
	GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
	Profiler Position: N/A (disabled)
	Player Count: 0 / 8; []
	Type: Integrated Server (map_client.txt)
	Is Modded: Definitely; Client brand changed to 'fml,forge'
Последнее редактирование:
Решение
Код:
@SubscribeEvent
public void onBreak(BlockEvent.HarvestDropsEvent e) {
    IBlockState state = e.getState();
    ItemStack inMainHand = player.getHeldItemMainhand();

    if (!inMainHand.isEmpty() && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, inMainHand) > 0) {
        if (state.getBlock() == TorxBlocksRegister.RUBY_ORE) {
            e.getDrops().clear();
            e.getDrops().add(new ItemStack(TorxBlocksRegister.RUBY_ORE));
        }
    }
}
И как было ранее сказано @Doc, лучше всё же дроп сделать через свой блок если таковой имеется(а он как раз и имеется). Вот к примеру так:
Java:
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
    return...
3,005
192
592
Если руда своя, нафиг костыли, когда можно в своей руде же и прописать дроп?
 
7,099
324
1,510
3,005
192
592

Icosider

Kotliner
Администратор
3,603
99
664
Код:
@SubscribeEvent
public void onBreak(BlockEvent.HarvestDropsEvent e) {
    IBlockState state = e.getState();
    ItemStack inMainHand = player.getHeldItemMainhand();

    if (!inMainHand.isEmpty() && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, inMainHand) > 0) {
        if (state.getBlock() == TorxBlocksRegister.RUBY_ORE) {
            e.getDrops().clear();
            e.getDrops().add(new ItemStack(TorxBlocksRegister.RUBY_ORE));
        }
    }
}
И как было ранее сказано @Doc, лучше всё же дроп сделать через свой блок если таковой имеется(а он как раз и имеется). Вот к примеру так:
Java:
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
    return Item.getItemFromBlock(TorxBlocksRegister.RUBY_ORE);
}

protected boolean canSilkHarvest() {
    return true;
}
 
Последнее редактирование:
7,099
324
1,510
Сверху