Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.9] Forge API of some sort? [UNSOLVED + A few questions]


Zodsmar
 Share

Recommended Posts

Here:

public class ContainerFabTable extends Container implements ISlotChanged {
private World worldObj;
public TileEntityFabTable tileEntity;

FabTabSlot FabSlot;
private int posX;
private int posY;
private int posZ;

/** The crafting matrix inventory (3x3). */ // container, width, length
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
private FabTabSlot fabTabSlot;

public ContainerFabTable(TileEntityFabTable fabTile, InventoryPlayer playerInv, World world, int x, int y, int z) {
	worldObj = world;
	tileEntity  = fabTile; //ERROR HERE
	posX = x;
	posY = y;
	posZ = z;
	fabTabSlot = new FabTabSlot(playerInv.player, this.craftMatrix, tileEntity.craftResult, 0, 143, 36);
	addSlotToContainer(fabTabSlot);
	int row;
	int col;

	updateCraftingMatrix();

	for (row = 0; row < 3; ++row) {
		for (col = 0; col < 3; ++col) {
			this.addSlotToContainer(new Slot(this.craftMatrix, col + row * 3, 48 + col * 18, 18 + row * 18));
		}
	}

	for (int row1 = 0; row1 < 2; row1++) {
		for (int col1 = 0; col1 < 9; col1++)
			this.addSlotToContainer(new Slot(tileEntity, col1 + row1 * 9, 8 + col1 * 18, 90 + row1 * 18));

	}

	this.addSlotToContainer(new SlotStartsWith(tileEntity, "fabUpgrade", 28, 16, 10).setSlotChange(tileEntity));
	this.addSlotToContainer(new SlotStartsWith(tileEntity, "fabUpgrade", 29, 16, 36).setSlotChange(tileEntity));
	this.addSlotToContainer(new SlotStartsWith(tileEntity, "fabUpgrade", 30, 16, 62).setSlotChange(tileEntity));

	this.addSlotToContainer(new SlotStartsWith(tileEntity, "fabPlan", 31, 143, 10).setSlotChange(this));

	for (int row2 = 0; row2 < 3; row2++) {
		for (int col2 = 0; col2 < 9; col2++)
			this.addSlotToContainer(new Slot(playerInv, col2 + row2 * 9 + 9, 8 + col2 * 18, 140 + row2 * 18));
	}

	for (row = 0; row < 9; ++row) {
		this.addSlotToContainer(new Slot(playerInv, row, 8 + row * 18, 198));
	}

	this.onCraftMatrixChanged(this.craftMatrix);

	// addSlotToContainer(new Slot(playerInv, 36, 17, 36));

}

private void updateCraftingMatrix() {
	for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
		craftMatrix.setInventorySlotContents(i, tileEntity.craftMatrixInventory[i]);
	}
}

@Override
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
	super.onContainerClosed(par1EntityPlayer);
	saveCraftingMatrix();
}

private void saveCraftingMatrix() {
	for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
		tileEntity.craftMatrixInventory[i] = craftMatrix.getStackInSlot(i);
	}
}

@Override
public void onCraftMatrixChanged(IInventory IInv) {
	tileEntity.craftResult.setInventorySlotContents(0,
			CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
}

@Override
public boolean canInteractWith(EntityPlayer entityPlayer) {
	return tileEntity.isUseableByPlayer(entityPlayer);

}

@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int par2) {
	ItemStack itemstack = null;
	Slot slot = (Slot) this.inventorySlots.get(par2);

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

		if (par2 == 0) {
			if (!this.mergeItemStack(itemstack1, 32, 67, false)) {

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

				return null;
			} else {
				slot.putStack((ItemStack) null);
			}

			fabTabSlot.onPickupFromSlot(entityPlayer, itemstack);
			this.onCraftMatrixChanged(this.craftMatrix);

			return itemstack;
		} else if (par2 >= 32 && par2 <= 67) {
			if (itemstack1.getUnlocalizedName().startsWith("fabUpgrade")) {
				return null;
			} else if (!this.mergeItemStack(itemstack1, 10, 27, false)) {
				if (itemstack1.stackSize == 0) {
					slot.putStack((ItemStack) null);
				} else {
					slot.onSlotChanged();
				}

				return null;
			}
		} else if (par2 >= 10 && par2 <= 27 || par2 <= 9 || par2 >= 28 && par2 <= 31) {
			if (!this.mergeItemStack(itemstack1, 32, 67, false)) {
				if (itemstack1.stackSize == 0) {
					slot.putStack((ItemStack) null);
				} else {
					slot.onSlotChanged();
				}

				return null;
			}
		}
	}

	return itemstack;
}

