Jump to content

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


Recommended Posts

Posted
  On 4/19/2016 at 3:15 PM, Zodsmar said:

Here is my code from 1.6 but I am un sure because Vec3 does not exist anymore.

 

Vec3 either:

a) still exists and you haven't imported it correctly

b) been replaced with a differently named, but identical class (e.g. Vector3)

 

If you look at the vanilla methods that used to return/take a Vec3 what are they taking now?

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.

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

Posted

So I am curious if this is possible but I am not sure because I am not quite sure how minecraft handles recipes. Right now for crafting I have it set up that it takes an input and an output. So for "Scrolling in a sense" through lets say all the metadata like so:

addRecipe(new HammerRecipe(Blocks.carpet, 0), 				new HammerRecipe(Blocks.carpet, 1));
	addRecipe(new HammerRecipe(Blocks.carpet, 1), 				new HammerRecipe(Blocks.carpet, 2));
	addRecipe(new HammerRecipe(Blocks.carpet, 2), 				new HammerRecipe(Blocks.carpet, 3));
	addRecipe(new HammerRecipe(Blocks.carpet, 3), 				new HammerRecipe(Blocks.carpet, 4));
	addRecipe(new HammerRecipe(Blocks.carpet, 4), 				new HammerRecipe(Blocks.carpet, 5));
	addRecipe(new HammerRecipe(Blocks.carpet, 5), 				new HammerRecipe(Blocks.carpet, 6));
	addRecipe(new HammerRecipe(Blocks.carpet, 6), 				new HammerRecipe(Blocks.carpet, 7));
	addRecipe(new HammerRecipe(Blocks.carpet, 7), 				new HammerRecipe(Blocks.carpet, );
	addRecipe(new HammerRecipe(Blocks.carpet, , 				new HammerRecipe(Blocks.carpet, 9));
	addRecipe(new HammerRecipe(Blocks.carpet, 9), 				new HammerRecipe(Blocks.carpet, 10));
	addRecipe(new HammerRecipe(Blocks.carpet, 10), 				new HammerRecipe(Blocks.carpet, 11));
	addRecipe(new HammerRecipe(Blocks.carpet, 11), 				new HammerRecipe(Blocks.carpet, 12));
	addRecipe(new HammerRecipe(Blocks.carpet, 12), 				new HammerRecipe(Blocks.carpet, 13));
	addRecipe(new HammerRecipe(Blocks.carpet, 13), 				new HammerRecipe(Blocks.carpet, 14));
	addRecipe(new HammerRecipe(Blocks.carpet, 14), 				new HammerRecipe(Blocks.carpet, 15));
	addRecipe(new HammerRecipe(Blocks.carpet, 15), 				new HammerRecipe(Blocks.carpet, 0));

I need to essentially create a recipe for each craft. Is there a way to condense this. What I am trying to do is set it so that the input, in this case would be Blocks.carpet, 15 (15 would be the max meta possible so for blocks with lower meta it can be changed) and the output, would be the starting meta which is almost always zero. So what I wanna then do is pass it through a loop like I am doing here:

	public static void addRecipeLOOP(HammerRecipe input, HammerRecipe output) {
	for(int i = 0; i < input.meta; i++){
		input.meta = i;
		output.meta = input.meta + 1;

		if (!input.isItems && !output.isItems)
			transformBlocks.put(input, new ItemStack(output.id, 1, output.meta));
	}

 

Only the way that minecraft handles recipes is it possible to create recipes via a loop? And you guys understand what I am trying to accomplish. Now this is not that important but like it gets rid of the hundreds of unnecessary lines of code for just simple meta jumping. Think about logs, and sand, and hardened clay and so on. Its a lot of stupid and repetitive code which if I can condense would be amazing and a lot easier to write then lol

 

Thanks Zods

Posted

Cough.

 

OreDictionary.

 

Cough.

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.

Posted
  On 4/20/2016 at 4:24 AM, Draco18s said:

Cough.

 

OreDictionary.

 

Cough.

 

Yes, but to my knowledge doesn't OreDictionary just look to see if that block exists with a meta, and the meta does not matter to the recipe? In my case I wanna increment up the by one each time. I tried Oredictionary.WILDCARD for the input and OreDictionary.WILDCARD + 1 for the output which I was sure was not gonna work but yeah.

Posted
  On 4/20/2016 at 1:46 PM, diesieben07 said:

OreDictionary.getOres("logWood")

If you read my question that does not really help. I am aware what ore dictionary does and how it works just integrating it is the issue.

Posted
  On 4/20/2016 at 1:16 PM, Zodsmar said:
Yes, but to my knowledge doesn't OreDictionary just look to see if that block exists with a meta, and the meta does not matter to the recipe? In my case I wanna increment up the by one each time. I tried Oredictionary.WILDCARD for the input and OreDictionary.WILDCARD + 1 for the output which I was sure was not gonna work but yeah.

 

Oredictionary.WILDCARD has a value of 32,767 (iirc).  It is larger than the metadata value allowed on an item stack, adding 1 to it isn't going to do what you want.

 

I can't tell you what you should be doing because I can't figure out WTF you want your hammer to do.  Write it in plain English as if I was a player of your mod.  What the fuck does this tool do?

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.

Posted

In plain English:

The hammer is a tool which allows a player to right click a block and based on recipes, that block will change and durability will be given to then hammer. However, all recipes which are "clickable" in the world can also be done in a crafting table. So the hammer is a tool which takes durability based on crafting.

 

Now the part I want to change for the hammer is right now to lets say craft from Oak log to Spruce Log the recipe is

addRecipe(new HammerRecipe(Blocks.log, 0), 					new HammerRecipe(Blocks.log, 1));

however there is 15 metadata available so to be able to go from lets say oak to jungle (because crafting is mainly click based) it has to increment up.

So for the 15 different block states for logs this is the code:

addRecipe(new HammerRecipe(Blocks.log, 0), 					new HammerRecipe(Blocks.log, 1));
	addRecipe(new HammerRecipe(Blocks.log, 1), 					new HammerRecipe(Blocks.log, 2));
	addRecipe(new HammerRecipe(Blocks.log, 2), 					new HammerRecipe(Blocks.log, 3));
	addRecipeT(new HammerRecipe(Blocks.log, 3), 					new HammerRecipe(Blocks.log, 4));
	addRecipeT(new HammerRecipe(Blocks.log, 4), 					new HammerRecipe(Blocks.log, 5));
	addRecipeT(new HammerRecipe(Blocks.log, 5), 					new HammerRecipe(Blocks.log, 6));
	addRecipeT(new HammerRecipe(Blocks.log, 6), 					new HammerRecipe(Blocks.log, 7));
	addRecipeT(new HammerRecipe(Blocks.log, 7), 					new HammerRecipe(Blocks.log, );
	addRecipeT(new HammerRecipe(Blocks.log, , 					new HammerRecipe(Blocks.log, 9));
	addRecipeT(new HammerRecipe(Blocks.log, 9), 					new HammerRecipe(Blocks.log, 10));
	addRecipeT(new HammerRecipe(Blocks.log, 10), 				new HammerRecipe(Blocks.log, 11));
	addRecipeT(new HammerRecipe(Blocks.log, 11), 				new HammerRecipe(Blocks.log, 12));
	addRecipeT(new HammerRecipe(Blocks.log, 12), 				new HammerRecipe(Blocks.log, 13));
	addRecipeT(new HammerRecipe(Blocks.log, 13), 				new HammerRecipe(Blocks.log, 14));
	addRecipeT(new HammerRecipe(Blocks.log, 14), 				new HammerRecipe(Blocks.log, 15));
	addRecipeT(new HammerRecipe(Blocks.log, 15), 				new HammerRecipe(Blocks.log, 0));

The thing I am trying to change is to bring down the amount of lines of code. I want to set up one recipe that will encapsulate all 15 meta's and increment in one line of code so something like:

addRecipe(new HammerRecipe(Blocks.log, OreDictionary.WILDCARD), new HammerRecipe(Blocks.log, OreDictionary.WILDCARD + 1));

Now I know this does not work but I am trying to basically for loop the recipes. Do you see what I am trying to do now? (Plain enough english)

-Zods

Posted

1) Why are you passing two

HammerRecipe

s to addRecipe?

1b) What is this class?

2)

new HammerRecipe(Blocks.log, OreDictionary.WILDCARD + 1)

makes no sense: you can't have a metdata that high and it in no way refers to the metadata of the other object.

 

You need to create your own version of IRecipe that takes a block and a wildcard metadata, which takes the input item stack's actual metadata and adds 1 (%16).

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.

Posted
  On 4/21/2016 at 12:04 AM, Draco18s said:

1) Why are you passing two

HammerRecipe

s to addRecipe?

1b) What is this class?

