Jump to content

Obscure NPE


Zeher_Monkey

Recommended Posts

Updating a spiritual successor to DimensionalPockets, DimensionalPocketsII. Github here. Updating the mod from 1.11.2 to 1.12.2. Having a major crash when i place the pocket block in the world. The whole game crashes with this error log:

 

ErrorLog.txt

Spoiler

[16:30:04] [Server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_144]
    at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_144]
    at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:796) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
Caused by: java.lang.NullPointerException
    at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:168) ~[ChunkProviderServer.class:?]
    at net.minecraft.world.World.getChunkFromChunkCoords(World.java:361) ~[World.class:?]
    at net.minecraft.world.World.getChunkFromBlockCoords(World.java:353) ~[World.class:?]
    at net.minecraft.world.World.getBlockState(World.java:994) ~[World.class:?]
    at com.zeher.dimensionalpockets.core.pocket.Pocket.generatePocketRoom(Pocket.java:128) ~[Pocket.class:?]
    at com.zeher.dimensionalpockets.core.tileentity.TileEntityDimensionalPocket.onBlockPlacedBy(TileEntityDimensionalPocket.java:120) ~[TileEntityDimensionalPocket.class:?]
    at com.zeher.dimensionalpockets.core.block.BlockDimensionalPocket.onBlockPlacedBy(BlockDimensionalPocket.java:58) ~[BlockDimensionalPocket.class:?]
    at net.minecraft.item.ItemBlock.placeBlockAt(ItemBlock.java:205) ~[ItemBlock.class:?]
    at net.minecraft.item.ItemBlock.onItemUse(ItemBlock.java:57) ~[ItemBlock.class:?]
    at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:851) ~[ForgeHooks.class:?]
    at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:200) ~[ItemStack.class:?]
    at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:504) ~[PlayerInteractionManager.class:?]
    at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:767) ~[NetHandlerPlayServer.class:?]
    at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]
    at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]
    at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_144]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_144]
    at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]
    ... 5 more
[16:30:04] [Server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Exception ticking world
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:835) ~[MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741) ~[MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) ~[IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
Caused by: java.lang.NullPointerException
    at net.minecraft.world.gen.ChunkProviderServer.queueUnload(ChunkProviderServer.java:61) ~[ChunkProviderServer.class:?]
    at net.minecraft.world.gen.ChunkProviderServer.queueUnloadAll(ChunkProviderServer.java:80) ~[ChunkProviderServer.class:?]
    at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:231) ~[PlayerChunkMap.class:?]
    at net.minecraft.world.WorldServer.tick(WorldServer.java:236) ~[WorldServer.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:829) ~[MinecraftServer.class:?]
    ... 4 more
[16:30:05] [Server thread/ERROR]: This crash report has been saved to: C:\Users\josh1\Desktop\Java Projects\Minecraft\DimensionalPocketsII\Main Coding\Latest Oxygen [1.12.2] (2555)\run\.\crash-reports\crash-2017-12-20_16.30.04-server.txt
[16:30:05] [Server thread/INFO]: Stopping server
[16:30:05] [Server thread/INFO]: Saving players
[16:30:05] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: ---- Minecraft Crash Report ----
// You're mean.

Time: 12/20/17 4:30 PM
Description: Exception ticking world

java.lang.NullPointerException: Exception ticking world
    at net.minecraft.world.gen.ChunkProviderServer.queueUnload(ChunkProviderServer.java:61)
    at net.minecraft.world.gen.ChunkProviderServer.queueUnloadAll(ChunkProviderServer.java:80)
    at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:231)
    at net.minecraft.world.WorldServer.tick(WorldServer.java:236)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:829)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590)
    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: Client thread
Stacktrace:
    at net.minecraft.world.gen.ChunkProviderServer.queueUnload(ChunkProviderServer.java:61)
    at net.minecraft.world.gen.ChunkProviderServer.queueUnloadAll(ChunkProviderServer.java:80)
    at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:231)
    at net.minecraft.world.WorldServer.tick(WorldServer.java:236)

