Jump to content

Recommended Posts

Posted

So I am trying to make an item that saves coordinates when you right click. I think it might have to do with packets, but I am not sure.  When I right click on the ground, I get a crash:

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

Time: 8/24/15 9:21 AM
Description: Ticking memory connection

java.lang.NullPointerException: Ticking memory connection
at io.github.mrnegablox.tecmod.item.GPS.onItemUse(GPS.java:36)
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.tecmod.item.GPS.onItemUse(GPS.java:36)
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@79c04bb1
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.7.0_75, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 268821320 bytes (256 MB) / 444596224 bytes (424 MB) up to 954728448 bytes (910 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	Tec2Mod_NegaBlox{0.1.0} [Tec Mod 2] (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'/247, l='Test', x=-559.12, y=4.00, z=-197.03]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

Here is the code:

 

Main Class:

package io.github.mrnegablox.tecmod;

import io.github.mrnegablox.tecmod.item.ModItems;
import net.minecraft.entity.EntityTracker;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;

@Mod(modid = Tec2Mod.MODID, name = Tec2Mod.MODNAME, version = Tec2Mod.VERSION)
public class Tec2Mod {

    public static final String MODID = "Tec2Mod_NegaBlox";
    public static final String MODNAME = "Tec Mod 2";
    public static final String VERSION = "0.1.0";
        
    @SidedProxy(clientSide = "io.github.mrnegablox.tecmod.ClientProxy", serverSide = "io.github.mrnegablox.tecmod.ServerProxy")
    public static CommonProxy proxy;
    
    //public static SimpleNetworkWrapper network;
    
    @Instance
    public static Tec2Mod instance = new Tec2Mod();
        
     
    @EventHandler
    public void preInit(FMLPreInitializationEvent e) {
    	//network = NetworkRegistry.INSTANCE.newSimpleChannel("TecTalk");
        //network.registerMessage(MyMessage.Handler.class, MyMessage.class, 0, Side.SERVER);
    	ModItems.init();
    }
        
    @EventHandler
    public void init(FMLInitializationEvent e) {

    }
        
    @EventHandler
    public void postInit(FMLPostInitializationEvent e) {
                
    }
}

 

The Problem Item:

package io.github.mrnegablox.tecmod.item;



import io.github.mrnegablox.tecmod.Tec2Mod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;

public class GPS extends Item {

public double savedTargetX = 0;
public double savedTargetY = 0;
public double savedTargetZ = 0;

public NBTTagCompound compound;

public GPS() {
	setMaxStackSize(1);
}

@Override
public boolean onItemUse(ItemStack itemstack, EntityPlayer player,
		World world, int x, int y, int z, int l, float f, float f1, float f2) {
	if(world.isRemote)
		return true;
    	player.addChatComponentMessage(new ChatComponentText("Target saved"));
    	savedTargetX = x + 0.5;
    	savedTargetY = y;
    	savedTargetZ = z + 0.5;
    	compound = itemstack.getTagCompound();
    	compound.setDouble("TargetX", savedTargetX);
    	compound.setDouble("TargetY", savedTargetY);
    	compound.setDouble("TargetZ", savedTargetZ);
    	itemstack.stackTagCompound = compound;
    	player.addChatComponentMessage(new ChatComponentText("X       - " + savedTargetX));
//    	entityplayer.addChatMessage("Y       - " + savedTargetY);
    	player.addChatComponentMessage(new ChatComponentText("Z       - " + savedTargetZ));
//    	entityplayer.addChatMessage("BlockID - " + world.getBlockId(i, j, k));
    	
    	
        return true;
}

@Override
public void onCreated(ItemStack item, World world,
	EntityPlayer player) {
item.stackTagCompound = new NBTTagCompound();


}

}

 

If it is packets, what do I send? a packet that tells Forge that NBT is being edited?

 

BONUS:

I have been trying to figure out how packets work. I have seen things like diesieben's tutorial. But how would I update a server on something like an entities location?

Posted

Does that code really show up in your IDE without a ton of errors reported? 

 

Things to do:

- Go read up on NBTTagCompound.  Search for some tutorials

- Delete all the variables you defined for your item.  They won't work the way you want them to. If you want variables specific to an itemstack in the world, you have to store the variables values in the itemstack NBT Data and then pull them out each time you want to use them.  You can't store in the Item class.  there is only one of those and its not unique for your itemstack in the world.

- 'compound = itemstack.getTagCompound();' is probably giving error.  You need to test if there is a tagcompound first and there probably isn't.  If there isn't add one first.

- 'itemstack.stackTagCompound = compound;' is not how you write the data back. 

Long time Bukkit & Forge Programmer

Happy to try and help

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Make a test with another Launcher like the Curseforge Launcher, MultiMC or AT Launcher
    • can anyone help me i am opening forge and add modpacks and then it says unable to update native luancher and i redownlaod java and the luancher it self?
    • The problem occurs also in 1.20.1 Forge, but with an "Error executing task on client" instead. I have "Sinytra Connector" installed. On 1.21.5 Fabric, there is no problem. When this happens, the chat message before the death screen appears gets sent, with an extra dash added.
    • Well, as usual, it was user error. Naming mismatch in sounds.json.  Please delete this post if you find it necessary. 
    • Hello Forge community.  I'm running into an issue with a mod I'm working on.  To preface, I can call /playsound modId:name music @a and I can hear the sound I registered being played in game. Great!  However, I cannot get it to trigger via my mod code.    Registration: public static final RegistryObject<SoundEvent> A_WORLD_OF_MADNESS = SOUND_EVENTS.register("a_world_of_madness", () -> new SoundEvent(new ResourceLocation("tetheredsouls", "a_world_of_madness")));   Playback: Minecraft mc = Minecraft.getInstance(); if (!(mc.player instanceof LocalPlayer) || mc.level == null) return; LocalPlayer player = (LocalPlayer) mc.player; BlockPos pos = player.blockPosition(); SoundEvent track = ModSounds.A_WORLD_OF_MADNESS.get(); System.out.println(track); System.out.println(pos); System.out.println(player); // play exactly like the tutorial: client-only, at the player's position try { mc.level.playLocalSound( player.getX(), player.getY(), player.getZ(), track, SoundSource.MUSIC, // Or MASTER if needed 1f, 1f, false ); System.out.println("[DEBUG] playSound success: " + track.getLocation()); } catch (Exception e) { System.err.println("[ERROR] Failed to play sound: " + track.getLocation()); e.printStackTrace(); } Sounds.json:   { "theme_of_laura": { "category": "music", "sounds": [ { "name": "tetheredsouls:a_world_of_madness", "stream": true } ] } } Things I have tried: - multiple .ogg files. Short .ogg files (5 seconds, <100KB).  - default minecraft sounds imported from import net.minecraft.sounds.SoundEvents; These work given my code. No idea why these are different.  - playSound() method, as well as several others in past iterations that did not work   I would be forever grateful if somebody could point me in the right direction. I've looked at several mod github repositories and found extremely similar code to what I'm doing. I've also found several threads in this forum that did not solve my issue. I just cannot figure out what I'm doing differently, and why I'm able to queue sounds manually with playsound but the code won't play it (despite confirming the code is being run with the debug statements.)
  • Topics

×
×
  • Create New...

Important Information

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