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

Sorry for not posting all the code here is all the code:

public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos,
		EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	double x = pos.getX();
	double y = pos.getY();
	double z = pos.getZ();
	BlockStateContainer id = worldIn.getBlockState(pos).getBlock().getBlockState();
	Block output = Recipes.getHammerRecipe(id);
	IBlockState block = worldIn.getBlockState(pos);
	int meta = worldIn.getBlockState(pos).getBlock().getMetaFromState(block);
	if (output != null) {
		if (worldIn.isRemote) {
			worldIn.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, x, y + 1D, z, 0D, 0D, 0D, 1);
			worldIn.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, x + 1, y + 1D, z, 0D, 0D, 0D, 1);
			worldIn.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, x + 1, y + 1D, z + 1, 0D, 0D, 0D, 1);
			worldIn.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, x, y + 1D, z + 1, 0D, 0D, 0D, 1);
		}
		if (!playerIn.capabilities.isCreativeMode)
			stack.damageItem(2, playerIn);

		worldIn.setBlockState(pos, output.getBlock().getStateFromMeta(meta), 2);
		return EnumActionResult.PASS;
	}
	return EnumActionResult.FAIL;
}

 

		addRecipe(new HammerRecipe(Blocks.stonebrick), new HammerRecipe(Blocks.stone));

}

public static ItemStack getHammerRecipe(BlockStateContainer id) {
	for (Entry<HammerRecipe, ItemStack> entry : transformBlocks.entrySet())
		if (entry.getKey().id == id)
			return entry.getValue();
	return null;
}

public static void addRecipe(HammerRecipe input, HammerRecipe output) {
	if (!input.isItems && !output.isItems)
		transformBlocks.put(input, new ItemStack(output.id.getBlock(), 1 ,output.meta));

	GameRegistry.addShapelessRecipe(new ItemStack(output.id.getBlock(), 1), new Object[] {
			new ItemStack(ItemsAF.hammer, 1, Short.MAX_VALUE), new ItemStack(input.id.getBlock(), 1) });
}

For the recipe tho I wanna be able to do something like addRecipe(new HammerRecipe(Blocks.log , 1, 0), new HammerRecipe(Blocks.log, 1 ,1 ));

So to go from like Oak to Birch or something like that right now using BlockStateContainer I got it to work with stone to stonebrick. But I am not sure how to do it for blocks with meta. With the code does this make more sense now?

 

Oops also here is the HammerRecipe class:

public class HammerRecipe {
public boolean isItems;
public BlockStateContainer id;
public int meta;

public HammerRecipe(Block Blocks) {
	this.id = Blocks.getBlockState();
	this.isItems = false;
}

public HammerRecipe(Block Blocks, int meta) {
	this.id = Blocks.getBlockState();
	this.meta = meta;
	this.isItems = false;
}
}

Link to comment
Share on other sites

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

Why are you using the

Block

's

BlockStateContainer

as an ID? Use the

Block

(the block type, e.g.

Blocks.stone

), its

RegistryDelegate

(a unique identifier of the

Block

) or a specific

IBlockState

(the

Block

and a map of properties and values, e.g.

Blocks.stone

with its

VARIANT

property set to

GRANITE

).

 

An

ItemStack

isn't an

IBlockState

, you can't cast between them. If the

ItemStack

's

Item

is an

ItemBlock

, use

ItemBlock#getBlock

to get the

Block

,

Item#getMetadata(int)

to get the block metadata corresponding to the

ItemStack

's metadata and

Block#getStateFromMeta

to get the

IBlockState

corresponding to that metadata.

 

Based on what you said here I was actually able to figure out everything I needed to everything works except now I need to figure out a way to limit only certain blocks like logs to be able to go when right clicking up to 15 meta (because this way I can get every type of wood ) but in a crafting grid it starts to give purple and black because minecraft doesn't actually have items for them in game so yeah. But for anyone wanting to see how I achieved this here is the code:

public static ItemBlock getHammerRecipe(Block id, int meta) {
	for (Entry<HammerRecipe, ItemStack> entry : transformBlocks.entrySet())
		if (entry.getKey().id == id && (entry.getKey().meta == meta || entry.getKey().igroneData))
			return (ItemBlock) entry.getValue().getItem();
	return null;
}
public static int getHammerRecipeMeta(Block id, int meta) { 
	for (Entry<HammerRecipe, ItemStack> entry : transformBlocks.entrySet())
		if (entry.getKey().id == id && (entry.getKey().meta == meta || entry.getKey().igroneData))
			return entry.getValue().getItemDamage();
	return 0;
}


public static boolean getIgroneMeta(Block id, int meta) {
	for (HammerRecipe recipe : transformBlocks.keySet())
	    if(recipe.id == id && (recipe.meta == meta || recipe.igroneData))
	    	return recipe.igroneData;
	return false;
}

public class HammerRecipe {
public boolean isItems;
public Block id;
public int meta;
boolean igroneData;

public HammerRecipe(Block Blocks) {
	this.id = Blocks.getBlockState().getBlock();
	this.isItems = false;
}

public HammerRecipe(Block Blocks, int meta) {
	this.id = Blocks.getBlockState().getBlock();
	this.meta = meta;
	this.isItems = false;
}

public HammerRecipe setIgroneMeta() {
	this.igroneData = true;
	return this;
}
}

 

	public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos,
		EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	double x = pos.getX();
	double y = pos.getY();
	double z = pos.getZ();
	IBlockState block = worldIn.getBlockState(pos);
	Block id = worldIn.getBlockState(pos).getBlock();
	ItemBlock output = Recipes.getHammerRecipe(id, id.getMetaFromState(block));
	int meta = Recipes.getHammerRecipeMeta(id, id.getMetaFromState(block));

	if (output != null) {
		if (worldIn.isRemote) {
			worldIn.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, x, y + 1D, z, 0D, 0D, 0D, 1);
			worldIn.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, x + 1, y + 1D, z, 0D, 0D, 0D, 1);
			worldIn.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, x + 1, y + 1D, z + 1, 0D, 0D, 0D, 1);
			worldIn.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, x, y + 1D, z + 1, 0D, 0D, 0D, 1);
		}
		if (!playerIn.capabilities.isCreativeMode)
			stack.damageItem(2, playerIn);

		worldIn.setBlockState(pos, output.getBlock().getStateFromMeta(meta), 2);
		return EnumActionResult.PASS;
	}
	return EnumActionResult.FAIL;
}

 