2)

new HammerRecipe(Blocks.log, OreDictionary.WILDCARD + 1)

makes no sense: you can't have a metdata that high and it in no way refers to the metadata of the other object.

 

You need to create your own version of IRecipe that takes a block and a wildcard metadata, which takes the input item stack's actual metadata and adds 1 (%16).

Hammer Recipe is the class which handles my own Recipe. I pass to Hammer Recipes because the first one is the input. And the second is the output. So

addRecipe(new HammerRecipe(Blocks.log, 0), new HammerRecipe(Blocks.log, 1));

Blocks.log, 0 is the input (BASICALLY when I right click ingame. If I click on Block.log, 1, which is Oak) it will then look at the second HammerRecipe which in this case is Blocks.log, 1 or Spruce and will replace Oak to spruce. So when I have 15 meta data's I need 15 lines of code to iterate threw. Does this make sense. Like I don't know how much easier I can explain this.....

Posted

I understand how you're doing the input and output, but you can't oredict that the way you want.

 

You need to create a recipe that takes * input and provides * output in the same class so that you can do the appropriate math.

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.

Posted

So I figured it out. This probably should have been easier than I thought but for anyone wanting to see the code here:

	/**
 * 
 * @param block
 *            (ex. Blocks.log)
 * @param starting
 *            (starting metadata)
 * @param ending
 *            (ending metadata)
 */