@Override
public void onSlotChange(Slot slot, int id, ItemStack itemStack) {
	System.out.println("Plans changed");

}

Link to comment
Share on other sites

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

I'm at a loss.  Null pointers are usually very easy to solve, but I can't locate ANYTHING in the method throwing the NPE that could be null.

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

Ikr like same. Normally after starring at the code something jumps out but fucken nothing. Like even if I comment it out. Then I get the null pointer on saveCraftingMatrix(); finally if I comment that then I get this null pointer.....

Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at net.minecraft.inventory.Slot.getStack(Slot.java:81)
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:84)
at net.minecraft.inventory.Container.onCraftMatrixChanged(Container.java:567)
at com.zodsmar.entities.ContainerFabTable.<init>(ContainerFabTable.java:69)
at com.zodsmar.entities.FabTableGui.<init>(FabTableGui.java:21)
at com.zodsmar.entities.GuiHandler.getClientGuiElement(GuiHandler.java:27)
at net.minecraftforge.fml.common.network.NetworkRegistry.getLocalGuiContainer(NetworkRegistry.java:266)
at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:102)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2694)
at com.zodsmar.blocks.FabricationTable.onBlockActivated(FabricationTable.java:36)
at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:425)
at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1597)
at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2268)
at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2052)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1840)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1114)
at net.minecraft.client.Minecraft.run(Minecraft.java:401)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

ITS LITERALLY NULL POINTERING ON at net.minecraft.inventory.Slot.getStack(Slot.java:81); HOW LIKE WHAT AM I MISSING HERE...... Jeez I love programming to death but things like this just get to me LOL <3

Link to comment
Share on other sites

Okay so for my class fabTabSlot I figure why it was null pointering thank you Choonster for that. But Here:

fabTabSlot = new FabTabSlot(playerInv.player, craftMatrix, fabTile, 0, 143, 36);
	addSlotToContainer(fabTabSlot);

And I pass in this:

public FabTabSlot(EntityPlayer par1EntityPlayer, InventoryCrafting craftResult, IInventory iinv, int par4, int par5, int par6)
{
         super(par1EntityPlayer, craftResult, iinv, par4, par5, par6);
         this.thePlayer = par1EntityPlayer;
         this.craftMatrix = craftResult;
}

 

Before I had craftmatrix being put into an IInventory and the craft fabTile into an InventoryCrafting. Now that line does not null pointer however I feel like I may have found the cause to my problem but because TileEntities and IInventory is kinda newer to me I am not sure. So here it goes with the explanation.

When I create my Container I pass in a Tile, InventoryPlayer, World, and 3 int.

But when I create slots I am using the Tile, which I passed in, as the IInventory. Is that right? Can my Tile Entity hold the IInventory. Like is that what it is suppose to do or did I royally mess up and need a new variable or something LOL

Link to comment
Share on other sites

In vanilla and older versions of Forge,

TileEntities

with inventories implement

IInventory

. This interface allows the inventory contents to be manipulated by GUIs and other blocks like Hoppers/Pipes.

 

In 1.8.9 and up, you should never be implementing

IInventory

yourself and you should avoid using it. The Capability system allows you to store one or more

IItemHandler

inventories in your

TileEntity

and access them through the

ICapabilityProvider

interface (implemented by

TileEntity

).

 

SlotItemHandler

allows you to create a

Slot

for an

IItemHandler

inventory.

 

Hoppers and vanilla inventories have been patched to support this system and item transport systems from properly updated mods (e.g. Extra Utilities 2) now use it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

You should be looking at exactly 1 line of TileEntityHopper if I understood Choonster correctly, the line that says what interfaces it implements.

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

Okay now I am a little confused. I am looking at the gui code for hoppers and so on and I still see IInventory everywhere.

 

