Jump to content

[Forge 1.10.2] Container Crashed java.lang.NullPointerException: Ticking player


Recommended Posts

Posted

Hello, I created a block that have gui but it crashed. Here is my crash report:

 

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

Time: 16:05 22/12/2016
Description: Ticking player

java.lang.NullPointerException: Ticking player
at com.sathern.itweaks.gui.ContainerNeutron.canInteractWith(ContainerNeutron.java:47)
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:294)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2111)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:874)
at net.minecraft.world.World.updateEntity(World.java:2078)
at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:675)
at net.minecraft.world.World.updateEntities(World.java:1867)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:646)
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(Thread.java:745)


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

-- Head --
Thread: Server thread
Stacktrace:
at com.sathern.itweaks.gui.ContainerNeutron.canInteractWith(ContainerNeutron.java:47)
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:294)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2111)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:874)
at net.minecraft.world.World.updateEntity(World.java:2078)

-- Player being ticked --
Details:
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity ID: 332
Entity Name: Player466
Entity's Exact location: -54,19, 63,00, 179,95
Entity's Block location: World: (-55,63,179), Chunk: (at 9,3,3 in -4,11; contains blocks -64,0,176 to -49,255,191), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
Entity's Momentum: 0,00, -0,08, 0,00
Entity's Passengers: []
Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:675)
at net.minecraft.world.World.updateEntities(World.java:1867)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:646)

-- Affected level --
Details:
Level name: New World
All players: 1 total; [EntityPlayerMP['Player466'/332, l='New World', x=-54,19, y=63,00, z=179,95]]
Chunk stats: ServerChunkCache: 372 Drop: 0
Level seed: -7818503990427167087
Level generator: ID 00 - default, ver 1. Features enabled: true
Level generator options: 
Level spawn location: World: (-4,64,208), Chunk: (at 12,4,0 in -1,13; contains blocks -16,0,208 to -1,255,223), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
Level time: 24414 game time, 1450 day time
Level dimension: 0
Level storage version: 0x04ABD - Anvil
Level weather: Rain time: 1654 (now: false), thunder time: 17872 (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(Thread.java:745)

-- System Details --
Details:
Minecraft Version: 1.10.2
Operating System: Windows 7 (x86) version 6.1
Java Version: 1.8.0_111, Oracle Corporation
Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation
Memory: 685354216 bytes (653 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 15, tcache: 0, allocated: 13, tallocated: 95
FML: MCP 9.32 Powered by Forge 12.18.3.2185 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
UCHIJAAAA	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.10.2-12.18.3.2185.jar) 
UCHIJAAAA	Forge{12.18.3.2185} [Minecraft Forge] (forgeSrc-1.10.2-12.18.3.2185.jar) 
UCHIJAAAA	itweaks{1.0.0} [Avaritia] (bin) 
UCHIJAAAA	JEI{3.13.6.392} [Just Enough Items] (jei_1.10.2-3.13.6.392.jar) 
UCHIJAAAA	MineTweaker3{3.0.14} [MineTweaker 3] (CraftTweaker-1.10.2-3.0.15.jar) 
UCHIJAAAA	ctgui{1.0.0} [CT-GUI] (CraftTweaker-1.10.2-3.0.15.jar) 
Loaded coremods (and transformers): 
Profiler Position: N/A (disabled)
Player Count: 1 / 8; [EntityPlayerMP['Player466'/332, l='New World', x=-54,19, y=63,00, z=179,95]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

Here is my block code:

 

package com.sathern.itweaks.blocks;

import java.util.Random;

import javax.annotation.Nullable;

import com.sathern.itweaks.ImmersiveTweaks;
import com.sathern.itweaks.tile.TileEntityNeutron;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

public class BlockNeutronCollector extends BlockContainer {

private Random randy = new Random();

public BlockNeutronCollector(String name) {
	super(Material.IRON);
	setSoundType(SoundType.METAL);
	setHardness(20.0F);
	setUnlocalizedName("neutron_collector");
	setRegistryName("neutron_collector");
	setHarvestLevel("pickaxe", 3);
	setCreativeTab(ImmersiveTweaks.modTab);
}

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
		@Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
	if (world.isRemote) {
		return true;
	} else {
		player.openGui(ImmersiveTweaks.instance, 1, world, pos.getX(), pos.getY(), pos.getZ());
		return true;
	}
}

@Override
public TileEntity createNewTileEntity(World world, int meta) {
	return new TileEntityNeutron();
}

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack item) {
	TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
	if (tile instanceof TileEntityNeutron) {
		TileEntityNeutron machine = (TileEntityNeutron) tile;
		int l = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

		if (l == 0)
			machine.setFacing(2);

		if (l == 1)
			machine.setFacing(5);

		if (l == 2)
			machine.setFacing(3);

		if (l == 3)
			machine.setFacing(4);
	}

}

public void breakBlock(World world, int x, int y, int z, IBlockState block) {
	TileEntityNeutron collector = (TileEntityNeutron) world.getTileEntity(new BlockPos(x, y, z));

	if (collector != null) {
		ItemStack itemstack = collector.getStackInSlot(0);

		if (itemstack != null) {
			float f = this.randy.nextFloat() * 0.8F + 0.1F;
			float f1 = this.randy.nextFloat() * 0.8F + 0.1F;
			float f2 = this.randy.nextFloat() * 0.8F + 0.1F;

			while (itemstack.stackSize > 0) {
				int j1 = this.randy.nextInt(21) + 10;

				if (j1 > itemstack.stackSize) {
					j1 = itemstack.stackSize;
				}

				itemstack.stackSize -= j1;
				EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1),
						(double) ((float) z + f2),
						new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));

				if (itemstack.hasTagCompound()) {
					entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
				}

				float f3 = 0.05F;
				entityitem.motionX = (double) ((float) this.randy.nextGaussian() * f3);
				entityitem.motionY = (double) ((float) this.randy.nextGaussian() * f3 + 0.2F);
				entityitem.motionZ = (double) ((float) this.randy.nextGaussian() * f3);
				world.spawnEntityInWorld(entityitem);
			}
		}

		world.getBlockState(new BlockPos(x, y, z));
	}

	super.breakBlock(world, new BlockPos(x, y, z), block);
}