public static void HRL(Block block, int starting, int ending) {
	int meta1 = -1;
	int meta2;
	if (meta1 < 0) {
		meta1 = starting;
	}
	for (int i = meta1; i <= ending; i++) {
		meta2 = meta1 + 1;
		addRecipe(new HammerRecipe(block, meta1), new HammerRecipe(block, meta2));
		meta1 = meta2;
		if (i == ending) {
			addRecipe(new HammerRecipe(block, meta1), new HammerRecipe(block, starting));
		}
	}

}

/**
 * 
 * @param block
 *            (ex. Blocks.log)
 * @param starting
 *            (starting metadata)
 * @param ending
 *            (ending metadata)
 * @param startingForTransform
 *            (in case you only want certain blocks not craftable in
 *            crafting table)
 * @param shouldAddLastRecipeBack (Simply if you want a last recipe from max back to min)           
 */
public static void HrlADV(Block block, int starting, int ending, int startingForTransform, boolean shouldAddLastRecipeBack) {
	int meta1 = -1;
	int meta2;
	if (meta1 < 0) {
		meta1 = starting;
	}
	for (int i = meta1; i <= ending; i++) {
		meta2 = meta1 + 1;
		if (i >= startingForTransform) {
			addRecipeT(new HammerRecipe(block, meta1), new HammerRecipe(block, meta2));
		} else {
			addRecipe(new HammerRecipe(block, meta1), new HammerRecipe(block, meta2));
		}
		meta1 = meta2;
		if (i == startingForTransform && shouldAddLastRecipeBack == true) {
			addRecipe(new HammerRecipe(block, startingForTransform), new HammerRecipe(block, starting));
		}
		if (i >= ending && meta1 <= startingForTransform && shouldAddLastRecipeBack == true) {
			addRecipe(new HammerRecipe(block, meta1), new HammerRecipe(block, starting));
		}

		if (i >= ending && meta1 >= startingForTransform && shouldAddLastRecipeBack == true) {
			addRecipeT(new HammerRecipe(block, meta1), new HammerRecipe(block, starting));
		}
	}

}

Posted

Okay new problems <3 Love you guys btw for all the help and Like most of the time it isnt even a solution you just say stuff that makes me think of ways to fix it. So honestly any input is nice <3

So here it goes I am trying to make my gui open when I right click the block. As of right now there is no error and no errors in the code so I do not understand why it does not open or work. Here are the classes:

Main Class Registers:

 

  Reveal hidden contents

 

 

GuiHandler:

 

  Reveal hidden contents

 

FabTableGui:

 

  Reveal hidden contents

 

Container: (Pretty sure this one isnt that important for actually making the gui open. Rn all I want is the actual gui to open)

 

  Reveal hidden contents

 

TileEntityFabTable:

 

  Reveal hidden contents

 

The actual Block Class itself:

 

  Reveal hidden contents

 

And now for Completeness here is the Registering of the block also.  AKA blocks Class LOL

 

  Reveal hidden contents

 

Posted

Okay so in regards to the GUI not opening it works now kinda. My issue was

@Override
 public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)

I was using the wrong method so essentially right clicking did nothing. Now it works and I am getting errors in this class only pretty much

 

 

  Reveal hidden contents

 

 

Even by commenting most of it out I get this error:

[23:55:33] [server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.7.0_79]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.7.0_79]
at net.minecraft.util.Util.runTask(Util.java:24) [util.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:738) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:683) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:155) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:532) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.7.0_79]
Caused by: java.lang.NullPointerException
at net.minecraft.inventory.Slot.getStack(Slot.java:81) ~[slot.class:?]
at net.minecraft.inventory.Container.getInventory(Container.java:62) ~[Container.class:?]
at net.minecraft.inventory.Container.onCraftGuiOpened(Container.java:51) ~[Container.class:?]
at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:93) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2694) ~[EntityPlayer.class:?]
at com.zodsmar.blocks.FabricationTable.onBlockActivated(FabricationTable.java:36) ~[FabricationTable.class:?]
at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:455) ~[PlayerInteractionManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processRightClickBlock(NetHandlerPlayServer.java:706) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:68) ~[CPacketPlayerTryUseItem.class:?]
at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:13) ~[CPacketPlayerTryUseItem.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.7.0_79]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.7.0_79]
at net.minecraft.util.Util.runTask(Util.java:23) ~[util.class:?]
... 5 more
[23:55:33] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking player
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:785) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:683) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:155) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:532) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.7.0_79]
Caused by: java.lang.NullPointerException
at net.minecraft.inventory.Slot.getStack(Slot.java:81) ~[slot.class:?]
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:84) ~[Container.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:290) ~[EntityPlayerMP.class:?]
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2086) ~[World.class:?]
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:864) ~[WorldServer.class:?]
at net.minecraft.world.World.updateEntity(World.java:2051) ~[World.class:?]
at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:666) ~[WorldServer.class:?]
at net.minecraft.world.World.updateEntities(World.java:1858) ~[World.class:?]
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:637) ~[WorldServer.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:779) ~[MinecraftServer.class:?]
... 4 more

 

By trying code I have come to the conclusion that it is happening for 2 reasons. One it is something to do with the way I am dealing with slots. And second is:

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

The Ticking Player is erroring. Even if I comment out everything and leave only the fundamentals and important stuff (pretty much no Slot stuff) it works but crashes on Ticking Player so yeah?

Any thoughts guys????

 

Oh also at the end of the error was this no idea what it means tho and if its important.

[23:55:33] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.

Posted

Okay so everything is working now and all I had to do was change one thing. As to how this makes sense I am unsure but now I do not think that my methods in my tile entity class are being called.

 

