Jump to content

[1.10.2] Registering Tile Entities with IDs


kriNon

Recommended Posts

Hey all,

I am working on making a mod that adds inter-server item teleporters based off of asiekierka's endernet mod for 1.6.4. This is my first mod and I am not very experienced with modding or java, although I do have some experience with programming. I have been making slow but steady progress.

 

Each TileEntityEnderTransmitter that is placed in the world has a "private int ea" which defaults to zero. This is meant to be the network id of the individual tile entity, so that when people want to teleport an item they are able to select which EnderReceiver to transmit to by entering the correct network id into the gui of the EnderTransmitter. As such every EnderReceiver and EnderTransmitter is meant to have its own individual network id.

 

To try to understand how to do this I had a look at the github page for EnderNet2, asie's unfinished 1.7.10 update to his endernet mod.

 

What I have done is I have added this EnderRegistry class:

package kriNon.endernet.lib;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.HashSet;

import kriNon.endernet.Endernet;

public class EnderRegistry {
class RegistryInformation {
	HashSet<Integer> addresses;
	int maxAddress;

	public void init() {
		addresses = new HashSet<Integer>();
		maxAddress = 0;
	}

	public void updateAddresses() {
		if(addresses.contains(maxAddress)) {
			// New address added, look up
			while(addresses.contains(maxAddress)) maxAddress++;
		} else {
			// Old address removed, look down
			while(!addresses.contains(maxAddress)) maxAddress--;
			maxAddress++;
		}
	}
}

public static EnderRegistry instance;

private RegistryInformation r;
private final HashMap<Integer, Object> objects = new HashMap<Integer, Object>();
private final File file;

public EnderRegistry(File file) {
	this.file = file;
	try {
		r = (RegistryInformation)(Endernet.gson.fromJson(new FileReader(file), RegistryInformation.class));
	} catch(FileNotFoundException e) {
		r = new RegistryInformation();
		r.init();
	}
}

public int register(Object o) {
	r.updateAddresses();
	int address = r.maxAddress;
	r.addresses.add(address);
	objects.put(address, o);
	r.updateAddresses();
	return address;
}

public void unregister(int address) {
	r.addresses.remove(address);
	objects.remove(address);
	r.updateAddresses();
}

public Object get(int address) {
	return objects.get(address);
}

public void set(int address, Object o) {
	objects.put(address, o);
	r.updateAddresses();
}

public void save() {
	try {
		Endernet.gson.toJson(r, new FileWriter(file));
	} catch(Exception e) {
		e.printStackTrace();
	}
}

}

 

Then in my main class I added "public static Gson gson = new Gson();" and "public static Endernet instance;". I also implemented a serverstart event and serverstop event which load the endernet-registry.json and save it respectively.

 

package kriNon.endernet;

import com.google.gson.Gson;

import kriNon.endernet.init.ModBlocks;
import kriNon.endernet.init.ModItems;
import kriNon.endernet.lib.EnderRegistry;
import kriNon.endernet.proxy.CommonProxy;
import kriNon.endernet.tileentities.TileEntityEnderTransmitter;
import kriNon.endernet.util.Utils;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION)
public class Endernet {



@Mod.Instance(Reference.MODID)
public static Endernet instance;

	public static Gson gson = new Gson();

@SidedProxy(serverSide = Reference.SERVER_PROXY_CLASS, clientSide = Reference.CLIENT_PROXY_CLASS)
public static CommonProxy proxy;


@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	proxy.registerTileEntities();
	ModItems.init();
	ModBlocks.init();
	ModItems.register();
	ModBlocks.register();

	proxy.registerRenders();
}

@EventHandler
public void init(FMLInitializationEvent event) {
	proxy.regiserGUIHandler();

}

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
}

@EventHandler
public void serverStart(FMLServerStartingEvent event){
	try {
    		EnderRegistry.instance = new EnderRegistry(event.getServer().getFile("endernet-registry.json"));
    	} catch(Exception e) {
    		Utils.getLogger().error("Could not start EnderNet server!");
    		e.printStackTrace();
    	}
}

 @EventHandler
    public void serverStop(FMLServerStoppingEvent event) {
    	EnderRegistry.instance.save();
    }

}

 

In my TileEntityEnderTransmitter class I have added "nbt.setInteger("ea", ea);" to the writeToNBT method and added:

if(nbt.hasKey("ea")){
    	ea = nbt.getInteger("ea");
    	EnderRegistry.instance.set(ea, this);
    } else {
    	ea = EnderRegistry.instance.register(this);
    }

