Jump to content

Recommended Posts

Posted

For some reason it returns a null pointer when I try retrieving data from the data watcher using the ID of 19.

 

Code:

package poop.handler;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemFood;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
import poop.Poop;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class ServerEventHandlerP {
@SubscribeEvent
public void playerConstruct(EntityEvent.EntityConstructing event) {
	if(!event.entity.worldObj.isRemote) {
		Entity entity = event.entity;
		if(entity instanceof EntityPlayer) {
			NBTTagCompound nbt = entity.getEntityData();
			if(!nbt.hasKey("Food Eaten")) {
				nbt.setInteger("Food Eaten", 0);
			}
			entity.getDataWatcher().addObject(19, Integer.valueOf(nbt.getInteger("Food Eaten")));
		}
	}
}

@SubscribeEvent
public void foodEaten(PlayerUseItemEvent.Finish event) {
	if(!event.entityPlayer.worldObj.isRemote) {
		if(event.item.getItem() instanceof ItemFood) {
			System.err.println("FOOD EATEN");
			NBTTagCompound nbt = event.entityPlayer.getEntityData();
			nbt.setInteger("Food Eaten", nbt.getInteger("Food Eaten") + ((ItemFood) event.item.getItem()).func_150905_g(event.item));
			event.entityPlayer.getDataWatcher().addObject(19, Integer.valueOf(nbt.getInteger("Food Eaten")));
		}
	}
}

@SubscribeEvent
public void bowlUsed(PlayerInteractEvent event) {
	if(event.action == Action.RIGHT_CLICK_AIR) {
		EntityPlayer player = event.entityPlayer;
		if(player.getHeldItem().getItem() == Items.bowl) {
			System.err.println("BOWL USED");
			if(player.getDataWatcher().getWatchableObjectInt(19) >=  { //Crash
				player.openGui(Poop.instance, 0, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
				if(!event.entityPlayer.worldObj.isRemote)
					ServerTickHandlerP.addTimer(player);
			} else {
				player.addChatComponentMessage(new ChatComponentText("You haven't eaten enough to food!"));
			}
		}
	}
}
}

Kain

Posted

Forgot the crash report:

---- Minecraft Crash Report ----
// Oops.

Time: 4/10/14 5:36 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at net.minecraft.entity.DataWatcher.getWatchableObjectInt(DataWatcher.java:98)
at poop.handler.ServerEventHandlerP.bowlUsed(ServerEventHandlerP.java:49)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_8_ServerEventHandlerP_bowlUsed_PlayerInteractEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122)
at net.minecraftforge.event.ForgeEventFactory.onPlayerInteract(ForgeEventFactory.java:57)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1525)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2011)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:996)
at net.minecraft.client.Minecraft.run(Minecraft.java:912)
at net.minecraft.client.main.Main.main(Main.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)


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