-- Affected level --
Details:
    Level name: Copy of New World
    All players: 0 total; []
    Chunk stats: ServerChunkCache: 1 Drop: 0
    Level seed: -2588443430239300562
    Level generator: ID 00 - default, ver 1. Features enabled: false
    Level generator options: 
    Level spawn location: World: (0,0,0), Chunk: (at 0,0,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 0 game time, 0 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: ~~ERROR~~ NullPointerException: null
Stacktrace:
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:829)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590)
    at java.lang.Thread.run(Unknown Source)

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_144, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 565632488 bytes (539 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
    FML: MCP 9.42 Powered by Forge 14.23.1.2555 7 mods loaded, 7 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

    | State     | ID                   | Version      | Source                           | Signature |
    |:--------- |:-------------------- |:------------ |:-------------------------------- |:--------- |
    | UCHIJAAAA | minecraft            | 1.12.2       | minecraft.jar                    | None      |
    | UCHIJAAAA | mcp                  | 9.42         | minecraft.jar                    | None      |
    | UCHIJAAAA | FML                  | 8.0.99.99    | forgeSrc-1.12.2-14.23.1.2555.jar | None      |
    | UCHIJAAAA | forge                | 14.23.1.2555 | forgeSrc-1.12.2-14.23.1.2555.jar | None      |
    | UCHIJAAAA | trzcore              | 2.2.0r       | bin                              | None      |
    | UCHIJAAAA | dimensionalpocketsii | 0.0.4a       | bin                              | None      |
    | UCHIJAAAA | jei                  | 4.8.4.130    | jei_1.12.2-4.8.4.130.jar         | None      |

    Loaded coremods (and transformers): 
    GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
    Profiler Position: N/A (disabled)
    Player Count: 1 / 8; [EntityPlayerMP['Player91'/1747, l='Copy of New World', x=-138.60, y=64.00, z=249.40]]
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'fml,forge'
[16:30:05] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2017-12-20_16.30.04-server.txt
[16:30:05] [main/INFO] [FML]: Waiting for the server to terminate/save.
[16:30:05] [Server thread/INFO]: Saving worlds
[16:30:05] [Server thread/INFO]: Saving chunks for level 'Copy of New World'/overworld
[16:30:05] [Server thread/INFO]: Saving chunks for level 'Copy of New World'/the_nether
[16:30:05] [Server thread/INFO]: Saving chunks for level 'Copy of New World'/the_end
[16:30:05] [Server thread/INFO]: Saving chunks for level 'Copy of New World'/Pocket Dimension
[16:30:05] [Server thread/ERROR]: Exception stopping the server
java.lang.NullPointerException: null
    at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:240) ~[ChunkProviderServer.class:?]
    at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:1060) ~[WorldServer.class:?]
    at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:468) ~[MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.saveAllWorlds(IntegratedServer.java:274) ~[IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:509) ~[MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:413) ~[IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:643) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
[16:30:05] [Server thread/INFO] [FML]: Applying holder lookups
[16:30:05] [Server thread/INFO] [FML]: Holder lookups applied
[16:30:05] [Server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.
[16:30:05] [main/INFO] [FML]: Server terminated.
[16:30:05] [Client Shutdown Thread/INFO]: Stopping server
[16:30:05] [Client Shutdown Thread/INFO]: Saving players
 

 

Really not sure what is wrong. Any help will be appreciated! :) 

Link to comment
Share on other sites

Show this code:

Quote

Pocket.generatePocketRoom(Pocket.java:128) 

Preferably the whole class. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I see "core" in your mod name. Core mods often don't fare well in Forge. Last time I heard, core mods were not supported in this forum.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

3 hours ago, jeffryfisher said:

I see "core" in your mod name. Core mods often don't fare well in Forge. Last time I heard, core mods were not supported in this forum.

Yeah TRZCore is just my libraries. Templates and basic java files, such as blocks, tileentities etc. Just a name, goes in the mods folder as a standard mod.

 

Pocket.class

Spoiler

package com.zeher.dimensionalpockets.core.pocket;

import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;

import com.google.common.base.Strings;
import com.google.gson.annotations.SerializedName;
import com.zeher.dimensionalpockets.DimensionalPockets;
import com.zeher.dimensionalpockets.core.block.BlockDimensionalPocket;
import com.zeher.dimensionalpockets.core.block.BlockDimensionalPocketWall;
import com.zeher.dimensionalpockets.core.dimshift.DimensionalShifter;
import com.zeher.dimensionalpockets.core.dimshift.DimensionalShiftUtils;
import com.zeher.dimensionalpockets.core.handlers.BlockHandler;
import com.zeher.dimensionalpockets.core.util.DimLogger;
import com.zeher.dimensionalpockets.core.util.DimUtils;
import com.zeher.dimensionalpockets.core.util.TeleportDirection;
import com.zeher.trzcore.api.TRZTextUtil;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraftforge.fml.common.FMLCommonHandler;

public class Pocket {

	// NBT CONSTANTS START //
	private static final String NBT_DIMENSIONAL_POCKET_KEY = "pocketData";
	private static final String NBT_FLOW_STATE_MAP_KEY = "stateMap";

	private static final String NBT_GENERATED_KEY = "generated";
	private static final String NBT_BLOCK_DIMENSION_KEY = "blockDim";
	private static final String NBT_CHUNK_COORDS_KEY = "chunkPos";
	private static final String NBT_BLOCK_COORDS_KEY = "blockPos";
	private static final String NBT_SPAWN_COORDS_KEY = "spawnPos";
	private static final String NBT_SPAWN_COORDS_YAW_KEY = "spawnPosYaw";
	private static final String NBT_SPAWN_COORDS_PITCH_KEY = "spawnPosPitch";
	private static final String NBT_CREATOR_KEY = "creator";
	// NBT CONSTANTS END //

	private transient NBTTagCompound nbtTagCompound;

	@SerializedName("sideStates")
	private Map<EnumFacing, PocketSideState> stateMap;

	@SerializedName("generated")
	private boolean isGenerated = false;

	@SerializedName("blockDim")
	private int blockDim;

	@SerializedName("chunkPos")
	private BlockPos chunkPos;

	@SerializedName("blockPos")
	private BlockPos blockPos;

	@SerializedName("spawnPos")
	private BlockPos spawnPos;
	
	@SerializedName("spawnPosYaw")
	private float spawnYaw;
	
	@SerializedName("spawnPosPitch")
	private float spawnPitch;

	@SerializedName("creator")
	private String creator;

	@Deprecated
	private BlockPos spawnSet; // renamed to spawnPos. Needs to stay for compatibility with old saves.

	private Map<EnumFacing, PocketSideState> getSideStateMap() {
		if (stateMap == null) {
			stateMap = new EnumMap<>(EnumFacing.class);
		}
		return stateMap;
	}

	private Pocket() {}

	public Pocket(BlockPos chunkPos, int blockDim, BlockPos blockPos) {
		setBlockDim(blockDim);
		setBlockPos(blockPos);
		setSpawnInPocket(new BlockPos(7, 1, 7), 0f, 0f);
		spawnPos = new BlockPos(7,1,7);
		this.chunkPos = chunkPos;
	}

	public void generatePocketRoom(String creatorName) {
		if (isGenerated) {
			return;
		}
		
		World world = PocketRegistry.getWorldForPockets();
		
		int worldX = chunkPos.getX() * 16;
		int worldY = chunkPos.getY() * 16;
		int worldZ = chunkPos.getZ() * 16;
		
		for (int x = 0; x < 16; x++) {
			for (int y = 0; y < 16; y++) {
				for (int z = 0; z < 16; z++) {
					boolean flagX = x == 0 || x == 15;
					boolean flagY = y == 0 || y == 15;
					boolean flagZ = z == 0 || z == 15;

					// Added those flags, so I could add these checks, almost halves the time.
					if (!(flagX || flagY || flagZ) || flagX && (flagY || flagZ) || flagY && flagZ) {
						continue;
					}

					world.setBlockState(new BlockPos(x, y, z), BlockHandler.block_dimensional_pocket_wall.getDefaultState());
				}
			}
		}

		isGenerated = world.getBlockState(new BlockPos(worldX + 1, 0, worldZ + 1)).getBlock() instanceof BlockDimensionalPocketWall;
		getNBT().setBoolean(NBT_GENERATED_KEY, isGenerated);

		if (!Strings.isNullOrEmpty(creatorName)) {
			creator = creatorName;
			getNBT().setString(NBT_GENERATED_KEY, creatorName);
		}
	}
	
	public void shiftTo(EntityPlayer entityPlayer) {
		if (entityPlayer.world.isRemote || !(entityPlayer instanceof EntityPlayerMP)) {
			return;
		}

		World world = getBlockWorld();
		TeleportDirection teleportSide = TeleportDirection.getValidTeleportLocation(world, blockPos);
		if (teleportSide == TeleportDirection.UNKNOWN) {
			TextComponentString comp = new TextComponentString(TRZTextUtil.ITALIC + "Teleport Disabled. Pocket is blocked on all sides.");
			entityPlayer.sendMessage(comp);
			
			return;
		}

		EntityPlayerMP player = (EntityPlayerMP) entityPlayer;

		int dimID = player.dimension;
		
		BlockPos tempSet = getChunkPos();
		BlockPos spawnSet = tempSet.add(this.spawnPos);
		
		DimensionalShifter teleporter = DimensionalShiftUtils.createTeleporter(dimID, spawnSet, spawnYaw, spawnPitch);

		generatePocketRoom(entityPlayer.getName());

		TextComponentString comp = new TextComponentString(TRZTextUtil.TEAL + "Entering pocket dimension...");
		entityPlayer.sendMessage(comp);
		
		if (dimID != DimensionalPockets.dimension_id) {
			DimensionalShiftUtils.shiftPlayerToDimension(player, DimensionalPockets.dimension_id, teleporter, spawnSet);
		} else {
			teleporter.placeInPortal(player, 0);
		}
	}

	public void shiftFrom(EntityPlayer entityPlayer) {
		if (entityPlayer.world.isRemote || !(entityPlayer instanceof EntityPlayerMP)) {
			return;
		}

		EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
		World world = getBlockWorld();

		if (isSourceBlockPlaced()) {
			TeleportDirection teleportSide = TeleportDirection.getValidTeleportLocation(world, blockPos);
			if (teleportSide != TeleportDirection.UNKNOWN) {
				BlockPos tempBlockSet = blockPos.add(teleportSide.toCoordSet());
				BlockPos spawnPos = new BlockPos(tempBlockSet.getX(), tempBlockSet.getY() + 1, tempBlockSet.getZ());
				DimensionalShifter teleporter = DimensionalShiftUtils.createTeleporter(blockDim, blockPos, player.rotationYaw, player.rotationPitch);

				if (blockDim != DimensionalPockets.dimension_id) {
					DimensionalShiftUtils.shiftPlayerToDimension(player, blockDim, teleporter, spawnPos);
				} else {
					teleporter.placeInPortal(player, 0);
				}
				
				TextComponentString comp = new TextComponentString(TRZTextUtil.TEAL + "Leaving pocket dimension...");
				entityPlayer.sendMessage(comp);
				
			} else {
				TextComponentString comp = new TextComponentString(TRZTextUtil.ITALIC + "You're trapped! Someone broke your Pocket.");
				entityPlayer.sendMessage(comp);
			}
		} else {
			TextComponentString comp = new TextComponentString(TRZTextUtil.ITALIC + "You're Trapped! Something is blocking your Pocket.");
			entityPlayer.sendMessage(comp);
		}
	}

	public boolean isSourceBlockPlaced() {
		return getBlock() instanceof BlockDimensionalPocket;
	}

	public World getBlockWorld() {
		return FMLCommonHandler.instance().getMinecraftServerInstance().getServer().getWorld(blockDim);
	}

	public Block getBlock() {
		World world = getBlockWorld();
		if (world == null) {
			DimLogger.warning("Dimension with ID " + blockDim + " does not exist... (Mystcraft or GalactiCraft world?) Returning null for Pocket");
			return null;
		}
		return world.getBlockState(blockPos).getBlock();
	}

	public int getBlockDim() {
		return blockDim;
	}

	public void setBlockDim(int blockDim) {
		this.blockDim = blockDim;
		getNBT().setInteger(NBT_BLOCK_DIMENSION_KEY, blockDim);
	}

	public BlockPos getBlockPos() {
		return blockPos;
	}

	public void setBlockPos(BlockPos blockPos) {
		this.blockPos = blockPos;
		//this.blockPos.writeToNBT(getNBT(), NBT_BLOCK_COORDS_KEY);
	}

	private BlockPos getSpawnPos() {
		if (spawnPos == null) {
			spawnPos = spawnSet;
			spawnSet = null;
		}
		return spawnPos;
	}

	public void setSpawnInPocket(BlockPos spawnPos, float spawnYaw, float spawnPitch) {
		this.spawnPos = spawnPos;
		//this.spawnPos.writeToNBT(getNBT(), NBT_SPAWN_COORDS_KEY);

		this.spawnYaw = spawnYaw;
		getNBT().setFloat(NBT_SPAWN_COORDS_YAW_KEY, this.spawnYaw);
		this.spawnPitch = spawnPitch;
		getNBT().setFloat(NBT_SPAWN_COORDS_PITCH_KEY, this.spawnPitch);
	}

	public BlockPos getChunkPos() {
		return chunkPos;
	}

	public String getCreator() {
		return creator;
	}

	private NBTTagCompound getNBT() {
		if (nbtTagCompound == null) {
			// generate first compound
			nbtTagCompound = new NBTTagCompound();

			NBTTagCompound stateMap = new NBTTagCompound();
			for (Entry<EnumFacing, PocketSideState> entry : getSideStateMap().entrySet()) {
				EnumFacing side = entry.getKey();
				PocketSideState state = entry.getValue();
				stateMap.setString(side.name(), state.name());
			}
			nbtTagCompound.setTag(NBT_FLOW_STATE_MAP_KEY, stateMap);

			nbtTagCompound.setBoolean(NBT_GENERATED_KEY, isGenerated);
			nbtTagCompound.setInteger(NBT_BLOCK_DIMENSION_KEY, blockDim);

			if (chunkPos != null) {
				//chunkPos.writeToNBT(nbtTagCompound, NBT_CHUNK_COORDS_KEY);
			}

			if (blockPos != null) {
				//blockPos.writeToNBT(nbtTagCompound, NBT_BLOCK_COORDS_KEY);
			}

			if (getSpawnPos() != null) {
				//spawnPos.writeToNBT(nbtTagCompound, NBT_SPAWN_COORDS_KEY);
			}

			getNBT().setFloat(NBT_SPAWN_COORDS_YAW_KEY, spawnYaw);
			getNBT().setFloat(NBT_SPAWN_COORDS_PITCH_KEY, spawnPitch);

			if (creator != null && !creator.isEmpty()) {
				nbtTagCompound.setString(NBT_CREATOR_KEY, creator);
			}
		}

		return nbtTagCompound;
	}

	public void writeToNBT(NBTTagCompound tag) {
		tag.setTag(NBT_DIMENSIONAL_POCKET_KEY, getNBT());
	}

	public static Pocket readFromNBT(NBTTagCompound tag) {
		NBTTagCompound pocketTag = tag.getCompoundTag(NBT_DIMENSIONAL_POCKET_KEY);

		Pocket pocket = new Pocket();

		//pocket.chunkPos = CoordSet.readFromNBT(pocketTag, NBT_CHUNK_COORDS_KEY);
		pocket.blockDim = pocketTag.getInteger(NBT_BLOCK_DIMENSION_KEY);
		//pocket.blockPos = CoordSet.readFromNBT(pocketTag, NBT_BLOCK_COORDS_KEY);

		pocket.isGenerated = pocketTag.getBoolean(NBT_GENERATED_KEY);
		//pocket.spawnPos = CoordSet.readFromNBT(pocketTag, NBT_SPAWN_COORDS_KEY);
		pocket.spawnYaw = pocketTag.getFloat(NBT_SPAWN_COORDS_YAW_KEY);
		pocket.spawnPitch = pocketTag.getFloat(NBT_SPAWN_COORDS_PITCH_KEY);

		pocket.creator = pocketTag.getString(NBT_CREATOR_KEY);
		if (pocket.creator.isEmpty()) {
			pocket.creator = null;
		}
		
		NBTTagCompound stateMap = pocketTag.getCompoundTag(NBT_FLOW_STATE_MAP_KEY);
		for (EnumFacing side : EnumFacing.VALUES) {
			if (stateMap.hasKey(side.name())) {
				PocketSideState state = PocketSideState.valueOf(stateMap.getString(side.name()));
				pocket.getSideStateMap().put(side, state);
			}
		}
		
		return pocket;
	}
}

 

Edited by Zeher_Monkey
Link to comment
Share on other sites

1 hour ago, Zeher_Monkey said:

Yeah TRZCore is just my libraries. Templates and basic java files, such as blocks, tileentities etc. Just a name, goes in the mods folder as a standard mod.

 

Pocket.class

  Reveal hidden contents


package com.zeher.dimensionalpockets.core.pocket;

import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;

import com.google.common.base.Strings;
import com.google.gson.annotations.SerializedName;
import com.zeher.dimensionalpockets.DimensionalPockets;
import com.zeher.dimensionalpockets.core.block.BlockDimensionalPocket;
import com.zeher.dimensionalpockets.core.block.BlockDimensionalPocketWall;
import com.zeher.dimensionalpockets.core.dimshift.DimensionalShifter;
import com.zeher.dimensionalpockets.core.dimshift.DimensionalShiftUtils;
import com.zeher.dimensionalpockets.core.handlers.BlockHandler;
import com.zeher.dimensionalpockets.core.util.DimLogger;
import com.zeher.dimensionalpockets.core.util.DimUtils;
import com.zeher.dimensionalpockets.core.util.TeleportDirection;
import com.zeher.trzcore.api.TRZTextUtil;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraftforge.fml.common.FMLCommonHandler;

public class Pocket {

	// NBT CONSTANTS START //
	private static final String NBT_DIMENSIONAL_POCKET_KEY = "pocketData";
	private static final String NBT_FLOW_STATE_MAP_KEY = "stateMap";

	private static final String NBT_GENERATED_KEY = "generated";
	private static final String NBT_BLOCK_DIMENSION_KEY = "blockDim";
	private static final String NBT_CHUNK_COORDS_KEY = "chunkPos";
	private static final String NBT_BLOCK_COORDS_KEY = "blockPos";
	private static final String NBT_SPAWN_COORDS_KEY = "spawnPos";
	private static final String NBT_SPAWN_COORDS_YAW_KEY = "spawnPosYaw";
	private static final String NBT_SPAWN_COORDS_PITCH_KEY = "spawnPosPitch";
	private static final String NBT_CREATOR_KEY = "creator";
	// NBT CONSTANTS END //

	private transient NBTTagCompound nbtTagCompound;

	@SerializedName("sideStates")
	private Map<EnumFacing, PocketSideState> stateMap;

	@SerializedName("generated")
	private boolean isGenerated = false;

	@SerializedName("blockDim")
	private int blockDim;

	@SerializedName("chunkPos")
	private BlockPos chunkPos;

	@SerializedName("blockPos")
	private BlockPos blockPos;

	@SerializedName("spawnPos")
	private BlockPos spawnPos;
	
	@SerializedName("spawnPosYaw")
	private float spawnYaw;
	
	@SerializedName("spawnPosPitch")
	private float spawnPitch;

	@SerializedName("creator")
	private String creator;

	@Deprecated
	private BlockPos spawnSet; // renamed to spawnPos. Needs to stay for compatibility with old saves.

	private Map<EnumFacing, PocketSideState> getSideStateMap() {
		if (stateMap == null) {
			stateMap = new EnumMap<>(EnumFacing.class);
		}
		return stateMap;
	}

	private Pocket() {}

	public Pocket(BlockPos chunkPos, int blockDim, BlockPos blockPos) {
		setBlockDim(blockDim);
		setBlockPos(blockPos);
		setSpawnInPocket(new BlockPos(7, 1, 7), 0f, 0f);
		spawnPos = new BlockPos(7,1,7);
		this.chunkPos = chunkPos;
	}

	public void generatePocketRoom(String creatorName) {
		if (isGenerated) {
			return;
		}
		
		World world = PocketRegistry.getWorldForPockets();
		
		int worldX = chunkPos.getX() * 16;
		int worldY = chunkPos.getY() * 16;
		int worldZ = chunkPos.getZ() * 16;
		
		for (int x = 0; x < 16; x++) {
			for (int y = 0; y < 16; y++) {
				for (int z = 0; z < 16; z++) {
					boolean flagX = x == 0 || x == 15;
					boolean flagY = y == 0 || y == 15;
					boolean flagZ = z == 0 || z == 15;

					// Added those flags, so I could add these checks, almost halves the time.
					if (!(flagX || flagY || flagZ) || flagX && (flagY || flagZ) || flagY && flagZ) {
						continue;
					}

					world.setBlockState(new BlockPos(x, y, z), BlockHandler.block_dimensional_pocket_wall.getDefaultState());
				}
			}
		}

		isGenerated = world.getBlockState(new BlockPos(worldX + 1, 0, worldZ + 1)).getBlock() instanceof BlockDimensionalPocketWall;
		getNBT().setBoolean(NBT_GENERATED_KEY, isGenerated);

		if (!Strings.isNullOrEmpty(creatorName)) {
			creator = creatorName;
			getNBT().setString(NBT_GENERATED_KEY, creatorName);
		}
	}
	
	public void shiftTo(EntityPlayer entityPlayer) {
		if (entityPlayer.world.isRemote || !(entityPlayer instanceof EntityPlayerMP)) {
			return;
		}

		World world = getBlockWorld();
		TeleportDirection teleportSide = TeleportDirection.getValidTeleportLocation(world, blockPos);
		if (teleportSide == TeleportDirection.UNKNOWN) {
			TextComponentString comp = new TextComponentString(TRZTextUtil.ITALIC + "Teleport Disabled. Pocket is blocked on all sides.");
			entityPlayer.sendMessage(comp);
			
			return;
		}

		EntityPlayerMP player = (EntityPlayerMP) entityPlayer;

		int dimID = player.dimension;
		
		BlockPos tempSet = getChunkPos();
		BlockPos spawnSet = tempSet.add(this.spawnPos);
		
		DimensionalShifter teleporter = DimensionalShiftUtils.createTeleporter(dimID, spawnSet, spawnYaw, spawnPitch);

		generatePocketRoom(entityPlayer.getName());

		TextComponentString comp = new TextComponentString(TRZTextUtil.TEAL + "Entering pocket dimension...");
		entityPlayer.sendMessage(comp);
		
		if (dimID != DimensionalPockets.dimension_id) {
			DimensionalShiftUtils.shiftPlayerToDimension(player, DimensionalPockets.dimension_id, teleporter, spawnSet);
		} else {
			teleporter.placeInPortal(player, 0);
		}
	}

	public void shiftFrom(EntityPlayer entityPlayer) {
		if (entityPlayer.world.isRemote || !(entityPlayer instanceof EntityPlayerMP)) {
			return;
		}

		EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
		World world = getBlockWorld();

		if (isSourceBlockPlaced()) {
			TeleportDirection teleportSide = TeleportDirection.getValidTeleportLocation(world, blockPos);
			if (teleportSide != TeleportDirection.UNKNOWN) {
				BlockPos tempBlockSet = blockPos.add(teleportSide.toCoordSet());
				BlockPos spawnPos = new BlockPos(tempBlockSet.getX(), tempBlockSet.getY() + 1, tempBlockSet.getZ());
				DimensionalShifter teleporter = DimensionalShiftUtils.createTeleporter(blockDim, blockPos, player.rotationYaw, player.rotationPitch);

				if (blockDim != DimensionalPockets.dimension_id) {
					DimensionalShiftUtils.shiftPlayerToDimension(player, blockDim, teleporter, spawnPos);
				} else {
					teleporter.placeInPortal(player, 0);
				}
				
				TextComponentString comp = new TextComponentString(TRZTextUtil.TEAL + "Leaving pocket dimension...");
				entityPlayer.sendMessage(comp);
				
			} else {
				TextComponentString comp = new TextComponentString(TRZTextUtil.ITALIC + "You're trapped! Someone broke your Pocket.");
				entityPlayer.sendMessage(comp);
			}
		} else {
			TextComponentString comp = new TextComponentString(TRZTextUtil.ITALIC + "You're Trapped! Something is blocking your Pocket.");
			entityPlayer.sendMessage(comp);
		}
	}

	public boolean isSourceBlockPlaced() {
		return getBlock() instanceof BlockDimensionalPocket;
	}

	public World getBlockWorld() {
		return FMLCommonHandler.instance().getMinecraftServerInstance().getServer().getWorld(blockDim);
	}

	public Block getBlock() {
		World world = getBlockWorld();
		if (world == null) {
			DimLogger.warning("Dimension with ID " + blockDim + " does not exist... (Mystcraft or GalactiCraft world?) Returning null for Pocket");
			return null;
		}
		return world.getBlockState(blockPos).getBlock();
	}

	public int getBlockDim() {
		return blockDim;
	}

	public void setBlockDim(int blockDim) {
		this.blockDim = blockDim;
		getNBT().setInteger(NBT_BLOCK_DIMENSION_KEY, blockDim);
	}

	public BlockPos getBlockPos() {
		return blockPos;
	}

	public void setBlockPos(BlockPos blockPos) {
		this.blockPos = blockPos;
		//this.blockPos.writeToNBT(getNBT(), NBT_BLOCK_COORDS_KEY);
	}

	private BlockPos getSpawnPos() {
		if (spawnPos == null) {
			spawnPos = spawnSet;
			spawnSet = null;
		}
		return spawnPos;
	}

	public void setSpawnInPocket(BlockPos spawnPos, float spawnYaw, float spawnPitch) {
		this.spawnPos = spawnPos;
		//this.spawnPos.writeToNBT(getNBT(), NBT_SPAWN_COORDS_KEY);

		this.spawnYaw = spawnYaw;
		getNBT().setFloat(NBT_SPAWN_COORDS_YAW_KEY, this.spawnYaw);
		this.spawnPitch = spawnPitch;
		getNBT().setFloat(NBT_SPAWN_COORDS_PITCH_KEY, this.spawnPitch);
	}

	public BlockPos getChunkPos() {
		return chunkPos;
	}

	public String getCreator() {
		return creator;
	}

	private NBTTagCompound getNBT() {
		if (nbtTagCompound == null) {
			// generate first compound
			nbtTagCompound = new NBTTagCompound();

			NBTTagCompound stateMap = new NBTTagCompound();
			for (Entry<EnumFacing, PocketSideState> entry : getSideStateMap().entrySet()) {
				EnumFacing side = entry.getKey();
				PocketSideState state = entry.getValue();
				stateMap.setString(side.name(), state.name());
			}
			nbtTagCompound.setTag(NBT_FLOW_STATE_MAP_KEY, stateMap);

			nbtTagCompound.setBoolean(NBT_GENERATED_KEY, isGenerated);
			nbtTagCompound.setInteger(NBT_BLOCK_DIMENSION_KEY, blockDim);

			if (chunkPos != null) {
				//chunkPos.writeToNBT(nbtTagCompound, NBT_CHUNK_COORDS_KEY);
			}

			if (blockPos != null) {
				//blockPos.writeToNBT(nbtTagCompound, NBT_BLOCK_COORDS_KEY);
			}

			if (getSpawnPos() != null) {
				//spawnPos.writeToNBT(nbtTagCompound, NBT_SPAWN_COORDS_KEY);
			}

			getNBT().setFloat(NBT_SPAWN_COORDS_YAW_KEY, spawnYaw);
			getNBT().setFloat(NBT_SPAWN_COORDS_PITCH_KEY, spawnPitch);

			if (creator != null && !creator.isEmpty()) {
				nbtTagCompound.setString(NBT_CREATOR_KEY, creator);
			}
		}

		return nbtTagCompound;
	}

	public void writeToNBT(NBTTagCompound tag) {
		tag.setTag(NBT_DIMENSIONAL_POCKET_KEY, getNBT());
	}

	public static Pocket readFromNBT(NBTTagCompound tag) {
		NBTTagCompound pocketTag = tag.getCompoundTag(NBT_DIMENSIONAL_POCKET_KEY);

		Pocket pocket = new Pocket();

		//pocket.chunkPos = CoordSet.readFromNBT(pocketTag, NBT_CHUNK_COORDS_KEY);
		pocket.blockDim = pocketTag.getInteger(NBT_BLOCK_DIMENSION_KEY);
		//pocket.blockPos = CoordSet.readFromNBT(pocketTag, NBT_BLOCK_COORDS_KEY);

		pocket.isGenerated = pocketTag.getBoolean(NBT_GENERATED_KEY);
		//pocket.spawnPos = CoordSet.readFromNBT(pocketTag, NBT_SPAWN_COORDS_KEY);
		pocket.spawnYaw = pocketTag.getFloat(NBT_SPAWN_COORDS_YAW_KEY);
		pocket.spawnPitch = pocketTag.getFloat(NBT_SPAWN_COORDS_PITCH_KEY);

		pocket.creator = pocketTag.getString(NBT_CREATOR_KEY);
		if (pocket.creator.isEmpty()) {
			pocket.creator = null;
		}
		
		NBTTagCompound stateMap = pocketTag.getCompoundTag(NBT_FLOW_STATE_MAP_KEY);
		for (EnumFacing side : EnumFacing.VALUES) {
			if (stateMap.hasKey(side.name())) {
				PocketSideState state = PocketSideState.valueOf(stateMap.getString(side.name()));
				pocket.getSideStateMap().put(side, state);
			}
		}
		
		return pocket;
	}
}

 

Small update, no success with the NPE, however ive changed the name of TRZCore to TRZLib across the board, to side-step any confusion as to it being a coremod.

Link to comment
Share on other sites

2 hours ago, Zeher_Monkey said:

Small update, no success with the NPE, however ive changed the name of TRZCore to TRZLib across the board, to side-step any confusion as to it being a coremod.

I was just about to suggest that

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So, I've gotten similar crashes recently when trying to handle the PopulateChunk event. Code I had that worked in previous versions for placing a bunch of blocks (kinda like what you're doing) crashed with concurrent modification exceptions now. I suspect it may actually be a bug because the point of the event is to allow some block editing at that point. But in any case, concurrent modification errors often arise when dealing with Java collections and iterating through them unsafely -- perhaps another thread is doing that at the same time you (or me in my case) were trying to place blocks.

 

From inspecting the vanilla generation code, it seems that the safe way to do it is to use a ChunkPrimer class. If one already exists at that point use it, or create a new one. Fill that up with block placements and then use the whole thing to create the chunk. Look at how ChunkPrimer is used in the vanilla code for ideas.

Edited by jabelar

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

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.

Announcements



×
×
  • Create New...

Important Information

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