to the readFromNBT method.

 

I also added

public void update() {
	if(!this.worldObj.isRemote && ea == 0){
		 EnderRegistry.instance.register(this);
	}
}

So that it can register an ID if the id is zero.

 

and finally I added "EnderRegistry.instance.unregister(te.getEndernetID());" to the breakBlock function in my BlockEnderTransmitter to remove the ID from the registry if the block is broken.

 

 

I have the entire project uploaded to github here: https://github.com/kriNon/Endernet1.10.2/tree/Testing_EnderRegistry

Currently the issues I am having is that the endernet-registry.json file is remaining empty, tile entities are not getting ids, and upon right clicking or breaking the Ender Transmitter block it crashes:

---- Minecraft Crash Report ----
// I bet Cylons wouldn't have this problem.

Time: 5/01/17 7:23 PM
Description: Ticking block entity

java.lang.NullPointerException: Ticking block entity
at kriNon.endernet.lib.EnderRegistry.register(EnderRegistry.java:51)
at kriNon.endernet.tileentities.TileEntityEnderTransmitter.update(TileEntityEnderTransmitter.java:47)
at net.minecraft.world.World.updateEntities(World.java:1945)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:645)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:783)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536)
at java.lang.Thread.run(Unknown Source)


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

-- Head --
Thread: Server thread
Stacktrace:
at kriNon.endernet.lib.EnderRegistry.register(EnderRegistry.java:51)
at kriNon.endernet.tileentities.TileEntityEnderTransmitter.update(TileEntityEnderTransmitter.java:47)

-- Block entity being ticked --
Details:
Name: ender_transmitter // kriNon.endernet.tileentities.TileEntityEnderTransmitter
Block type: ID #0 (tile.air // net.minecraft.block.BlockAir)
Block data value: 0 / 0x0 / 0b0000
Block location: World: (-327,4,-1237), Chunk: (at 9,0,11 in -21,-78; contains blocks -336,0,-1248 to -321,255,-1233), Region: (-1,-3; contains chunks -32,-96 to -1,-65, blocks -512,0,-1536 to -1,255,-1025)
Actual block type: ID #0 (tile.air // net.minecraft.block.BlockAir)
Actual block data value: 0 / 0x0 / 0b0000
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:1945)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:645)

-- Affected level --
Details:
Level name: New World
All players: 1 total; [EntityPlayerMP['Player360'/167, l='New World', x=-324.57, y=4.00, z=-1238.58]]
Chunk stats: ServerChunkCache: 1089 Drop: 0
Level seed: -4428084075862744427
Level generator: ID 01 - flat, ver 0. Features enabled: true
Level generator options: 
Level spawn location: World: (-319,4,-1240), Chunk: (at 1,0,8 in -20,-78; contains blocks -320,0,-1248 to -305,255,-1233), Region: (-1,-3; contains chunks -32,-96 to -1,-65, blocks -512,0,-1536 to -1,255,-1025)
Level time: 21045 game time, 21045 day time
Level dimension: 0
Level storage version: 0x04ABD - Anvil
Level weather: Rain time: 114098 (now: false), thunder time: 100798 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:783)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536)
at java.lang.Thread.run(Unknown Source)

