Jump to content

Recommended Posts

Posted

So I am trying to have an item that can link to a mob and have it go to a set point. But I am getting a null point exception.

 

The Problem Function:

@Override
protected boolean interact(EntityPlayer player) {
if(player.getCurrentEquippedItem().getItem() == ModItems.staff){
	System.out.println("interact called");
	player.getCurrentEquippedItem().stackTagCompound.setInteger("target", this.getEntityId()); // the problem line
}
return super.interact(player);
}

 

Stacktrace:

---- Minecraft Crash Report ----
// But it works on my machine.

Time: 7/6/15 10:46 AM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at io.github.mrnegablox.minefortress.entity.EntityDwarf.interact(EntityDwarf.java:46)
at net.minecraft.entity.EntityLiving.interactFirst(EntityLiving.java:1158)
at net.minecraft.entity.player.EntityPlayer.interactWith(EntityPlayer.java:1267)
at net.minecraft.client.multiplayer.PlayerControllerMP.interactWithEntitySendPacket(PlayerControllerMP.java:472)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1513)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2044)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039)
at net.minecraft.client.Minecraft.run(Minecraft.java:962)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)


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

-- Head --
Stacktrace:
at io.github.mrnegablox.minefortress.entity.EntityDwarf.interact(EntityDwarf.java:46)
at net.minecraft.entity.EntityLiving.interactFirst(EntityLiving.java:1158)
at net.minecraft.entity.player.EntityPlayer.interactWith(EntityPlayer.java:1267)
at net.minecraft.client.multiplayer.PlayerControllerMP.interactWithEntitySendPacket(PlayerControllerMP.java:472)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1513)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['LoztInSpace'/215, l='MpServer', x=-758.65, y=5.62, z=510.90]]
Chunk stats: MultiplayerChunkCache: 345, 345
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: World: (-780,4,518), Chunk: (at 4,0,6 in -49,32; contains blocks -784,0,512 to -769,255,527), Region: (-2,1; contains chunks -64,32 to -33,63, blocks -1024,0,512 to -513,255,1023)
Level time: 6032 game time, 6032 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 73 total; [EntitySlime['Slime'/136, l='MpServer', x=-755.80, y=4.48, z=472.35], EntitySlime['Slime'/137, l='MpServer', x=-747.34, y=4.00, z=476.06], EntitySlime['Slime'/138, l='MpServer', x=-747.92, y=4.00, z=489.25], EntitySlime['Slime'/139, l='MpServer', x=-752.61, y=4.09, z=509.45], EntitySlime['Slime'/140, l='MpServer', x=-742.22, y=4.00, z=514.50], EntitySlime['Slime'/141, l='MpServer', x=-750.26, y=4.18, z=518.54], EntitySlime['Slime'/142, l='MpServer', x=-741.32, y=4.18, z=561.28], EntitySlime['Slime'/143, l='MpServer', x=-753.02, y=4.00, z=591.46], EntitySlime['Slime'/147, l='MpServer', x=-726.62, y=4.00, z=490.68], EntitySlime['Slime'/148, l='MpServer', x=-730.53, y=4.65, z=533.54], EntitySlime['Slime'/149, l='MpServer', x=-727.70, y=4.65, z=548.05], EntityPig['Pig'/159, l='MpServer', x=-706.88, y=4.00, z=435.72], EntitySlime['Slime'/160, l='MpServer', x=-715.63, y=4.00, z=493.47], EntitySlime['Slime'/161, l='MpServer', x=-716.50, y=4.00, z=587.31], EntityPig['Pig'/168, l='MpServer', x=-693.94, y=4.00, z=431.88], EntityHorse['Horse'/169, l='MpServer', x=-695.44, y=4.00, z=431.28], EntityPig['Pig'/170, l='MpServer', x=-692.44, y=4.00, z=442.09], EntityChicken['Chicken'/42, l='MpServer', x=-833.59, y=4.00, z=490.41], EntityHorse['Horse'/171, l='MpServer', x=-697.28, y=4.00, z=442.50], EntitySheep['Sheep'/43, l='MpServer', x=-836.78, y=4.00, z=503.19], EntityChicken['Chicken'/172, l='MpServer', x=-694.56, y=4.00, z=437.53], EntityCow['Cow'/173, l='MpServer', x=-691.69, y=4.00, z=437.47], EntitySlime['Slime'/174, l='MpServer', x=-702.70, y=4.65, z=513.45], EntitySlime['Slime'/46, l='MpServer', x=-834.52, y=4.00, z=519.15], EntitySlime['Slime'/175, l='MpServer', x=-683.35, y=4.00, z=538.66], EntitySlime['Slime'/176, l='MpServer', x=-700.00, y=4.65, z=539.35], EntityCow['Cow'/177, l='MpServer', x=-698.19, y=4.00, z=571.81], EntityCow['Cow'/178, l='MpServer', x=-698.16, y=4.00, z=587.59], EntityCow['Cow'/179, l='MpServer', x=-703.50, y=4.00, z=579.50], EntitySheep['Sheep'/51, l='MpServer', x=-837.44, y=4.00, z=583.19], EntitySheep['Sheep'/181, l='MpServer', x=-689.78, y=4.00, z=580.09], EntityChicken['Chicken'/59, l='MpServer', x=-832.75, y=4.00, z=522.19], EntitySlime['Slime'/60, l='MpServer', x=-825.01, y=4.00, z=516.41], EntityCow['Cow'/188, l='MpServer', x=-679.81, y=4.00, z=440.75], EntitySheep['Sheep'/189, l='MpServer', x=-685.81, y=4.00, z=439.88], EntitySlime['Slime'/190, l='MpServer', x=-681.09, y=4.00, z=534.96], EntitySlime['Slime'/63, l='MpServer', x=-814.56, y=4.00, z=494.94], EntityChicken['Chicken'/191, l='MpServer', x=-684.59, y=4.00, z=577.63], EntitySlime['Slime'/64, l='MpServer', x=-808.65, y=4.69, z=522.21], EntitySlime['Slime'/65, l='MpServer', x=-800.55, y=4.83, z=540.08], EntitySlime['Slime'/66, l='MpServer', x=-810.15, y=4.84, z=531.74], EntitySlime['Slime'/67, l='MpServer', x=-809.93, y=4.00, z=544.55], EntitySlime['Slime'/72, l='MpServer', x=-796.09, y=4.00, z=435.30], EntitySlime['Slime'/73, l='MpServer', x=-783.09, y=4.00, z=479.22], EntitySlime['Slime'/74, l='MpServer', x=-789.99, y=4.00, z=485.29], EntitySlime['Slime'/75, l='MpServer', x=-797.61, y=4.00, z=513.83], EntitySlime['Slime'/76, l='MpServer', x=-793.55, y=4.40, z=506.94], EntitySlime['Slime'/77, l='MpServer', x=-780.92, y=4.00, z=539.67], EntityHorse['Horse'/78, l='MpServer', x=-787.56, y=4.00, z=539.72], EntityCow['Cow'/79, l='MpServer', x=-784.50, y=4.00, z=551.56], EntityHorse['Horse'/80, l='MpServer', x=-789.78, y=4.00, z=558.06], EntitySlime['Slime'/81, l='MpServer', x=-787.12, y=4.00, z=572.23], EntitySheep['Sheep'/82, l='MpServer', x=-791.59, y=4.00, z=574.09], EntityCow['Cow'/83, l='MpServer', x=-797.78, y=4.00, z=566.61], EntityCow['Cow'/84, l='MpServer', x=-787.81, y=4.00, z=583.13], EntityCow['Cow'/85, l='MpServer', x=-789.88, y=4.00, z=579.81], EntitySlime['Slime'/94, l='MpServer', x=-779.70, y=4.18, z=481.58], EntitySheep['Sheep'/95, l='MpServer', x=-782.50, y=4.00, z=559.78], EntitySheep['Sheep'/96, l='MpServer', x=-773.91, y=4.00, z=568.84], EntityHorse['Horse'/97, l='MpServer', x=-776.78, y=4.00, z=560.22], EntitySlime['Slime'/98, l='MpServer', x=-787.23, y=4.92, z=578.27], EntitySlime['Slime'/114, l='MpServer', x=-756.06, y=4.00, z=462.41], EntitySlime['Slime'/4466, l='MpServer', x=-824.01, y=4.48, z=518.11], EntitySlime['Slime'/115, l='MpServer', x=-766.59, y=4.00, z=470.09], EntityClientPlayerMP['LoztInSpace'/215, l='MpServer', x=-758.65, y=5.62, z=510.90], EntitySlime['Slime'/116, l='MpServer', x=-765.06, y=4.48, z=489.04], EntitySlime['Slime'/117, l='MpServer', x=-767.45, y=4.69, z=498.91], EntityDwarf['entity.Dwarf.name'/118, l='MpServer', x=-758.84, y=4.00, z=512.41], EntitySlime['Slime'/119, l='MpServer', x=-754.84, y=4.00, z=538.69], EntitySheep['Sheep'/120, l='MpServer', x=-763.19, y=4.00, z=544.06], EntitySlime['Slime'/121, l='MpServer', x=-758.10, y=4.69, z=556.86], EntitySlime['Slime'/122, l='MpServer', x=-767.68, y=4.69, z=583.42], EntitySlime['Slime'/123, l='MpServer', x=-769.72, y=4.92, z=585.73]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566)
at net.minecraft.client.Minecraft.run(Minecraft.java:991)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 184130008 bytes (175 MB) / 828899328 bytes (790 MB) up to 1903689728 bytes (1815 MB)
JVM Flags: 0 total; 
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.99.99 Minecraft Forge 10.13.4.1448 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
UCHIJAAAA	mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) 
UCHIJAAAA	Forge{10.13.4.1448} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) 
UCHIJAAAA	minefortress{1.0.0} [Mine Fortress] (bin) 
UCHIJAAAA	examplemod{1.0} [Example Mod] (bin) 
GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.4.0 NVIDIA 344.60' Renderer: 'GeForce GT 740/PCIe/SSE2'
Launched Version: 1.7.10
LWJGL: 2.9.1
OpenGL: GeForce GT 740/PCIe/SSE2 GL version 4.4.0 NVIDIA 344.60, NVIDIA Corporation
GL Caps: Using GL 1.3 multitexturing.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Anisotropic filtering is supported and maximum anisotropy is 16.
Shaders are available because OpenGL 2.1 is supported.

Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Anisotropic Filtering: Off (1)

 

Thank you in advance

Posted

Hi

As @diesieben07 said, check against null values. EX:

if(player.getCurrentEquippedItem != null)
{
    //do something
}

if(stack.getTagCompound() != null) 
{
    //do something
}

 

To set a new NBTTagCompound, do this:

public void example(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
    if(par1ItemStack.getTagCompound() == null) 
    {
        par1ItemStack.setTagCompound(new NBTTagCompound());
    }
    else
    {
        //do NBT stuff here (getting and setting)
    }
}

//An easier and slicker way of getting an NBT integer, can also be converted to return strings
public int getNBTInteger(ItemStack par1ItemStack, String par2String)
{
    return par1ItemStack.getTagCompound != null ? par1ItemStack.getTagCompound().getInteger(par2String) : null;
}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

in the case of your code change to

 

@Override
protected boolean interact(EntityPlayer player) {
        ItemStack cei=player.getCurrentEquippedItem();
if(cei !=null && cei.getItem() == ModItems.staff){
	System.out.println("interact called");
                if (cei.stackTagCompound == null){
                    cei.setTagCompound(new NBTTagCompound());
                }
	cei.stackTagCompound.setInteger("target", this.getEntityId()); // the problem line
}
return super.interact(player);
}

 

though as diesieben07 said this.getEntityId() will change when the entity unloads

 

Posted

Okay, so I set two longs in the NBT. setting the nbt initally worked. I then had it spit out the UUID, but the server and client bring up different UUID's. I get a Null Pointer Exception when it reads the NBT.

 

Stacktrace:

---- Minecraft Crash Report ----
// I just don't know what went wrong 

Time: 7/7/15 6:40 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at java.security.MessageDigest.update(Unknown Source)
at java.security.MessageDigest.digest(Unknown Source)
at java.util.UUID.nameUUIDFromBytes(Unknown Source)
at io.github.mrnegablox.minefortress.item.ItemStaff.onItemUse(ItemStaff.java:38)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:143)
at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:403)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1529)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2044)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039)
at net.minecraft.client.Minecraft.run(Minecraft.java:962)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)


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

-- Head --
Stacktrace:
at java.security.MessageDigest.update(Unknown Source)
at java.security.MessageDigest.digest(Unknown Source)
at java.util.UUID.nameUUIDFromBytes(Unknown Source)
at io.github.mrnegablox.minefortress.item.ItemStaff.onItemUse(ItemStaff.java:38)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:143)
at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:403)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1529)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['LoztInSpace'/218, l='MpServer', x=-820.85, y=5.62, z=503.85]]
Chunk stats: MultiplayerChunkCache: 625, 625
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: World: (-780,4,518), Chunk: (at 4,0,6 in -49,32; contains blocks -784,0,512 to -769,255,527), Region: (-2,1; contains chunks -64,32 to -33,63, blocks -1024,0,512 to -513,255,1023)
Level time: 35909 game time, 10691 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 75 total; [EntitySlime['Slime'/128, l='MpServer', x=-768.10, y=4.00, z=448.14], EntityCow['Cow'/129, l='MpServer', x=-780.81, y=4.00, z=561.59], EntityCow['Cow'/130, l='MpServer', x=-783.56, y=4.00, z=571.97], EntityClientPlayerMP['LoztInSpace'/218, l='MpServer', x=-820.85, y=5.62, z=503.85], EntitySlime['Slime'/9, l='MpServer', x=-884.17, y=4.61, z=584.41], EntitySlime['Slime'/14, l='MpServer', x=-896.84, y=4.55, z=447.81], EntitySlime['Slime'/143, l='MpServer', x=-745.84, y=4.00, z=454.55], EntitySheep['Sheep'/15, l='MpServer', x=-889.09, y=4.00, z=518.06], EntitySlime['Slime'/144, l='MpServer', x=-741.77, y=4.47, z=516.92], EntitySheep['Sheep'/145, l='MpServer', x=-767.88, y=4.00, z=538.94], EntitySlime['Slime'/146, l='MpServer', x=-746.93, y=4.00, z=580.51], EntityChicken['Chicken'/24, l='MpServer', x=-868.41, y=4.00, z=465.59], EntitySlime['Slime'/25, l='MpServer', x=-882.32, y=4.61, z=482.45], EntityChicken['Chicken'/26, l='MpServer', x=-867.63, y=4.00, z=482.47], EntitySheep['Sheep'/27, l='MpServer', x=-871.81, y=4.00, z=486.31], EntitySlime['Slime'/155, l='MpServer', x=-759.65, y=4.55, z=496.37], EntitySheep['Sheep'/28, l='MpServer', x=-873.53, y=4.00, z=483.56], EntitySlime['Slime'/29, l='MpServer', x=-885.44, y=4.00, z=503.31], EntitySlime['Slime'/157, l='MpServer', x=-748.16, y=4.00, z=541.44], EntitySlime['Slime'/30, l='MpServer', x=-880.90, y=4.00, z=505.72], EntitySlime['Slime'/44446, l='MpServer', x=-857.55, y=4.47, z=483.05], EntitySheep['Sheep'/31, l='MpServer', x=-865.78, y=4.00, z=514.56], EntitySlime['Slime'/32, l='MpServer', x=-876.26, y=4.00, z=539.52], EntitySlime['Slime'/33, l='MpServer', x=-885.09, y=4.47, z=555.53], EntitySlime['Slime'/34, l='MpServer', x=-875.49, y=4.00, z=556.46], EntitySlime['Slime'/35, l='MpServer', x=-893.59, y=4.58, z=545.21], EntitySlime['Slime'/37, l='MpServer', x=-864.38, y=4.00, z=582.33], EntitySlime['Slime'/49, l='MpServer', x=-870.76, y=4.61, z=455.34], EntitySlime['Slime'/50, l='MpServer', x=-871.98, y=4.00, z=462.59], EntityChicken['Chicken'/51, l='MpServer', x=-868.41, y=4.00, z=479.41], EntitySlime['Slime'/52, l='MpServer', x=-858.38, y=4.00, z=450.13], EntitySlime['Slime'/53, l='MpServer', x=-874.44, y=4.00, z=472.53], EntitySheep['Sheep'/54, l='MpServer', x=-861.50, y=4.00, z=501.19], EntityChicken['Chicken'/55, l='MpServer', x=-849.89, y=4.00, z=505.79], EntitySheep['Sheep'/56, l='MpServer', x=-856.44, y=4.00, z=559.47], EntitySlime['Slime'/57, l='MpServer', x=-864.37, y=4.18, z=565.79], EntitySlime['Slime'/34107, l='MpServer', x=-797.18, y=4.00, z=448.70], EntitySlime['Slime'/73, l='MpServer', x=-822.23, y=4.00, z=434.95], EntitySlime['Slime'/74, l='MpServer', x=-835.73, y=4.47, z=432.81], EntitySlime['Slime'/75, l='MpServer', x=-819.62, y=4.00, z=441.92], EntitySlime['Slime'/76, l='MpServer', x=-848.45, y=4.00, z=444.19], EntitySheep['Sheep'/77, l='MpServer', x=-846.69, y=4.00, z=469.22], EntitySlime['Slime'/13645, l='MpServer', x=-842.40, y=4.00, z=433.16], EntitySlime['Slime'/78, l='MpServer', x=-830.63, y=4.00, z=499.38], EntitySlime['Slime'/79, l='MpServer', x=-832.00, y=4.55, z=511.67], EntitySheep['Sheep'/80, l='MpServer', x=-833.25, y=4.00, z=575.38], EntitySlime['Slime'/81, l='MpServer', x=-853.10, y=4.00, z=583.15], EntitySlime['Slime'/44118, l='MpServer', x=-837.49, y=4.00, z=578.34], EntitySheep['Sheep'/87, l='MpServer', x=-819.09, y=4.00, z=450.19], EntitySlime['Slime'/88, l='MpServer', x=-832.28, y=4.00, z=480.47], EntitySlime['Slime'/89, l='MpServer', x=-803.22, y=4.00, z=523.38], EntityDwarf['entity.Dwarf.name'/90, l='MpServer', x=-815.97, y=4.00, z=510.72], EntityHorse['Horse'/91, l='MpServer', x=-831.84, y=4.00, z=509.75], EntitySlime['Slime'/92, l='MpServer', x=-812.72, y=4.00, z=562.47], EntitySheep['Sheep'/93, l='MpServer', x=-828.94, y=4.00, z=564.03], EntitySpider['Spider'/98, l='MpServer', x=-804.03, y=4.00, z=448.50], EntitySlime['Slime'/99, l='MpServer', x=-807.26, y=4.00, z=475.97], EntitySlime['Slime'/100, l='MpServer', x=-811.69, y=4.00, z=476.22], EntitySlime['Slime'/101, l='MpServer', x=-797.12, y=4.00, z=484.73], EntitySlime['Slime'/102, l='MpServer', x=-800.07, y=4.00, z=497.50], EntitySheep['Sheep'/103, l='MpServer', x=-807.75, y=4.00, z=558.41], EntityCow['Cow'/104, l='MpServer', x=-809.41, y=4.00, z=582.78], EntitySlime['Slime'/82536, l='MpServer', x=-806.13, y=4.00, z=459.25], EntitySlime['Slime'/108, l='MpServer', x=-814.57, y=4.00, z=479.49], EntitySlime['Slime'/109, l='MpServer', x=-773.00, y=4.58, z=489.27], EntitySlime['Slime'/110, l='MpServer', x=-772.88, y=4.00, z=514.28], EntityHorse['Horse'/111, l='MpServer', x=-793.00, y=4.00, z=552.88], EntityCow['Cow'/112, l='MpServer', x=-786.97, y=4.00, z=574.03], EntitySlime['Slime'/15729, l='MpServer', x=-835.16, y=4.47, z=429.13], EntityHorse['Horse'/114, l='MpServer', x=-787.19, y=4.00, z=576.91], EntitySlime['Slime'/87543, l='MpServer', x=-835.90, y=4.00, z=457.10], EntityChicken['Chicken'/122, l='MpServer', x=-776.44, y=4.00, z=428.44], EntityChicken['Chicken'/123, l='MpServer', x=-776.22, y=4.00, z=430.81], EntityCow['Cow'/125, l='MpServer', x=-771.84, y=4.00, z=434.25], EntitySlime['Slime'/127, l='MpServer', x=-763.95, y=4.00, z=445.58]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566)
at net.minecraft.client.Minecraft.run(Minecraft.java:991)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 487448120 bytes (464 MB) / 781189120 bytes (745 MB) up to 1903689728 bytes (1815 MB)
JVM Flags: 0 total; 
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.99.99 Minecraft Forge 10.13.4.1448 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
UCHIJAAAA	mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) 
UCHIJAAAA	Forge{10.13.4.1448} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) 
UCHIJAAAA	minefortress{1.0.0} [Mine Fortress] (bin) 
UCHIJAAAA	examplemod{1.0} [Example Mod] (bin) 
GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.4.0 NVIDIA 344.60' Renderer: 'GeForce GT 740/PCIe/SSE2'
Launched Version: 1.7.10
LWJGL: 2.9.1
OpenGL: GeForce GT 740/PCIe/SSE2 GL version 4.4.0 NVIDIA 344.60, NVIDIA Corporation
GL Caps: Using GL 1.3 multitexturing.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Anisotropic filtering is supported and maximum anisotropy is 16.
Shaders are available because OpenGL 2.1 is supported.

Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Anisotropic Filtering: Off (1)

 

Code


//How the NBT is set
       @Override
public boolean interact(EntityPlayer player) {
	System.out.println("interact start");
        ItemStack cei=player.getCurrentEquippedItem();
	if(cei !=null && cei.getItem() == ModItems.staff){
		System.out.println("interact called");
                if (cei.stackTagCompound == null){
                    cei.setTagCompound(new NBTTagCompound());
                }
		cei.stackTagCompound.setLong("targetUUIDLeast", this.getPersistentID().getLeastSignificantBits());
		cei.stackTagCompound.setLong("targetUUIDMost", this.getPersistentID().getMostSignificantBits());
		System.out.println(this.getPersistentID().toString());
	}
	return super.interact(player);
}

//When it is read
@Override
public void onCreated(ItemStack item, World world, EntityPlayer player) {
	item.stackTagCompound = new NBTTagCompound();
	item.stackTagCompound.setString("targetUUID", null);
	item.stackTagCompound.setLong("targetLeast", 0);
	item.stackTagCompound.setLong("targetMost", 0);
}

@Override
public boolean onItemUse(ItemStack Item, EntityPlayer Player, World world,
		int x, int y, int z, int side, float hitx, float hity, float hitz) {
	System.out.println("ItemUseCalled");
	// if(Player.getCurrentEquippedItem() == new ItemStack(ModItems.staff)
	// && Player.getCurrentEquippedItem() != null) {
	//try{
	UUID targetUUID = UUID.nameUUIDFromBytes(LongstoBytes(
			Item.stackTagCompound.getLong("targetLeast"),
			Item.stackTagCompound.getLong("targetMost")));

	if (targetUUID != null) {
		Entity target = getEntityfromUUID(targetUUID, world);
		/**
		 * if(target instanceof EntityDwarf){ ((EntityDwarf)
		 * target).setTargetPos(x, y+1, z);
		 * 
		 * ((EntityDwarf) target).setgoingToWaypoint(true); }
		 **/
		if (target != null) {
			((EntityDwarf) target).getNavigator().tryMoveToXYZ(x, y + 1, z,
					1.3D);
			if (((EntityDwarf) target).getNavigator().tryMoveToXYZ(x,
					y + 1, z, 1.3D)) {
				System.out.println("can go");
			}
		}
		// }

	}
	/*} catch(Exception e) {
		System.out.println("Houston, We have a problem");
		return false;
	}*/
	return false;
}

private byte[] LongstoBytes(long long1, long long2) {
	if (long1 != 0 && long2 != 0) {
		ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
		buffer.putLong(long2);
		buffer.putLong(long1);
		return buffer.array();
	}
	return null;

Posted

Both UUID and disk-NBT is server sided.

 

Client only has a mirror of server's NBT - yes, you can read it and it will most likely be equal to server's one, but still - it's the server that loads/saves it.

Any action that is NOT "read-only" MUST happen on server. Client should never change nbt data - only read it.

 

Yes, UUIDs are ONLY server-sided. Client will always generate different one that is not compatybile with server's one.

 

To run code on server logical side use if(!world.isRemote)

1.7.10 is no longer supported by forge, you are on your own.

  • 3 months later...
Posted

Ok, so I am still having problems with this... so now when it tries to read an NBt long, it keeps getting a Null Pointer Exception even when I check if it is null.

 

---- Minecraft Crash Report ----
// Why is it breaking 

Time: 10/24/15 6:52 PM
Description: Ticking memory connection

java.lang.NullPointerException: Ticking memory connection
at io.github.mrnegablox.minefortress.item.ItemStaff.onItemUse(ItemStaff.java:44)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:507)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:142)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:422)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)


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

-- Head --
Stacktrace:
at io.github.mrnegablox.minefortress.item.ItemStaff.onItemUse(ItemStaff.java:44)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:507)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:142)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:422)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)

-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@4cc5d6fa
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 354749696 bytes (338 MB) / 586678272 bytes (559 MB) up to 1903689728 bytes (1815 MB)
JVM Flags: 0 total; 
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.99.99 Minecraft Forge 10.13.4.1448 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
UCHIJAAAA	mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) 
UCHIJAAAA	Forge{10.13.4.1448} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar) 
UCHIJAAAA	minefortress{1.0.0} [Mine Fortress] (bin) 
UCHIJAAAA	examplemod{1.0} [Example Mod] (bin) 
GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
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['LoztInSpace'/237, l='New World', x=-824.86, y=6.00, z=501.28]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

@Override
public boolean onItemUse(ItemStack Item, EntityPlayer Player, World world,
		int x, int y, int z, int side, float hitx, float hity, float hitz) {
	System.out.println("ItemUseCalled");
	// if(Player.getCurrentEquippedItem() == new ItemStack(ModItems.staff)
	// && Player.getCurrentEquippedItem() != null) {
	// try{
	Long least = (long) 0;
	Long most = (long) 0;
	if (!world.isRemote) {
		try{
		least = Item.stackTagCompound.getLong("targetLeast");
		most = Item.stackTagCompound.getLong("targetMost");
		} catch(NullPointerException npe){
			Console.out().println(npe);;
		}
	}
	UUID targetUUID = null;
	if (least != (long) 0 && most != (long) 0) {
		targetUUID = UUID.nameUUIDFromBytes(LongstoBytes(least, most));
	} else {
		targetUUID = null;
	}

	Entity target = null;
	if (targetUUID != null) {

		try {
			target = getEntityfromUUID(targetUUID, world);
		} catch (Exception ex) {
			return false;
		}
	}
	/**
	 * if(target instanceof EntityDwarf){ ((EntityDwarf)
	 * target).setTargetPos(x, y+1, z);
	 * 
	 * ((EntityDwarf) target).setgoingToWaypoint(true); }
	 **/
	if (target != null) {
		((EntityDwarf) target).getNavigator().tryMoveToXYZ(x, y + 1, z,
				1.3D);
		if (((EntityDwarf) target).getNavigator().tryMoveToXYZ(x, y + 1, z,
				1.3D)) {
			System.out.println("can go");
		}
	}
	// }

	/*
	 * } catch(Exception e) {
	 * System.out.println("Houston, We have a problem"); return false; }
	 */
	return false;
}

@Override
public void onCreated(ItemStack item, World world, EntityPlayer player) {
	if (!world.isRemote) {
		if (item.stackTagCompound == null)
			item.stackTagCompound = new NBTTagCompound();
		item.stackTagCompound.setString("targetUUID", null);
		item.stackTagCompound.setLong("targetLeast", 0);
		item.stackTagCompound.setLong("targetMost", 0);
	}
}


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.