Here is what I changed:

	public ContainerFabTable(TileEntityFabTable fabTile, InventoryPlayer playerInv, World world, int x, int y, int z) {
	worldObj = world;
	tileEntity  = new TileEntityFabTable();

Before it was:

tileEntity  = fabTile;

 

can someone explain why that makes sense. Also now in the tile entity class the NBT data for saving items when the gui is closed, does not work. Here is the code for the NBT Tags? Am I not calling them right or?

 

@Override
public void readFromNBT(NBTTagCompound nbtTagCompound) {

	super.readFromNBT(nbtTagCompound);

	// Read in the ItemStacks in the inventory from NBT
	NBTTagList tagList = nbtTagCompound.getTagList("Items", 18);
	inventory = new ItemStack[this.getSizeInventory()];
	for (int i = 0; i < tagList.tagCount(); ++i) {
		NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
		byte slot = tagCompound.getByte("Slot");
		if (slot >= 0 && slot < inventory.length) {
			inventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
		}
	}

	// Read in the Crafting Matrix from NBT
	NBTTagList craftingTag = nbtTagCompound.getTagList("CraftingMatrix", 9);
	craftMatrixInventory = new ItemStack[9]; // TODO: magic number
	for (int i = 0; i < craftingTag.tagCount(); ++i) {
		NBTTagCompound tagCompound = (NBTTagCompound) craftingTag.getCompoundTagAt(i);
		byte slot = tagCompound.getByte("Slot");
		if (slot >= 0 && slot < craftMatrixInventory.length) {
			craftMatrixInventory[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
		}
	}

	// Read craftingResult from NBT
	NBTTagCompound tagCraftResult = nbtTagCompound.getCompoundTag("CraftingResult");
	craftResult.setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(tagCraftResult));
}

@Override
public void writeToNBT(NBTTagCompound nbtTagCompound) {

	super.writeToNBT(nbtTagCompound);

	// Write the ItemStacks in the inventory to NBT
	NBTTagList tagList = new NBTTagList();
	for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) {
		if (inventory[currentIndex] != null) {
			NBTTagCompound tagCompound = new NBTTagCompound();
			tagCompound.setByte("Slot", (byte) currentIndex);
			inventory[currentIndex].writeToNBT(tagCompound);
			tagList.appendTag(tagCompound);
		}
	}
	nbtTagCompound.setTag("Items", tagList);

	// Write Crafting Matrix to NBT
	NBTTagList craftingTag = new NBTTagList();
	for (int currentIndex = 0; currentIndex < craftMatrixInventory.length; ++currentIndex) {
		if (craftMatrixInventory[currentIndex] != null) {
			NBTTagCompound tagCompound = new NBTTagCompound();
			tagCompound.setByte("Slot", (byte) currentIndex);
			craftMatrixInventory[currentIndex].writeToNBT(tagCompound);
			craftingTag.appendTag(tagCompound);
		}
	}
	nbtTagCompound.setTag("CraftingMatrix", craftingTag);

	// Write craftingResult to NBT
	if (craftResult.getStackInSlot(0) != null)
		nbtTagCompound.setTag("CraftingResult", craftResult.getStackInSlot(0).writeToNBT(new NBTTagCompound()));

}

Posted

The change you made makes it impossible for the "changes" to save back to the TileEntity in the world because you created a new one.

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.

Posted
  On 4/22/2016 at 3:05 PM, Draco18s said:

The change you made makes it impossible for the "changes" to save back to the TileEntity in the world because you created a new one.

If I don't tho then I get A ticking Player error. Or it starts to null pointer everywhere which makes no sense what so ever.

Posted

Then you're doing something seriously wrong.

You need to debug things.

I'm almost certain that the problem has to do with either the Slots you've set up, or the call to onCraftMatrixChanged in the constructor.

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.

Posted
  On 4/22/2016 at 3:15 PM, Draco18s said:

Then you're doing something seriously wrong.

You need to debug things.

I'm almost certain that the problem has to do with either the Slots you've set up, or the call to onCraftMatrixChanged in the constructor.

Well your right. That is where the Errors occur. If I comment out the slots, and leave the crafting matrix here is the error:

java.lang.NullPointerException: Unexpected error
at com.zodsmar.entities.ContainerFabTable.updateCraftingMatrix(ContainerFabTable.java:76)
at com.zodsmar.entities.ContainerFabTable.<init>(ContainerFabTable.java:39)
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)

 

The thing is I do not understand what I would be doing wrong.

Here is the code:

	/** The craft matrix inventory linked to this result slot. */
private final IInventory craftMatrix;
/** The player that is using the GUI where this slot resides. */
private EntityPlayer thePlayer;
/**
         * The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset.
         */
private int amountCrafted;

public FabTabSlot(EntityPlayer par1EntityPlayer, InventoryCrafting par2IInventory, InventoryCraftResult craftResult, int par4, int par5, int par6)
{
         super(par1EntityPlayer, par2IInventory, craftResult, par4, par5, par6);
         this.thePlayer = par1EntityPlayer;
         this.craftMatrix = par2IInventory;
}
/**
         * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
         */
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
         return false;
}
/**
         * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
         * stack.
         */
@Override
public ItemStack decrStackSize(int par1)
{
         if (this.getHasStack())
         {
                 this.amountCrafted += Math.min(par1, this.getStack().stackSize);
         }
         return super.decrStackSize(par1);
}
/**
         * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
         * internal count then calls onCrafting(item).
         */
@Override
protected void onCrafting(ItemStack par1ItemStack, int par2)
{
         this.amountCrafted += par2;
         this.onCrafting(par1ItemStack);
}

and the crafting matrix:

	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));
}

Posted

Show the full class that contains

updateCraftingMatrix

? Uh...ContainerFabTable.java

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.

Posted

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");

}

Posted

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.

Posted

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

Posted
Slot#getStack

can only throw a

NullPointerException

if its

IInventory

is

null

.

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.

Posted

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

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.