-- System Details --
Details:
Minecraft Version: 1.10.2
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_91, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 679530888 bytes (648 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.32 Powered by Forge 12.18.2.2171 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.19} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.10.2-12.18.2.2171.jar) 
UCHIJAAAA	Forge{12.18.2.2171} [Minecraft Forge] (forgeSrc-1.10.2-12.18.2.2171.jar) 
UCHIJAAAA	endernet{1.0.0} [Endernet] (bin) 
Loaded coremods (and transformers): 
Profiler Position: N/A (disabled)
Player Count: 1 / 8; [EntityPlayerMP['Player360'/167, l='New World', x=-324.57, y=4.00, z=-1238.58]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

Thanks for any help!

Link to comment
Share on other sites

It seems like your RegistryInformation field in EnderRegistry is not initialized before you use it.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

RegistryInformation is being initialised on line 36, and the nested class RegistryInformation is defined above that starting line 13. Where exactly am I going wrong?

I said it is not getting initialized before it is being used, try FMLServerAboutToStartEvent.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Sorry, do you mean that I should be using FMLServerAboutToStartEvent instead of FMLServerStartingEvent in my main class?

Yes

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

r.updateAddresses();

 

which calls:

		public void updateAddresses() {
		if(addresses.contains(maxAddress)) {
			// New address added, look up
			while(addresses.contains(maxAddress)) maxAddress++;
		} else {
			// Old address removed, look down
			while(!addresses.contains(maxAddress)) maxAddress--;
			maxAddress++;
		}
	}

Link to comment
Share on other sites

So after some further testing I've determined that both when placing and breaking the block, the error occurs with lines 53 and 64 respectively, both of which are calling the function updateAddresses() in the nested class RegistryInformation.

 

public void updateAddresses() {
		if(addresses.contains(maxAddress)) {
			// New address added, look up
			while(addresses.contains(maxAddress)) maxAddress++;
		} else {
			// Old address removed, look down
			while(!addresses.contains(maxAddress)) maxAddress--;
			maxAddress++;
		}
	}

 

When loading a world with the blocks already placed I also get this error:

[11:53:00] [server thread/ERROR]: Failed to load data for block entity ender_transmitter
java.lang.NullPointerException
at kriNon.endernet.lib.EnderRegistry.set(EnderRegistry.java:73) ~[EnderRegistry.class:?]
at kriNon.endernet.tileentities.TileEntityEnderTransmitter.readFromNBT(TileEntityEnderTransmitter.java:248) ~[TileEntityEnderTransmitter.class:?]
at net.minecraft.tileentity.TileEntity.create(TileEntity.java:137) [TileEntity.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:515) [AnvilChunkLoader.class:?]
at net.minecraftforge.common.chunkio.ChunkIOProvider.syncCallback(ChunkIOProvider.java:96) [ChunkIOProvider.class:?]
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:94) [ChunkIOExecutor.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:92) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:138) [ChunkProviderServer.class:?]
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:336) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:107) [integratedServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:124) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:496) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
[11:53:00] [server thread/ERROR] [FML]: A TileEntity ender_transmitter(kriNon.endernet.tileentities.TileEntityEnderTransmitter) has thrown an exception during loading, its state cannot be restored. Report this to the mod author
java.lang.NullPointerException
at kriNon.endernet.lib.EnderRegistry.set(EnderRegistry.java:73) ~[EnderRegistry.class:?]
at kriNon.endernet.tileentities.TileEntityEnderTransmitter.readFromNBT(TileEntityEnderTransmitter.java:248) ~[TileEntityEnderTransmitter.class:?]
at net.minecraft.tileentity.TileEntity.create(TileEntity.java:137) [TileEntity.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:515) [AnvilChunkLoader.class:?]
at net.minecraftforge.common.chunkio.ChunkIOProvider.syncCallback(ChunkIOProvider.java:96) [ChunkIOProvider.class:?]
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:94) [ChunkIOExecutor.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:92) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:138) [ChunkProviderServer.class:?]
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:336) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:107) [integratedServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:124) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:496) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]

Link to comment
Share on other sites

Alright, so after some further testing I've removed the section of code which was checking if the TileEntityEnderTransmitter has a ea value, and if not was registering one. This is because inside the readFromNBT part of the tile entity, it would register the tileentity with a ea value. This has fixed the crashing upon breaking or placing the Ender Transmitter blocks. However, upon placing the blocks, they still do not receive an ea value, and upon loading the world, and breaking the blocks I get errors:

 

[15:34:17] [server thread/ERROR]: Failed to load data for block entity ender_transmitter
java.lang.NullPointerException
at kriNon.endernet.lib.EnderRegistry.set(EnderRegistry.java:73) ~[EnderRegistry.class:?]
at kriNon.endernet.tileentities.TileEntityEnderTransmitter.readFromNBT(TileEntityEnderTransmitter.java:245) ~[TileEntityEnderTransmitter.class:?]
at net.minecraft.tileentity.TileEntity.create(TileEntity.java:137) [TileEntity.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:515) [AnvilChunkLoader.class:?]
at net.minecraftforge.common.chunkio.ChunkIOProvider.syncCallback(ChunkIOProvider.java:96) [ChunkIOProvider.class:?]
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:94) [ChunkIOExecutor.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:92) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:138) [ChunkProviderServer.class:?]
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:336) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:107) [integratedServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:124) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:496) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
[15:34:17] [server thread/ERROR] [FML]: A TileEntity ender_transmitter(kriNon.endernet.tileentities.TileEntityEnderTransmitter) has thrown an exception during loading, its state cannot be restored. Report this to the mod author
java.lang.NullPointerException
at kriNon.endernet.lib.EnderRegistry.set(EnderRegistry.java:73) ~[EnderRegistry.class:?]
at kriNon.endernet.tileentities.TileEntityEnderTransmitter.readFromNBT(TileEntityEnderTransmitter.java:245) ~[TileEntityEnderTransmitter.class:?]
at net.minecraft.tileentity.TileEntity.create(TileEntity.java:137) [TileEntity.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:515) [AnvilChunkLoader.class:?]
at net.minecraftforge.common.chunkio.ChunkIOProvider.syncCallback(ChunkIOProvider.java:96) [ChunkIOProvider.class:?]
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:94) [ChunkIOExecutor.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:121) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:92) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:138) [ChunkProviderServer.class:?]
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:336) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:107) [integratedServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:124) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:496) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]

 