And an actual example of the recipes (And what I meant with logs LOL):

		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));
	addRecipe(new HammerRecipe(Blocks.log, 3), 					new HammerRecipe(Blocks.log, 4));
	addRecipe(new HammerRecipe(Blocks.log, 4), 					new HammerRecipe(Blocks.log, 5));
	addRecipe(new HammerRecipe(Blocks.log, 5), 					new HammerRecipe(Blocks.log, 6));
	addRecipe(new HammerRecipe(Blocks.log, 6), 					new HammerRecipe(Blocks.log, 7));
	addRecipe(new HammerRecipe(Blocks.log, 7), 					new HammerRecipe(Blocks.log, );
	addRecipe(new HammerRecipe(Blocks.log, , 					new HammerRecipe(Blocks.log, 9));
	addRecipe(new HammerRecipe(Blocks.log, 9), 					new HammerRecipe(Blocks.log, 10));
	addRecipe(new HammerRecipe(Blocks.log, 10), 				new HammerRecipe(Blocks.log, 11));
	addRecipe(new HammerRecipe(Blocks.log, 11), 				new HammerRecipe(Blocks.log, 12));
	addRecipe(new HammerRecipe(Blocks.log, 12), 				new HammerRecipe(Blocks.log, 13));
	addRecipe(new HammerRecipe(Blocks.log, 13), 				new HammerRecipe(Blocks.log, 14));
	addRecipe(new HammerRecipe(Blocks.log, 14), 				new HammerRecipe(Blocks.log, 15));
	addRecipe(new HammerRecipe(Blocks.log, 15), 				new HammerRecipe(Blocks.log, 0));

Link to comment
Share on other sites

Okay so I got a new question. On rightclick I want to spawn a bolt of lightning where I am looking. However if its a block that can be converted via a recipe then do not do lightning but the recipe. Here is my code from 1.6 but I am un sure because Vec3 does not exist anymore.

 

	 public ItemStack onItemRightClick(ItemStack itemstack, World worldObj, EntityPlayer entityplayer)
 {
 if(itemstack.getItemDamage() >= 0){
	 float f = 1.0F;
	 float f1 = entityplayer.prevRotationPitch + (entityplayer.rotationPitch - entityplayer.prevRotationPitch) * f;
	 float f2 = entityplayer.prevRotationYaw + (entityplayer.rotationYaw - entityplayer.prevRotationYaw) * f;
	 double d = entityplayer.prevPosX + (entityplayer.posX - entityplayer.prevPosX) * (double)f;
	 double d1 = (entityplayer.prevPosY + (entityplayer.posY - entityplayer.prevPosY) * (double)f + 1.6200000000000001D) - (double)entityplayer.yOffset;
 	double d2 = entityplayer.prevPosZ + (entityplayer.posZ - entityplayer.prevPosZ) * (double)f;
 Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
 	float f3 = MathHelper.cos(-f2 * 0.01745329F - 3.141593F);
 	float f4 = MathHelper.sin(-f2 * 0.01745329F - 3.141593F);
 	float f5 = -MathHelper.cos(-f1 * 0.01745329F);
 	float f6 = MathHelper.sin(-f1 * 0.01745329F);
 	float f7 = f4 * f5;
 	float f8 = f6;
 	float f9 = f3 * f5;
 	double d3 = 5000D;
 Vec3 vec3d1 = vec3d.addVector((double)f7 * d3, (double)f8 * d3 + 1, (double)f9 * d3);
 MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks_do_do(vec3d, vec3d1, false, true);
 if (movingobjectposition == null)
 	{
	 return itemstack;
 	}
 if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
 {
	 int i = movingobjectposition.blockX;
	 int j = movingobjectposition.blockY;
	 int k = movingobjectposition.blockZ;
	 world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k));
 }
 	itemstack.setItemDamage(0);
 }
 	return itemstack;
 }

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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:

 

 

	
@Instance(Reference.MODID)
public static AppliedFabrication instance;

	NetworkRegistry.INSTANCE.registerGuiHandler(AppliedFabrication.instance, new GuiHandler());
	GameRegistry.registerTileEntity(TileEntityFabTable.class, NamesAF.FABTABLE);

 

 

 

GuiHandler:

 

 

public class GuiHandler implements IGuiHandler{

@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
	TileEntityFabTable tileFabTable = (TileEntityFabTable) world.getTileEntity(new BlockPos(x, y, z));
if(id == NamesAF.FABTABLE_ID){
	return new ContainerFabTable(tileFabTable, player.inventory, world, x, y, z);
	}
return null;
}

@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
	TileEntityFabTable tileFabTable = (TileEntityFabTable) world.getTileEntity(new BlockPos(x, y, z));
	if(id == NamesAF.FABTABLE_ID){
		return new FabTableGui(player.inventory, tileFabTable, world,  x, y, z);
		}

return null;
}

}

 

 

FabTableGui:

 

 

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


private static final ResourceLocation getTexture = new ResourceLocation("afabmod:textures/gui/fabTableGuiTest.png");

public FabTableGui(InventoryPlayer playerInv, TileEntityFabTable tileFabTable, World world, int x, int y, int z)
{
         super(new ContainerFabTable(tileFabTable, playerInv, world, x, y, z));
         
         xSize = 176;
         ySize = 222;
}

/**
         * Draw the foreground layer for the GuiContainer (everything in front of the items)
         */