All the vanilla GUIs still use

IInventory

, but the inventories themselves have been patched to support the

IItemHandler

capability.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Okay but in my case how should I be doing slots tho. Like for this:

	public FabTabSlot(EntityPlayer par1EntityPlayer, InventoryCrafting craftResult, IInventory iinv, int par4, int par5, int par6)
{
         super(par1EntityPlayer, craftResult, iinv, par4, par5, par6);
         this.thePlayer = par1EntityPlayer;
         this.craftMatrix = craftResult;
}

 

I cannot change it to IItemHandler because then it errors since I am extending SlotCrafting

Link to comment
Share on other sites

Is there any github repos which are using this new functionality which I could look at to understand better?

 

Try searching for

net.minecraftforge.items.IItemHandler

on GitHub.

 

Refined Relocation 2 and Chisels and Bits are two I noticed.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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
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.

 Share




  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Those three errors are what is making the IRCE return null and kicking them. Not sure what more the debug log will give but at least you know for sure the issue is happening when those three functions try to run. So process of deduction.
    • [Info: 2022-01-23 01:21:36.6133870: Xal.lib(0)] XAL: <<< Xal::Auth::InMemoryXboxTokenCache::GetTokenInternal (000085C2AB6FB370) [Info: 2022-01-23 01:21:36.6159390: Xal.lib(0)] XAL: [op 285139008] Refresh Xtoken running with user: true. [Info: 2022-01-23 01:21:36.6166694: Xal.lib(0)] XAL: [op 285139008] Operation RefreshXtoken is starting [Info: 2022-01-23 01:21:36.6176117: Xal.lib(0)] XAL: [op 285139008]     with CV '9/gCxFwybu+GIYtd.14.95' [Info: 2022-01-23 01:21:36.6179699: Xal.lib(0)] XAL: [op 285139008] RefreshXtoken token fetch started. [Info: 2022-01-23 01:21:36.6560585: NetQueue.cpp(601)] NetQueue: No connection available for https://sentry.io/api/2703928/store/ [Error: 2022-01-23 01:21:36.6562804: SentryAPI.cpp(124)] 0 No network connection available [Info: 2022-01-23 01:21:36.6565318: NetQueue.cpp(601)] NetQueue: No connection available for xsts.auth.xboxlive.com [Error: 2022-01-23 01:21:36.8822268: Xal.lib(0)] XAL: Http request 0C18B300 failed with 0x89235006, system error code 0, message:  [Warning: 2022-01-23 01:21:36.8868846: Xal.lib(0)] XAL: [op 285139008] Operation RefreshXtoken failed with result: 0x89235106 - Network error [Warning: 2022-01-23 01:21:36.8885727: Xal.lib(0)] XAL: [op 295548488] Operation GetXtoken failed with result: 0x89235106 - Network error [Warning: 2022-01-23 01:21:36.8968640: Xal.lib(0)] XAL: [op 258947712] Operation GetTokenAndSignature failed with result: 0x89235106 - Network error [Warning: 2022-01-23 01:21:36.8993100: Xal.lib(0)] XAL: GetTokenAndSignature for presence heartbeat failed with Network error (0x89235106)
    • Did you ever find a resolution?  I know that io.netty.util.IllegalReferenceCountException: refCnt: 0 is used as a way to check/validate functions.  I have yet to understand where there is "0" count. We don't have the issue ever on Val 3 only issue that arrises there is.. lets not go there. Anyway I was curious if you had any info in your research, thanks again!
    • I added it like this main private void doClientStuff(final FMLClientSetupEvent event) { event.enqueueWork(() -> { OverlayRegistry.registerOverlayBelow(ForgeIngameGui.FOOD_LEVEL_ELEMENT , "Mana", new ManaOverlay()); }); } But it's not working.   I feel that you don't understand about main... I'll try to find it.
    • Mc Version: 1.17.1 Forge: 37.1.1 Eclipse: 2021-06 new BlockItem(BlockInit.COMPRESSED_SOULS_BLOCK.get(), new Item(new Item.Properties().tab(CreativeModeTab.TAB_MISC))   When I hover over the line, eclipse says that the constructer BlockItem(Block, Item) is not defined
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.