-- Head --
Stacktrace:
at net.minecraft.entity.DataWatcher.getWatchableObjectInt(DataWatcher.java:98)
at poop.handler.ServerEventHandlerP.bowlUsed(ServerEventHandlerP.java:49)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_8_ServerEventHandlerP_bowlUsed_PlayerInteractEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122)
at net.minecraftforge.event.ForgeEventFactory.onPlayerInteract(ForgeEventFactory.java:57)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1525)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player270'/210, l='MpServer', x=-244.73, y=71.62, z=235.97]]
Chunk stats: MultiplayerChunkCache: 255, 255
Level seed: 0
Level generator: ID 00 - default, ver 1. Features enabled: false
Level generator options: 
Level spawn location: World: (-256,64,244), Chunk: (at 0,4,4 in -16,15; contains blocks -256,0,240 to -241,255,255), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
Level time: 676 game time, 676 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: 107 total; [EntityBat['Bat'/1360, l='MpServer', x=-290.25, y=15.78, z=219.59], EntityBat['Bat'/1659, l='MpServer', x=-284.75, y=34.10, z=188.75], EntityBat['Bat'/1658, l='MpServer', x=-284.75, y=25.84, z=193.25], EntityCaveBatRF['Cave Bat'/269, l='MpServer', x=-287.50, y=37.00, z=189.50], EntityCaveBatRF['Cave Bat'/314, l='MpServer', x=-169.50, y=32.00, z=253.50], EntityCaveBatRF['Cave Bat'/319, l='MpServer', x=-175.50, y=21.00, z=262.50], EntityCaveBatRF['Cave Bat'/318, l='MpServer', x=-178.50, y=21.00, z=261.50], EntityCaveBatRF['Cave Bat'/2491, l='MpServer', x=-240.50, y=30.00, z=290.50], EntityCaveBatRF['Cave Bat'/529, l='MpServer', x=-322.50, y=54.00, z=178.50], EntityCaveBatRF['Cave Bat'/1570, l='MpServer', x=-263.50, y=42.00, z=315.50], EntityCreeper['Creeper'/622, l='MpServer', x=-286.50, y=41.00, z=296.50], EntityFireCreeper['Fire Creeper'/623, l='MpServer', x=-292.50, y=53.00, z=189.50], EntityCreeper['Creeper'/621, l='MpServer', x=-284.59, y=44.00, z=291.00], EntityFireCreeper['Fire Creeper'/624, l='MpServer', x=-292.50, y=53.00, z=186.50], EntityCaveBatRF['Cave Bat'/634, l='MpServer', x=-299.50, y=56.00, z=235.50], EntityBat['Bat'/2514, l='MpServer', x=-167.15, y=30.82, z=245.66], EntityChicken['Chicken'/102, l='MpServer', x=-297.56, y=64.00, z=241.41], EntityChicken['Chicken'/100, l='MpServer', x=-300.50, y=64.00, z=235.50], EntityChicken['Chicken'/101, l='MpServer', x=-298.50, y=64.00, z=236.50], EntityChicken['Chicken'/99, l='MpServer', x=-298.47, y=65.00, z=225.56], EntityFireCreeper['Fire Creeper'/368, l='MpServer', x=-276.50, y=46.00, z=290.50], EntityBat['Bat'/2538, l='MpServer', x=-289.64, y=31.00, z=196.93], EntityChicken['Chicken'/110, l='MpServer', x=-286.50, y=64.00, z=246.50], EntityChicken['Chicken'/111, l='MpServer', x=-295.50, y=63.00, z=310.50], EntityChicken['Chicken'/108, l='MpServer', x=-282.59, y=64.00, z=244.53], EntityBat['Bat'/2534, l='MpServer', x=-172.48, y=59.09, z=164.63], EntityChicken['Chicken'/109, l='MpServer', x=-290.59, y=67.00, z=249.41], EntityChicken['Chicken'/107, l='MpServer', x=-289.75, y=70.00, z=252.64], EntityMinecartChest['entity.MinecartChest.name'/119, l='MpServer', x=-250.50, y=33.50, z=317.50], EntityChicken['Chicken'/118, l='MpServer', x=-251.50, y=68.00, z=301.50], EntityCaveBatRF['Cave Bat'/1567, l='MpServer', x=-296.50, y=54.00, z=233.50], EntityChicken['Chicken'/117, l='MpServer', x=-251.50, y=68.00, z=301.50], EntityCaveBatRF['Cave Bat'/2284, l='MpServer', x=-318.50, y=51.00, z=212.50], EntityChicken['Chicken'/116, l='MpServer', x=-250.50, y=68.00, z=301.50], EntityCaveBatRF['Cave Bat'/1324, l='MpServer', x=-318.50, y=55.00, z=211.50], EntityChicken['Chicken'/115, l='MpServer', x=-248.50, y=77.00, z=302.50], EntityCaveBatRF['Cave Bat'/2282, l='MpServer', x=-314.50, y=51.00, z=210.50], EntityChicken['Chicken'/114, l='MpServer', x=-293.50, y=64.00, z=310.50], EntityCaveBatRF['Cave Bat'/1325, l='MpServer', x=-247.50, y=14.00, z=240.50], EntityCaveBatRF['Cave Bat'/2281, l='MpServer', x=-316.50, y=51.00, z=211.50], EntityChicken['Chicken'/113, l='MpServer', x=-294.50, y=63.00, z=310.50], EntityChicken['Chicken'/112, l='MpServer', x=-293.50, y=64.00, z=310.50], EntityCaveBatRF['Cave Bat'/2279, l='MpServer', x=-310.50, y=51.00, z=211.50], EntityBat['Bat'/1559, l='MpServer', x=-289.91, y=29.10, z=171.22], EntityPig['Pig'/125, l='MpServer', x=-233.50, y=67.00, z=161.50], EntityPig['Pig'/124, l='MpServer', x=-233.81, y=71.00, z=164.50], EntityPig['Pig'/123, l='MpServer', x=-236.94, y=71.00, z=165.03], EntityPig['Pig'/122, l='MpServer', x=-232.47, y=71.00, z=164.50], EntitySkeleton['Skeleton'/607, l='MpServer', x=-320.44, y=30.00, z=181.94], EntityCaveBatRF['Cave Bat'/1500, l='MpServer', x=-292.50, y=58.00, z=234.50], EntityCaveBatRF['Cave Bat'/1501, l='MpServer', x=-280.50, y=58.00, z=229.50], EntityPig['Pig'/152, l='MpServer', x=-187.50, y=73.00, z=214.50], EntityBat['Bat'/1478, l='MpServer', x=-190.26, y=41.10, z=309.55], EntityPig['Pig'/153, l='MpServer', x=-176.97, y=72.00, z=202.94], EntityCaveBatRF['Cave Bat'/2321, l='MpServer', x=-191.50, y=12.00, z=236.50], EntityBat['Bat'/1477, l='MpServer', x=-206.75, y=39.64, z=305.50], EntityPig['Pig'/154, l='MpServer', x=-185.50, y=64.00, z=273.50], EntityPig['Pig'/155, l='MpServer', x=-185.50, y=64.00, z=275.50], EntityPig['Pig'/156, l='MpServer', x=-187.50, y=64.00, z=274.50], EntityPig['Pig'/157, l='MpServer', x=-188.50, y=64.00, z=272.50], EntityCreeper['Creeper'/939, l='MpServer', x=-202.50, y=39.00, z=313.50], EntityPig['Pig'/158, l='MpServer', x=-174.34, y=72.00, z=203.13], EntityCreeper['Creeper'/938, l='MpServer', x=-206.50, y=39.00, z=314.50], EntityPig['Pig'/159, l='MpServer', x=-174.19, y=71.00, z=206.22], EntityDirtCreeper['Dirt Creeper'/933, l='MpServer', x=-188.50, y=39.00, z=314.50], EntityDirtCreeper['Dirt Creeper'/932, l='MpServer', x=-191.50, y=39.00, z=312.50], EntityFireCreeper['Fire Creeper'/692, l='MpServer', x=-198.97, y=15.00, z=289.50], EntityIceCreeper['Ice Creeper'/690, l='MpServer', x=-192.50, y=15.00, z=288.50], EntityDirtCreeper['Dirt Creeper'/691, l='MpServer', x=-197.50, y=15.00, z=289.50], EntityPig['Pig'/150, l='MpServer', x=-184.50, y=75.00, z=213.50], EntityPig['Pig'/151, l='MpServer', x=-187.50, y=73.00, z=214.50], EntityBat['Bat'/2336, l='MpServer', x=-316.25, y=23.70, z=234.31], EntityCaveBatRF['Cave Bat'/1525, l='MpServer', x=-178.50, y=24.00, z=245.50], EntityPig['Pig'/175, l='MpServer', x=-167.50, y=70.00, z=184.50], EntityPig['Pig'/163, l='MpServer', x=-174.19, y=69.00, z=235.50], EntityPig['Pig'/162, l='MpServer', x=-175.78, y=69.00, z=235.50], EntityPig['Pig'/161, l='MpServer', x=-173.03, y=72.00, z=202.50], EntityPig['Pig'/160, l='MpServer', x=-172.50, y=71.00, z=202.50], EntityPig['Pig'/165, l='MpServer', x=-178.50, y=69.00, z=236.50], EntityPig['Pig'/164, l='MpServer', x=-175.50, y=69.00, z=232.50], EntityCreeper['Creeper'/660, l='MpServer', x=-238.50, y=30.00, z=298.50], EntityPig['Pig'/176, l='MpServer', x=-167.50, y=70.00, z=186.50], EntityCreeper['Creeper'/658, l='MpServer', x=-240.50, y=30.00, z=297.50], EntityCreeper['Creeper'/659, l='MpServer', x=-238.84, y=30.00, z=296.84], EntitySnowCreeper['Snow Creeper'/1156, l='MpServer', x=-308.50, y=22.00, z=241.50], EntityCaveBatRF['Cave Bat'/1434, l='MpServer', x=-293.50, y=55.00, z=226.50], EntityCaveBatRF['Cave Bat'/1435, l='MpServer', x=-296.50, y=55.00, z=227.50], EntityBat['Bat'/1437, l='MpServer', x=-275.67, y=55.02, z=228.66], EntityIceCreeper['Ice Creeper'/1415, l='MpServer', x=-198.50, y=48.00, z=295.50], EntityIceCreeper['Ice Creeper'/1414, l='MpServer', x=-196.50, y=48.00, z=295.50], EntityCaveBatRF['Cave Bat'/2124, l='MpServer', x=-323.50, y=36.00, z=159.50], EntitySnowCreeper['Snow Creeper'/1416, l='MpServer', x=-316.50, y=27.00, z=222.50], EntityBat['Bat'/2120, l='MpServer', x=-199.75, y=32.10, z=314.75], EntityCaveBatRF['Cave Bat'/978, l='MpServer', x=-294.50, y=25.00, z=185.50], EntityIceCreeper['Ice Creeper'/500, l='MpServer', x=-286.50, y=51.00, z=262.50], EntityCaveBatRF['Cave Bat'/1465, l='MpServer', x=-315.50, y=12.00, z=247.50], EntityIceCreeper['Ice Creeper'/501, l='MpServer', x=-285.50, y=51.00, z=266.50], EntityIceCreeper['Ice Creeper'/502, l='MpServer', x=-284.50, y=51.00, z=263.50], EntityCaveBatRF['Cave Bat'/982, l='MpServer', x=-323.50, y=27.00, z=219.50], EntityCaveBatRF['Cave Bat'/710, l='MpServer', x=-180.50, y=41.00, z=246.50], EntityCaveBatRF['Cave Bat'/730, l='MpServer', x=-279.50, y=56.00, z=238.50], EntityCaveBatRF['Cave Bat'/1921, l='MpServer', x=-230.50, y=36.00, z=306.50], EntityClientPlayerMP['Player270'/210, l='MpServer', x=-244.73, y=71.62, z=235.97], EntityBat['Bat'/723, l='MpServer', x=-221.25, y=40.10, z=309.75], EntityCaveBatRF['Cave Bat'/724, l='MpServer', x=-224.50, y=39.00, z=316.50], EntityCaveBatRF['Cave Bat'/726, l='MpServer', x=-313.50, y=44.00, z=200.50], EntityCaveBatRF['Cave Bat'/482, l='MpServer', x=-292.50, y=30.00, z=196.50]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:412)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2517)
at net.minecraft.client.Minecraft.run(Minecraft.java:941)
at net.minecraft.client.main.Main.main(Main.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

-- System Details --
Details:
Minecraft Version: 1.7.2
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_51, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 712513128 bytes (679 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 10003 (560168 bytes; 0 MB) allocated, 2 (112 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
FML: MCP v9.01-pre FML v7.2.137.1055 Minecraft Forge 10.12.0.1055 11 mods loaded, 11 mods active
mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.2.137.1055} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.0.1055.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.12.0.1055} [Minecraft Forge] (forgeSrc-1.7.2-10.12.0.1055.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
deathchest{1.0} [Death Chest] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
enderStorage{1.0} [Ender Storage] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
increasedHealth{1.0} [increased Health] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
moretools{1.0} [More Tools] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
poop{1.0} [The Excrement Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
realmoffera{Indev 1} [Realm of Fera] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
variedcreepers{1.0} [Varied Creepers] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Launched Version: 1.6
LWJGL: 2.9.0
OpenGL: GeForce GT 520/PCIe/SSE2 GL version 4.3.0, NVIDIA Corporation
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: 2152 (120512 bytes; 0 MB) allocated, 17 (952 bytes; 0 MB) used
Anisotropic Filtering: Off (1)

Kain

Posted

1. player.getHeldItem() can return null so check for that or it will crash there, too!

2. There's no dataWatcher object with ID 19 within the EntityPlayer. What are you trying to check exactly?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Ok, I'll do that.

 

In my first event (entity constructing) I add it.

 

I'm keeping count of how many food bars the player has eaten. Like when the player eats steak, it adds 8.

 

I'm trying to avoid using packets to sync the data.

Kain

Posted

Ok, I'll do that.

 

In my first event (entity constructing) I add it.

 

I'm keeping count of how many food bars the player has eaten. Like when the player eats steak, it adds 8.

 

I'm trying to avoid using packets to sync the data.

 

Can I see that code of your event? (also where you register it)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

The entity constructing event is in the code I already posted.

 

Here's my registering code:

package poop;

import net.minecraftforge.common.MinecraftForge;
import poop.handler.GuiHandlerP;
import poop.handler.ServerEventHandlerP;
import poop.handler.ServerTickHandlerP;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.NetworkRegistry;

public class ServerProxyP {
public void initServer() {
	MinecraftForge.EVENT_BUS.register(new ServerEventHandlerP());
	FMLCommonHandler.instance().bus().register(new ServerTickHandlerP());
	NetworkRegistry.INSTANCE.registerGuiHandler(Poop.instance, new GuiHandlerP());
}

public void initClient() {
}
}

Kain

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.