@Override
protected void drawGuiContainerForegroundLayer(int x, int z)	
{
//	         this.fontRendererObj.drawString((StatCollector.translateToLocal("\u00a71Fabrication Table"), 48, 6, 4210752);
//	         this.fontRendererObj.drawString(StatCollector.translateToLocal("Inventory"), 8, this.ySize - 96 + 2, 4210752);
}
/**
         * Draw the background layer for the GuiContainer (everything behind the items)
         */
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y)
{
         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        Minecraft.getMinecraft().getTextureManager().bindTexture(getTexture);
         int k = (this.width - this.xSize) / 2;
         int l = (this.height - this.ySize) / 2;
         this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
}

 @Override
    public void onGuiClosed() {
        super.onGuiClosed();
    }

}

 

 

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

 

 

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 tileFabTable, InventoryPlayer playerInv, World world, int x, int y, int z)
{
         worldObj = world;
         posX = x;
         posY =  y;
         posZ = z;
         fabTabSlot = new FabTabSlot(playerInv.player, this.craftMatrix, tileFabTable.craftResult, 0, 143, 36);
         addSlotToContainer(fabTabSlot);
         int row;
         int col;
         tileEntity = tileFabTable;
         
         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(tileFabTable, col1 + row1 * 9, 8 + col1 * 18, 90 + row1 * 18));

         }
         
//	         this.addSlotToContainer(new SlotStartsWith(tileFabTable, "fabUpgrade", 28, 16, 10).setSlotChange(tileFabTable));
//	         this.addSlotToContainer(new SlotStartsWith(tileFabTable, "fabUpgrade", 29, 16, 36).setSlotChange(tileFabTable));
//	         this.addSlotToContainer(new SlotStartsWith(tileFabTable, "fabUpgrade", 30, 16, 62).setSlotChange(tileFabTable));
//	         
//	         this.addSlotToContainer(new SlotStartsWith(tileFabTable, "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(par1InventoryPlayer, 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");


}
}

 

 

TileEntityFabTable:

 

 

public class TileEntityFabTable extends TileEntity implements IInventory, ISlotChanged {
private ItemStack[] inventory;
public InventoryCraftResult craftResult = new InventoryCraftResult();
public ItemStack[] craftMatrixInventory;

public TileEntityFabTable() {

	super();
	inventory = new ItemStack[32];
	craftMatrixInventory = new ItemStack[9]; // TODO: magic number
}

@Override
public int getSizeInventory() {
	return inventory.length;
}

@Override
public ItemStack getStackInSlot(int i) {

	return this.inventory[i];
}

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

@Override
public ItemStack decrStackSize(int slot, int amount) {

	ItemStack itemStack = getStackInSlot(slot);
	if (itemStack != null) {
		if (itemStack.stackSize <= amount) {
			setInventorySlotContents(slot, null);
		} else {
			itemStack = itemStack.splitStack(amount);
			if (itemStack.stackSize == 0) {
				setInventorySlotContents(slot, null);
			}
		}
	}

	return itemStack;
}

public ItemStack getStackInSlotOnClosing(int slot) {

	if (inventory[slot] != null) {
		ItemStack itemStack = inventory[slot];
		inventory[slot] = null;
		return itemStack;
	} else
		return null;
}

@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
	inventory[i] = itemstack;

	if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
		itemstack.stackSize = getInventoryStackLimit();
	}

	this.markDirty();
}

public String getInvName() {
	return "Fabrication Table";
}

public boolean isInvNameLocalized() {
	return false;
}

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

@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
//		return entityplayer.getDistanceSq(entityplayer.posX + 0.5, entityplayer.posY + 0.5, entityplayer.posZ + 0.5) <= 64;
	return true;
}

public void openChest() {
}

public void closeChest() {
}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
	return true;
}

@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()));

}

public String getInventoryName() {
	// TODO Auto-generated method stub
	return null;
}

public boolean hasCustomInventoryName() {
	// TODO Auto-generated method stub
	return false;
}

public void openInventory() {
	// TODO Auto-generated method stub

}

public void closeInventory() {
	// TODO Auto-generated method stub

}


public String getName() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public boolean hasCustomName() {
	// TODO Auto-generated method stub
	return false;
}

@Override
public ITextComponent getDisplayName() {
	// TODO Auto-generated method stub
	return null;
}