[15:34:51] [server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_91]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_91]
at net.minecraft.util.Util.runTask(Util.java:26) [util.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:742) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
Caused by: java.lang.NullPointerException
at kriNon.endernet.lib.EnderRegistry.unregister(EnderRegistry.java:62) ~[EnderRegistry.class:?]
at kriNon.endernet.blocks.BlockEnderTransmitter.breakBlock(BlockEnderTransmitter.java:70) ~[blockEnderTransmitter.class:?]
at net.minecraft.world.chunk.Chunk.setBlockState(Chunk.java:610) ~[Chunk.class:?]
at net.minecraft.world.World.setBlockState(World.java:384) ~[World.class:?]
at net.minecraft.block.Block.removedByPlayer(Block.java:1324) ~[block.class:?]
at net.minecraft.server.management.PlayerInteractionManager.removeBlock(PlayerInteractionManager.java:298) ~[PlayerInteractionManager.class:?]
at net.minecraft.server.management.PlayerInteractionManager.removeBlock(PlayerInteractionManager.java:292) ~[PlayerInteractionManager.class:?]
at net.minecraft.server.management.PlayerInteractionManager.tryHarvestBlock(PlayerInteractionManager.java:339) ~[PlayerInteractionManager.class:?]
at net.minecraft.server.management.PlayerInteractionManager.onBlockClicked(PlayerInteractionManager.java:175) ~[PlayerInteractionManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:658) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:56) ~[CPacketPlayerDigging.class:?]
at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:12) ~[CPacketPlayerDigging.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_91]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_91]
at net.minecraft.util.Util.runTask(Util.java:25) ~[util.class:?]
... 5 more

 

Link to comment
Share on other sites

So I did some more testing, and it seems that the errors are caused when calling the function updateAddresses().

 

Any idea what could be wrong with it? I've tried making a simplified version of the class so that I can test basic functionality.

 

So I have a "private RegistryInformation r"

 

Where the class RegistryInformation is defined as:

class RegistryInformation {
	HashSet<Integer> addresses;
	int maxAddress;

	public void init() {
		addresses = new HashSet<Integer>();
		maxAddress = 0;
	}

	public void updateAddresses() {
		if(addresses.contains(maxAddress)) {
			// New address added, look up
			while(addresses.contains(maxAddress)) maxAddress++;
		} else {
			// Old address removed, look down
			while(!addresses.contains(maxAddress)) maxAddress--;
			maxAddress++;
		}
	}
}

 

And upon calling r.updateAddresses() it will cause errors.

 

The class in it's entirety is here:

package kriNon.endernet.lib;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.HashSet;

import kriNon.endernet.Endernet;

public class EnderRegistry {
class RegistryInformation {
	HashSet<Integer> addresses;
	int maxAddress;

	public void init() {
		addresses = new HashSet<Integer>();
		maxAddress = 0;
	}

	public void updateAddresses() {
		if(addresses.contains(maxAddress)) {
			// New address added, look up
			while(addresses.contains(maxAddress)) maxAddress++;
		} else {
			// Old address removed, look down
			while(!addresses.contains(maxAddress)) maxAddress--;
			maxAddress++;
		}
	}
}

public static EnderRegistry instance;

private RegistryInformation r;
private final HashMap<Integer, Object> objects = new HashMap<Integer, Object>();
private final File file;

public EnderRegistry(File file) {
	this.file = file;
	try {
		r = (RegistryInformation)(Endernet.gson.fromJson(new FileReader(file), RegistryInformation.class));
	} catch(FileNotFoundException e) {
		r = new RegistryInformation();
		r.init();
	}
}

public int register(Object o) {
	r.updateAddresses();
	int address = r.maxAddress;
	r.addresses.add(address);
	objects.put(address, o);
	r.updateAddresses();
	return address;
}
}

 

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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