Jump to content

Crash When I open GUI


sohaspaces

Recommended Posts

I made orb maker.

but it was crash when i open GUI

Caused by: java.lang.NullPointerException
	at net.minecraftforge.items.SlotItemHandler.getStack(SlotItemHandler.java:62) ~[SlotItemHandler.class:?]
	at net.minecraft.inventory.Container.getInventory(Container.java:75) ~[Container.class:?]
	at net.minecraft.inventory.Container.addListener(Container.java:61) ~[Container.class:?]
	at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:101) ~[FMLNetworkHandler.class:?]
	at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2809) ~[EntityPlayer.class:?]
	at com.teamapplejuice.blocks.BlockOrbMaker.onBlockActivated(BlockOrbMaker.java:39) ~[BlockOrbMaker.class:?]
	at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:475) ~[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(Executors.java:511) ~[?:1.8.0_161]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_161]
	at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]
	... 5 more
public class BlockOrbMaker extends BlockBase implements ITileEntityProvider{

	public BlockOrbMaker() {
		super("orb_maker", Material.WOOD, 2, "axe", 0, 0);
		// TODO Auto-generated constructor stub
	}
	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
			EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
		// TODO Auto-generated method stub
			playerIn.openGui(EpicStats.instance, GuiHandler.ORB_MAKER, worldIn, pos.getX(), pos.getY(), pos.getZ());
		return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
	}
	@Override
	public TileEntity createNewTileEntity(World worldIn, int meta) {
		// TODO Auto-generated method stub
		return new TileEntityOrbMaker();
	}
}
public class GUIOrbMaker extends GuiContainer {
	private TileEntityOrbMaker te;

	public GUIOrbMaker(IInventory player, TileEntityOrbMaker orbMaker) {
		super(new ContainerOrbMaker(orbMaker, player));
		this.te = orbMaker;
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
		// TODO Auto-generated method stub
		this.mc.getTextureManager().bindTexture(new ResourceLocation(Reference.MODID, "textures/gui/orbmaker.png"));
		this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);

	}
}

class ContainerOrbMaker extends Container {
	private TileEntityOrbMaker te;
	public IItemHandler handler;

	public ContainerOrbMaker(TileEntityOrbMaker te, IInventory playerInv) {
		this.te = te;
		this.handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); // Gets
																								// the
																								// inventory
																								// from
																								// our
																								// tile
																								// entity

		this.addSlotToContainer(new SlotItemHandler(handler, 0, 62, 17));
		this.addSlotToContainer(new SlotItemHandler(handler, 1, 98, 17));
		this.addSlotToContainer(new SlotItemHandler(handler, 2, 62, 53));
		// The player's inventory slots
		int xPos = 8; // The x position of the top left player inventory
						// slot on our texture
		int yPos = 84; // The y position of the top left player inventory
						// slot on our texture

		// Player slots
		for (int y = 0; y < 3; ++y) {
			for (int x = 0; x < 9; ++x) {
				this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, xPos + x * 18, yPos + y * 18));
			}
		}

		for (int x = 0; x < 9; ++x) {
			this.addSlotToContainer(new Slot(playerInv, x, xPos + x * 18, yPos + 58));
		}
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean canInteractWith(EntityPlayer player) {
		// TODO Auto-generated method stub
		return true;
	}

}
package com.teamapplejuice.gui;

import com.teamapplejuice.stats.Stats;
import com.teamapplejuice.tileentity.TileEntityOrbMaker;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler
{
	public static final int ORB_MAKER=112;
	@Override
	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		// TODO Auto-generated method stub
		if(ID==ORB_MAKER)
			return new ContainerOrbMaker((TileEntityOrbMaker) world.getTileEntity(new BlockPos(x, y, z)), player.inventory);
		return null;
	}

	@Override
	public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		// TODO Auto-generated method stub
		if(ID==ORB_MAKER)
			return new GUIOrbMaker(player.inventory, (TileEntityOrbMaker) world.getTileEntity(new BlockPos(x, y, z)));
		return null;
	}
}

 

Link to comment
Share on other sites

Don't implement ITileEntityProvider instead override hasTileEntity(IBlockState) and createTileEntity(World, IBlockState).

 

Post your TileEntity.

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

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.