so i'm trying to add a block that will make a mine shaft and take all the ore blocks that it hit and put them in to a chest to be recover.
but the game would crash when the block was placed in to the world. so i put eclipse in to debug mode to fine the sours of the problem
and I pin ponied it to one line of code witch is marked in red. the crash report is at the bottom.
@SubscribeEvent
public void makeMineShaft(BlockEvent.PlaceEvent e)
{
if(e.block instanceof MineShaftTnt)
{
//Super
//Sets the block to air on the x, y, and z coords from where you placed the block
e.world.setBlockToAir(e.x, e.y, e.z);
//Sets the block on the x, y, and z coords starting from where you placed the block
e.world.setBlock(e.x, e.y, e.z, b.cobblestone);
//Sets the block(with set metadata) on the x, y, and z coords from where you placed the block
//This is for birch planks, if you want other planks, search 'Minecraft Block Metadata' in google or find it on the MinecraftWiki
//e.world.setBlock(e.x, e.y, e.z, b.planks, 2, 2);
e.world.setBlock(e.x, e.y, e.z, b.chest);
for(int i = 0; i <3;i++)
{
for(int j =0; j<3;j++)
{
for(int c =0; c<20;c++)
{
if(e.world.getBlock(e.x, e.y, e.z) instanceof BlockOre)
{
e.world.getBlock(e.x, e.y, e.z);
}
}*/
for(int x = 1; x < t.getSizeInventory();i++)//runs though inventory slots
{
if(e.world.getBlock(e.x+i-2, e.y+j, e.z+c) instanceof BlockOre)//test if it an ore block
{
Block b = e.world.getBlock(e.x+i-2, e.y+j, e.z+c);//gets block at x y z
Item it= b.getItemDropped(0, random, 1); //get the Item to be drooped
int q = b.quantityDroppedWithBonus(1, random); //get quantity to be drooped
ItemStack ts = new ItemStack(it, q);
if(!(null == t.getStackInSlot(x)))//if slot is empty
{
///////////// this line crash the game ///////////////////////
t.setInventorySlotContents(x, ts);//sets the Slot Content to item
///////////// this line crash the game ///////////////////////
}else{
if(it == t.getStackInSlot(x).getItem())
{
t.setInventorySlotContents(t.getStackInSlot(x).stackSize+ q, new ItemStack(it, q));//gets number of items and add quantity (q)
}
java.lang.NullPointerException: Ticking memory connection
at com.javackman.DropHandler.makeMineShaft(DropHandler.java:121)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_DropHandler_makeMineShaft_PlaceEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)
at net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(ForgeEventFactory.java:69)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:535)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:128)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:389)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:556)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:60)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:9)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:212)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:165)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:659)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:547)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:111)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at com.javackman.DropHandler.makeMineShaft(DropHandler.java:121)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_DropHandler_makeMineShaft_PlaceEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)
at net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(ForgeEventFactory.java:69)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:535)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:128)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:389)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:556)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:60)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:9)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:212)
-- Ticking connection --
Details:
Connection: [email protected]
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:165)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:659)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:547)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:111)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685)
-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_31, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 654438200 bytes (624 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.85.1291 Minecraft Forge 10.13.2.1291 5 mods loaded, 5 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.10.85.1291} [Forge Mod Loader] (forgeBin-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.13.2.1291} [Minecraft Forge] (forgeBin-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
examplemod{1.0} [Example Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
minermod{0.01} [minermod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player281'/6, l='stone world', x=-13.98, y=225.00, z=277.82]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
but the game would crash when the block was placed in to the world. so i put eclipse in to debug mode to fine the sours of the problem
and I pin ponied it to one line of code witch is marked in red. the crash report is at the bottom.
////////////////////code/////////////////////////
package com.javackman;
import java.util.Random;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.world.BlockEvent;
import com.javackman.blocks.InstantHous;
import com.javackman.blocks.MineShaftTnt;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.Block;
import net.minecraft.block.BlockOre;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.world.World;
public class DropHandler
{
public static Random random;
public static int dropped;
Blocks b;
BlockOre b2;
TileEntityChest t = new TileEntityChest(10);
@SubscribeEvent
public void onEntityDrop(LivingDropsEvent event)
{
random = new Random();
dropped = random.nextInt(2) + 1; //DO NOT CHANGE THIS
if(event.entityLiving instanceof EntityCow)
{
event.entityLiving.entityDropItem(new ItemStack(Items.apple), dropped);
}
}
@SubscribeEvent
public void makeMineShaft(BlockEvent.PlaceEvent e)
{
if(e.block instanceof MineShaftTnt)
{
//Super
//Sets the block to air on the x, y, and z coords from where you placed the block
e.world.setBlockToAir(e.x, e.y, e.z);
//Sets the block on the x, y, and z coords starting from where you placed the block
e.world.setBlock(e.x, e.y, e.z, b.cobblestone);
//Sets the block(with set metadata) on the x, y, and z coords from where you placed the block
//This is for birch planks, if you want other planks, search 'Minecraft Block Metadata' in google or find it on the MinecraftWiki
//e.world.setBlock(e.x, e.y, e.z, b.planks, 2, 2);
e.world.setBlock(e.x, e.y, e.z, b.chest);
for(int i = 0; i <3;i++)
{
for(int j =0; j<3;j++)
{
for(int c =0; c<20;c++)
{
if(e.world.getBlock(e.x, e.y, e.z) instanceof BlockOre)
{
e.world.getBlock(e.x, e.y, e.z);
}
/*if(c%5 == 0 && c != 1 && 0<c)
{
e.world.setBlock(e.x+i-3, e.y, e.z+c,b.fence);
e.world.setBlock(e.x+i-3, e.y+1, e.z+c,b.fence);
e.world.setBlock(e.x+i-1, e.y, e.z+c,b.fence);
e.world.setBlock(e.x+i-1, e.y+1, e.z+c,b.fence);
e.world.setBlock(e.x-2, e.y+2, e.z+c, b.planks, 0, 0);
e.world.setBlock(e.x-3, e.y+2, e.z+c, b.planks, 0, 0);
e.world.setBlock(e.x-4, e.y+2, e.z+c, b.planks, 0, 0);
}*/
for(int x = 1; x < t.getSizeInventory();i++)//runs though inventory slots
{
if(e.world.getBlock(e.x+i-2, e.y+j, e.z+c) instanceof BlockOre)//test if it an ore block
{
Block b = e.world.getBlock(e.x+i-2, e.y+j, e.z+c);//gets block at x y z
Item it= b.getItemDropped(0, random, 1); //get the Item to be drooped
int q = b.quantityDroppedWithBonus(1, random); //get quantity to be drooped
ItemStack ts = new ItemStack(it, q);
if(!(null == t.getStackInSlot(x)))//if slot is empty
{
///////////// this line crash the game ///////////////////////
t.setInventorySlotContents(x, ts);//sets the Slot Content to item
///////////// this line crash the game ///////////////////////
}else{
if(it == t.getStackInSlot(x).getItem())
{
t.setInventorySlotContents(t.getStackInSlot(x).stackSize+ q, new ItemStack(it, q));//gets number of items and add quantity (q)
}
}
}
}
e.world.setBlock(e.x+i-2, e.y+j, e.z+c,b.air);
e.world.setBlock(e.x+i-2, e.y+j, e.z-c,b.air);
e.world.setBlock(e.x+c, e.y+j, e.z+i-2,b.air);
e.world.setBlock(e.x-c, e.y+j, e.z+i-2,b.air);
}
}
}
}
e.world.setTileEntity(e.x, e.y, e.z, t);
/////////////////////////////////////////////////////////////////
if(e.block instanceof InstantHous)
{
for(int i = 0; i <5;i++)
{
for(int j =0; j<4;j++)
{
for(int c =0; c<5;c++)
{
e.world.setBlock(e.x+i, e.y+j, e.z+c,b.planks);
}
}
}
for(int i = 0; i <4;i++)
{
for(int j =0; j<3;j++)
{
for(int c =0; c<4;c++)
{
e.world.setBlock(e.x+i+1, e.y+j+1, e.z+c+1,b.air);
}
}
}
/////////////////////////////chash report////////////////////////////////
---- Minecraft Crash Report ----
// I feel sad now
Time: 20/02/15 8:18 PM
Description: Ticking memory connection
java.lang.NullPointerException: Ticking memory connection
at com.javackman.DropHandler.makeMineShaft(DropHandler.java:121)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_DropHandler_makeMineShaft_PlaceEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)
at net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(ForgeEventFactory.java:69)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:535)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:128)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:389)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:556)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:60)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:9)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:212)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:165)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:659)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:547)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:111)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at com.javackman.DropHandler.makeMineShaft(DropHandler.java:121)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_7_DropHandler_makeMineShaft_PlaceEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)
at net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(ForgeEventFactory.java:69)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:535)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:128)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:389)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:556)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:60)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(SourceFile:9)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:212)
-- Ticking connection --
Details:
Connection: [email protected]
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:165)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:659)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:547)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:111)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685)
-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_31, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 654438200 bytes (624 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.85.1291 Minecraft Forge 10.13.2.1291 5 mods loaded, 5 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.10.85.1291} [Forge Mod Loader] (forgeBin-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.13.2.1291} [Minecraft Forge] (forgeBin-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
examplemod{1.0} [Example Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
minermod{0.01} [minermod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player281'/6, l='stone world', x=-13.98, y=225.00, z=277.82]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
Probably the variable "it" is equal to null.
You need to add a check for it.
I use this code for adding items to player inventory: