Jump to content

Recommended Posts

Posted

how would I detect what a player is holding in an if statement when a block is right-clicked?  I have this code but it keeps crashing with unexpected error:

 

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
  {
  if(playerIn.getHeldItem().getItem() instanceof serverKey){
	  System.out.println("true");
	  TileEntity tileentity = worldIn.getTileEntity(pos);
	  return (tileentity instanceof tileEntityServer) ? ((tileEntityServer)tileentity).getCommandBlockLogic().func_175574_a(playerIn) : false;  //tileEntityServer
  }else{
	  System.out.println("false");
	  return false;
  }
  }

I'm working on something big!  As long as there arent alot of big issues... [D

Posted

You should always post the error output when asking a question. The error usually says exactly what's wrong.

 

Usually the problem with checking items is that it is possible that the itemstack is null. So when you call .getItem() you'll get a null pointer exception. So generally you should first check if itemstack is not null and then do the rest of your code.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

ok, i added a check to see if its not equal to null before continuing, but why would it be null?

 

EDIT : it still crashes on the new if statement, but now with nullPointerException

 

here is the error:

[20:55:30] [Client thread/FATAL]: Unreported exception thrown!

java.lang.NullPointerException

at com.UltraTechX.serverroom.serverBlock.onBlockActivated(serverBlock.java:71) ~[serverBlock.class:?]

at net.minecraft.client.multiplayer.PlayerControllerMP.func_178890_a(PlayerControllerMP.java:416) ~[PlayerControllerMP.class:?]

at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1571) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:2131) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1087) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]

at GradleStart.main(Unknown Source) [start/:?]

[20:55:30] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:663]: ---- Minecraft Crash Report ----

// You're mean.

 

Time: 10/12/15 8:55 PM

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at com.UltraTechX.serverroom.serverBlock.onBlockActivated(serverBlock.java:71)

at net.minecraft.client.multiplayer.PlayerControllerMP.func_178890_a(PlayerControllerMP.java:416)

at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1571)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:2131)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1087)

at net.minecraft.client.Minecraft.run(Minecraft.java:376)

at net.minecraft.client.main.Main.main(Main.java:117)

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 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.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 com.UltraTechX.serverroom.serverBlock.onBlockActivated(serverBlock.java:71)

at net.minecraft.client.multiplayer.PlayerControllerMP.func_178890_a(PlayerControllerMP.java:416)

at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1571)

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityPlayerSP['Player334'/94, l='MpServer', x=-1270.85, y=4.00, z=-501.69]]

Chunk stats: MultiplayerChunkCache: 440, 440

Level seed: 0

Level generator: ID 01 - flat, ver 0. Features enabled: false

Level generator options:

Level spawn location: -1281.00,4.00,-515.00 - World: (-1281,4,-515), Chunk: (at 15,0,13 in -81,-33; contains blocks -1296,0,-528 to -1281,255,-513), Region: (-3,-2; contains chunks -96,-64 to -65,-33, blocks -1536,0,-1024 to -1025,255,-513)