@Override
public ItemStack removeStackFromSlot(int index) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public void openInventory(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public void closeInventory(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public int getField(int id) {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public void setField(int id, int value) {
	// TODO Auto-generated method stub

}

@Override
public int getFieldCount() {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public void clear() {
	// TODO Auto-generated method stub

}

 

 

The actual Block Class itself:

 

 

ublic class FabricationTable extends Block {

protected FabricationTable(Material materialIn) {
	super(materialIn);
}

public boolean onBlockActivated(World world, int x, int y, int z, IBlockState state, EntityPlayer player, EnumHand hand,
		ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {

	if(!player.isSneaking())
        {
            player.openGui(AppliedFabrication.instance, NamesAF.FABTABLE_ID, world, x, y, z);
            return true;
        }
        else
        {
            return false;
        }
}

  public void breakBlock(World world, BlockPos pos, IBlockState state) {

//	        dropInventory(world, pos);
        super.breakBlock(world, pos, state.getBlock().getDefaultState());
    }


//	    private void dropInventory(World world, int x, int y, int z) {
//
//	        TileEntity tileEntity = world.getTileEntity(pos);
//
//	        if (!(tileEntity instanceof IInventory))
//	            return;
//
//	        IInventory inventory = (IInventory) tileEntity;
//
//	        for (int i = 0; i < inventory.getSizeInventory(); i++) {
//
//	            ItemStack itemStack = inventory.getStackInSlot(i);
//
//	            if (itemStack != null && itemStack.stackSize > 0) {
//	                float dX = rand.nextFloat() * 0.8F + 0.1F;
//	                float dY = rand.nextFloat() * 0.8F + 0.1F;
//	                float dZ = rand.nextFloat() * 0.8F + 0.1F;
//
//	                EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));
//
//	                if (itemStack.hasTagCompound()) {
//	                    entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
//	                }
//
//	                float factor = 0.05F;
//	                entityItem.motionX = rand.nextGaussian() * factor;
//	                entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
//	                entityItem.motionZ = rand.nextGaussian() * factor;
//	                world.spawnEntityInWorld(entityItem);
//	                itemStack.stackSize = 0;
//	            }
//	        }
//	    }
  
public TileEntity createNewTileEntity(World worldIn, int meta) {
	return new TileEntityFabTable();
}

public int getRenderType() {
	return 3;
}

 

 

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

 

 

public class BlocksAF {
public static Block fabTable;

public static void init() {
	GameRegistry.registerBlock(fabTable = new FabricationTable(Material.wood).setRegistryName(NamesAF.FABTABLE)
			.setCreativeTab(AFTabs.tabAppliedFabrication));

	uN(fabTable, NamesAF.FABTABLE);
}

public static void registerTileEntities() {
	GameRegistry.registerTileEntity(new TileEntityFabTable().getClass(), NamesAF.FABTABLE_GUI);
}

public static void registerRender(Block block) {
	Item item = Item.getItemFromBlock(block);
	ModelLoader.setCustomModelResourceLocation(item, 0,
			new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

public static void registerRenders() {
	registerRender(fabTable);
}
public static void uN(Block block, String name) {
	block.setUnlocalizedName(name).setCreativeTab(AFTabs.tabAppliedFabrication);
}
}

 

 

Link to comment
Share on other sites

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

 

 

 

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 tileFabTable, InventoryPlayer playerInv, World world, int x, int y, int z)
{
         worldObj = world;
         posX = x;
         posY =  y;
         posZ = z;
//	         fabTabSlot = new FabTabSlot(playerInv.player, this.craftMatrix, tileFabTable.craftResult, 0, 143, 36);
//	         addSlotToContainer(fabTabSlot);
         int row;
         int col;
         tileEntity = tileFabTable;
         
//	         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(tileFabTable, col1 + row1 * 9, 8 + col1 * 18, 90 + row1 * 18));

         }
         
//	         this.addSlotToContainer(new SlotStartsWith(tileFabTable, "fabUpgrade", 28, 16, 10).setSlotChange(tileFabTable));
//	         this.addSlotToContainer(new SlotStartsWith(tileFabTable, "fabUpgrade", 29, 16, 36).setSlotChange(tileFabTable));
//	         this.addSlotToContainer(new SlotStartsWith(tileFabTable, "fabUpgrade", 30, 16, 62).setSlotChange(tileFabTable));
         
//	         this.addSlotToContainer(new SlotStartsWith(tileFabTable, "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");


}
}

 

 

 

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.

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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




×
×
  • Create New...

Important Information

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