public void registerItemModel(ItemBlock itemBlock) {
	ImmersiveTweaks.proxy.registerItemRenderer(itemBlock, 0, "block_crystal_matrix");
}

}

 

My container code:

 

package com.sathern.itweaks.gui;

import com.sathern.itweaks.blocks.ModBlocks;
import com.sathern.itweaks.tile.TileEntityNeutron;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnaceOutput;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class ContainerNeutron extends Container {

private TileEntityNeutron tileNeutron;
protected World worldObj;
protected BlockPos pos;

public ContainerNeutron(InventoryPlayer player, TileEntityNeutron machine) {
	this.tileNeutron = machine;
	this.addSlotToContainer(new SlotFurnaceOutput(player.player, machine, 2, 80, 35));
	int i;

	for (i = 0; i < 3; ++i) {
		for (int j = 0; j < 9; ++j) {
			this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
		}
	}

	for (i = 0; i < 9; ++i) {
		this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142));
	}
}

@Override
/**
 * Called when the container is closed.
 */
public void onContainerClosed(EntityPlayer player) {
	super.onContainerClosed(player);

}

public boolean canInteractWith(EntityPlayer player) {
	return this.worldObj.getBlockState(pos) == ModBlocks.neutron_collector.getDefaultState()
			&& player.getDistanceSq(pos) <= 64.0D;
}

/**
 * Called when a player shift-clicks on a slot. You must override this or
 * you will crash when someone does that.
 */
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
	ItemStack itemstack = null;
	Slot slot = (Slot) this.inventorySlots.get(slotNumber);

	if (slot != null && slot.getHasStack()) {
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();

		if (slotNumber == 0) {
			if (!this.mergeItemStack(itemstack1, 1, 37, true)) {
				return null;
			}

			slot.onSlotChange(itemstack1, itemstack);
		} else {
			if (slotNumber >= 1 && slotNumber < 28) {
				if (!this.mergeItemStack(itemstack1, 28, 37, false)) {
					return null;
				}
			} else if (slotNumber >= 28 && slotNumber < 37 && !this.mergeItemStack(itemstack1, 1, 28, false)) {
				return null;
			}
		}

		if (itemstack1.stackSize == 0) {
			slot.putStack((ItemStack) null);
		} else {
			slot.onSlotChanged();
		}

		if (itemstack1.stackSize == itemstack.stackSize) {
			return null;
		}

		slot.onPickupFromSlot(player, itemstack1);
	}

	return itemstack;
}

}

 

My GUI code:

 

package com.sathern.itweaks.gui;

import org.lwjgl.opengl.GL11;

import com.sathern.itweaks.ImmersiveTweaks;
import com.sathern.itweaks.tile.TileEntityNeutron;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GUINeutron extends GuiContainer {

private static final ResourceLocation furnaceGuiTextures = new ResourceLocation(ImmersiveTweaks.modId,
		"textures/gui/neutron_collector_gui.png");

public GUINeutron(InventoryPlayer player, TileEntityNeutron machine) {
	super(new ContainerNeutron(player, machine));
}

/**
 * Draw the foreground layer for the GuiContainer (everything in front of
 * the items)
 */
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
	this.fontRendererObj.drawString("Neutron Collector",
			this.xSize / 2 - this.fontRendererObj.getStringWidth("Neutron Collector") / 2, 6, 4210752);
	this.fontRendererObj.drawString("Inventory", 8, this.ySize - 96 + 2, 4210752);
}

protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.getTextureManager().bindTexture(furnaceGuiTextures);
	int k = (this.width - this.xSize) / 2;
	int l = (this.height - this.ySize) / 2;
	this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);

}

}

 

My Tile Entity Code:

 

package com.sathern.itweaks.tile;

import com.sathern.itweaks.items.ModItems;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;

public class TileEntityNeutron extends TileBase implements IInventory {

private ItemStack neutrons;
private int facing = 2;
private int progress;

@Override
public void updateEntity() {
	if (++progress >= 7111) {
		// if(++progress >= 300){
		if (neutrons == null)
			neutrons = new ItemStack(ModItems.neutron_pile);
		else if (neutrons.getItem() == ModItems.diamond_lattice && neutrons.getItemDamage() == 2
				&& neutrons.stackSize < 64)
			neutrons.stackSize++;
		progress = 0;
		markDirty();
	}
}

public int getFacing() {
	return facing;
}

public void setFacing(int dir) {
	facing = dir;
}

@Override
public void readCustomNBT(NBTTagCompound tag) {
	this.neutrons = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Neutrons"));
	this.progress = tag.getInteger("Progress");
	this.facing = tag.getShort("Facing");
}

@Override
public void writeCustomNBT(NBTTagCompound tag) {
	tag.setInteger("Progress", this.progress);
	tag.setShort("Facing", (short) this.facing);
	if (neutrons != null) {
		NBTTagCompound produce = new NBTTagCompound();
		neutrons.writeToNBT(produce);
		tag.setTag("Neutrons", produce);
	} else
		tag.removeTag("Neutrons");
}

@Override
public String getName() {
	return "container.neutron";
}

@Override
public boolean hasCustomName() {
	return false;
}

@Override
public int getSizeInventory() {
	return 1;
}

@Override
public ItemStack getStackInSlot(int index) {
	return neutrons;
}

@Override
public ItemStack decrStackSize(int index, int count) {
	if (neutrons == null)
		return null;
	else {
		if (count < neutrons.stackSize) {
			ItemStack take = neutrons.splitStack(count);
			if (neutrons.stackSize <= 0)
				neutrons = null;
			return take;
		} else {
			ItemStack take = neutrons;
			neutrons = null;
			return take;
		}
	}
}

@Override
public ItemStack removeStackFromSlot(int index) {
	return null;
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
	neutrons = stack;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return this.worldObj
			.getTileEntity(new BlockPos(this.getPos().getX(), this.getPos().getY(), this.getPos().getX())) == this
			&& player.getDistanceSq((double) this.getPos().getX() + 0.5D, (double) this.getPos().getY() + 0.5D,
					(double) this.getPos().getZ() + 0.5D) <= 64.0D;
}

@Override
public void openInventory(EntityPlayer player) {

}

@Override
public void closeInventory(EntityPlayer player) {

}

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
	return false;
}

@Override
public int getField(int id) {
	return 0;
}

@Override
public void setField(int id, int value) {

}

@Override
public int getFieldCount() {
	return 0;
}

@Override
public void clear() {

}

}

 

My TileBase code:

 

package com.sathern.itweaks.tile;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;

public class TileBase extends TileEntity {

@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) {

	writeCustomNBT(tag);
	return super.writeToNBT(tag);
}

@Override
public void readFromNBT(NBTTagCompound tag) {
	super.readFromNBT(tag);
	readCustomNBT(tag);
}

public void writeCustomNBT(NBTTagCompound tag) {
}

public void readCustomNBT(NBTTagCompound tag) {
}

public void updateEntity() {

}

/*
 * @Override public Packet getDescriptionPacket() { NBTTagCompound tag = new
 * NBTTagCompound(); writeCustomNBT(tag); return new
 * S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, -999, tag); }
 */

/*
 * @Override public void onDataPacket(NetworkManager net,
 * S35PacketUpdateTileEntity packet) { super.onDataPacket(net, packet);
 * readCustomNBT(packet.func_148857_g()); }
 */

}

 

I have registered the Gui Handler and the tile entiy and I am creating a port from avaritia mod. Does anyone know to fix this?

Posted

You don't seem to initialize your

worldObj

or

pos

fields in your

ContainerNeutron

- that would mean they're both null when

canInteractWith

is called. You can use the debugger to check that.

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.