Level time: 27364 game time, 8852 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: 48 total; [EntityPig['Pig'/64, l='MpServer', x=-1221.19, y=4.00, z=-484.38], EntitySheep['Sheep'/65, l='MpServer', x=-1218.81, y=4.00, z=-455.38], EntitySheep['Sheep'/66, l='MpServer', x=-1222.50, y=4.00, z=-433.22], EntityChicken['Chicken'/69, l='MpServer', x=-1199.51, y=4.00, z=-552.24], EntityChicken['Chicken'/70, l='MpServer', x=-1203.69, y=4.00, z=-555.19], EntityChicken['Chicken'/72, l='MpServer', x=-1201.47, y=4.00, z=-555.41], EntityCow['Cow'/73, l='MpServer', x=-1207.78, y=4.00, z=-512.34], EntityPig['Pig'/74, l='MpServer', x=-1201.06, y=4.00, z=-503.66], EntityPig['Pig'/75, l='MpServer', x=-1214.38, y=4.00, z=-475.78], EntityRabbit['Rabbit'/11, l='MpServer', x=-1346.31, y=4.14, z=-531.60], EntityPig['Pig'/12, l='MpServer', x=-1349.84, y=4.00, z=-526.41], EntityChicken['Chicken'/77, l='MpServer', x=-1206.41, y=4.00, z=-441.41], EntityPig['Pig'/18, l='MpServer', x=-1334.19, y=4.00, z=-562.69], EntityPig['Pig'/82, l='MpServer', x=-1192.81, y=4.00, z=-453.06], EntityPig['Pig'/19, l='MpServer', x=-1330.34, y=4.00, z=-569.41], EntityChicken['Chicken'/83, l='MpServer', x=-1199.91, y=4.00, z=-432.97], EntitySheep['Sheep'/20, l='MpServer', x=-1338.84, y=4.00, z=-554.22], EntitySheep['Sheep'/21, l='MpServer', x=-1336.50, y=4.00, z=-529.57], EntityRabbit['Rabbit'/22, l='MpServer', x=-1341.53, y=4.00, z=-521.66], EntityRabbit['Rabbit'/27, l='MpServer', x=-1323.06, y=4.00, z=-571.31], EntitySheep['Sheep'/28, l='MpServer', x=-1313.88, y=4.00, z=-526.19], EntitySheep['Sheep'/29, l='MpServer', x=-1323.50, y=4.00, z=-486.06], EntitySheep['Sheep'/30, l='MpServer', x=-1313.31, y=4.00, z=-483.84], EntityPig['Pig'/31, l='MpServer', x=-1323.09, y=4.00, z=-483.97], EntityPig['Pig'/32, l='MpServer', x=-1312.91, y=4.00, z=-485.34], EntityPig['Pig'/35, l='MpServer', x=-1311.84, y=4.00, z=-571.25], EntityPlayerSP['Player334'/94, l='MpServer', x=-1270.85, y=4.00, z=-501.69], EntityRabbit['Rabbit'/36, l='MpServer', x=-1307.81, y=4.00, z=-558.59], EntityRabbit['Rabbit'/37, l='MpServer', x=-1296.72, y=4.00, z=-553.25], EntityRabbit['Rabbit'/38, l='MpServer', x=-1303.69, y=4.00, z=-452.38], EntitySheep['Sheep'/39, l='MpServer', x=-1298.91, y=4.00, z=-453.44], EntityPig['Pig'/43, l='MpServer', x=-1291.41, y=4.00, z=-531.91], EntityRabbit['Rabbit'/44, l='MpServer', x=-1289.94, y=4.00, z=-519.09], EntityRabbit['Rabbit'/45, l='MpServer', x=-1292.94, y=4.25, z=-477.64], EntityRabbit['Rabbit'/46, l='MpServer', x=-1284.88, y=4.00, z=-458.06], EntityRabbit['Rabbit'/49, l='MpServer', x=-1249.69, y=4.00, z=-456.88], EntityRabbit['Rabbit'/50, l='MpServer', x=-1263.38, y=4.00, z=-447.69], EntityRabbit['Rabbit'/51, l='MpServer', x=-1261.09, y=4.00, z=-437.19], EntityHorse['Horse'/53, l='MpServer', x=-1234.19, y=4.00, z=-481.41], EntityHorse['Horse'/54, l='MpServer', x=-1238.47, y=4.00, z=-470.25], EntityHorse['Horse'/55, l='MpServer', x=-1236.50, y=4.00, z=-468.25], EntityCow['Cow'/56, l='MpServer', x=-1245.16, y=4.00, z=-471.94], EntityHorse['Horse'/57, l='MpServer', x=-1239.50, y=4.00, z=-459.81], EntitySheep['Sheep'/58, l='MpServer', x=-1244.75, y=4.00, z=-444.56], EntityCow['Cow'/60, l='MpServer', x=-1227.16, y=4.00, z=-529.69], EntityCow['Cow'/61, l='MpServer', x=-1223.15, y=4.00, z=-517.53], EntityCow['Cow'/62, l='MpServer', x=-1225.69, y=4.00, z=-520.56], EntityPig['Pig'/63, l='MpServer', x=-1226.44, y=4.00, z=-480.63]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:392)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2614)

at net.minecraft.client.Minecraft.run(Minecraft.java:405)

at net.minecraft.client.main.Main.main(Main.java:117)

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 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.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

-- System Details --

Details:

Minecraft Version: 1.8

Operating System: Windows 7 (amd64) version 6.1

Java Version: 1.8.0_31, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 810855056 bytes (773 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.3.1520 4 mods loaded, 4 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{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.3.1520.jar)

UCHIJAAAA Forge{11.14.3.1520} [Minecraft Forge] (forgeSrc-1.8-11.14.3.1520.jar)

UCHIJAAAA serverroom{0.1.0} [server Room Assets] (bin)

Loaded coremods (and transformers):

GL info: ' Vendor: 'ATI Technologies Inc.' Version: '3.3.11672 Compatibility Profile Context' Renderer: 'ATI Radeon HD 4250'

Launched Version: 1.8

LWJGL: 2.9.1

OpenGL: ATI Radeon HD 4250 GL version 3.3.11672 Compatibility Profile Context, ATI Technologies Inc.

GL Caps: Using GL 1.3 multitexturing.

Using GL 1.3 texture combiners.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Shaders are available because OpenGL 2.1 is supported.

VBOs are available because OpenGL 1.5 is supported.

 

Using VBOs: No

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)

[20:55:30] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:663]: #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\UltraTechX\Desktop\serverroom\run\.\crash-reports\crash-2015-10-12_20.55.30-client.txt

AL lib: (EE) alc_cleanup: 1 device not closed

I'm working on something big!  As long as there arent alot of big issues... [D

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.