Thanks for the advice but it's just "public void UpdateEntity ()"
There's no @Override above :/
I can post my actual tile entity class if you need
In your Block class, did you create a method to update the 'furnace' state? e.g. from idle to active? If you've ever made a Furnace-type block before, you should already be familiar with that.
In your TileEntity class, there absolutely SHOULD be @Override above the updateEntity method; in Java, case matters. UpdateEntity is NOT the same as updateEntity.
// this one will give you an error when you add @Override
// don't just think that removing @Override will remove the error!
// you need to make the method signature match exactly the method in the super-class
// (i.e. the class that you 'extend')
@Override
public void UpdateEntity()
// this is the correct method signature:
@Override
public void updateEntity()
nope never ventured into making a semi complicated custom machine before i have basic to medium modding knowledge, blocks, items, recipes, mobs, tile entity blocks, food liquids etc never really looked into machines, atm im only good at reading, understanding and adapting code but since i dont understand the furnace atm because of things like
public static void updateFurnaceBlockState(boolean p_149931_0_, World p_149931_1_, int p_149931_2_, int p_149931_3_, int p_149931_4_)
{
int l = p_149931_1_.getBlockMetadata(p_149931_2_, p_149931_3_, p_149931_4_);
TileEntity tileentity = p_149931_1_.getTileEntity(p_149931_2_, p_149931_3_, p_149931_4_);
field_149934_M = true;
its hard for me to look at code that havent been deobfuscated and interpret it :/
if you or anyone is able to provide the method for me deobfuscated i would really apreciate it once i complete this machine i can adapt it for heaps of purposes :3
its hard for me to look at code that havent been deobfuscated and interpret it :/
if you or anyone is able to provide the method for me deobfuscated i would really apreciate it once i complete this machine i can adapt it for heaps of purposes :3
Lol, yeah, that sure is an eyesore. The parameters are exactly the same as they were in 1.6.4:
public static void updateFurnaceBlockState(boolean isActive, World world, int x, int y, int z)
field_149934_M // this is "keepInventory"
The first parameter is what determines the block to place: lit or unlit; the rest are pretty self-explanatory. All the method does is get the block's metadata, get the tile entity, then set "keepInventory" to true. This is important because calling setBlock will "break" the block currently there, and "keepInventory" determines whether or not to spill all the contents. So now the block gets set to either the lit or unlit furnace based on the first parameter, keepInventory is set back to false so other blocks will work properly, and the metadata and tile entity for the "new" block are set with the correct values. Finally, it validates the tile entity.
Basically you just copy that exact code into your Block class, change the name if you want, and make sure to account for "keepInventory" in your Block's breakBlock method. If you need more explanations and have some time, I recommend checking out pretty much any 1.6.4 tutorial on creating a custom furnace - it's all still quite pertinent and mostly the same in 1.7.2.
World.spawnEntityInWorld(droppedItem);
super.breakBlock(World, x, y, z, id, meta);
}
}
}
}
sorry for the trouble lol but like i said i havent ventured much into machines code apart from creating new blocks with vanilla code, never tried to make a machine or container before so i have no clue about the whole block class for furnace like things
public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
{
if (!field_149934_M)
{
TileEntityFurnace tileentityfurnace = (TileEntityFurnace)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
if (tileentityfurnace != null)
{
for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1)
{
ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
if (itemstack != null)
{
float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int j1 = this.field_149933_a.nextInt(21) + 10;
if (j1 > itemstack.stackSize)
{
j1 = itemstack.stackSize;
}
public static void updateCoffeeMachineState(boolean p_149931_0_, World p_149931_1_, int p_149931_2_, int p_149931_3_, int p_149931_4_)
{
int l = p_149931_1_.getBlockMetadata(p_149931_2_, p_149931_3_, p_149931_4_);
TileEntity tileentity = p_149931_1_.getTileEntity(p_149931_2_, p_149931_3_, p_149931_4_);
field_149934_M = true;
@Override
public TileEntity createNewTileEntity(World world, int i) {
return new TileEntityCoffeeMachine();
}
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (par1World.isRemote)
{
the issue was nothing to do with my block class, nothing to do with the @Override or the "@Override
public void updateEntity()"
method ...... it was simply me being an idiot and putting ModBlocks.CoffeeMaker where i should of put "ModBlockCoffeeMaker" in the line
to put it in context i register localize and set creative tab in the class ModBlocks and almost everywhere i reference a block as ModBlocks.WhateverBlock LOL so i made blonde mistake when trying to adapt the code
but thank you for helping anyway coolALIAS you in fact raised the problem of my Block class
hey just an update on before for anyone else who wants to have a DERP moment like me...
~snip~
Heh, those are the worst and the best mistakes to have
In your breakBlock method, however, you will want to either copy the vanilla furnace code directly, or just look for how it uses "field_149934_M" within and replicate that in yours (that's "keepInventory", btw, if you wanted to use a readable name).
thanks! but i decided to replace the class entirely with the vanilla code and adapt it to my needs it works great now no bugs throughout the whole mod except one
in the container class, where you had "
else if (itemstack1 == ArcaneInscriber.Blank_Scroll.ItemID)
{
if (!this.mergeItemStack(itemstack1, BLANK_SCROLL, BLANK_SCROLL+1, false))
{
return null;
}
}
"
i changed "ArcaneInscriber.Blank_Scroll.ItemID" to ModItems.Empty_Mug.ItemID but there is an error on "ItemID" ive tried deleting it no luck :/ i assume its a 1.6.2 to 1.7.2 update that causes the error cause its done differently
error is itemID cannot be resolved or is not a field
thanks! but i decided to replace the class entirely with the vanilla code and adapt it to my needs it works great now no bugs throughout the whole mod except one
in the container class, where you had "
else if (itemstack1 == ArcaneInscriber.Blank_Scroll.ItemID)
{
if (!this.mergeItemStack(itemstack1, BLANK_SCROLL, BLANK_SCROLL+1, false))
{
return null;
}
}
"
i changed "ArcaneInscriber.Blank_Scroll.ItemID" to ModItems.Empty_Mug.ItemID but there is an error on "ItemID" ive tried deleting it no luck :/ i assume its a 1.6.2 to 1.7.2 update that causes the error cause its done differently
error is itemID cannot be resolved or is not a field
That should be "else if (itemstack1.itemID == ArcaneLegacy.scrollBlank.itemID)", not just "itemstack1 == ..."
But anyway, yes, the itemID (and blockID) has been removed in 1.7; I thought everyone was aware of that... the solution is usually just to replace it with something like "ItemStack.getItem() == YourMod.someItem".
ok everything works great now my machine now shows slots as i add or remove them so its all sorted but the recipe file isnt working at all for 1.7.2, ive found an open source recipe file but it only works for 2 inputs that i have very slightly modified to fit the machine im working with but i just cannot get it to add any more than two inputs, i dont know much about hash maps so im no use
public class CoffeeMachineRecipes
{
private static final CoffeeMachineRecipes instance = new CoffeeMachineRecipes();
private HashMap<List<Integer>, ItemStack> Recipes = new HashMap<List<Integer>, ItemStack>();
public static final CoffeeMachineRecipes instance()
{
return instance;
}
/**
* Registers a recipes for the squeezer (the main item will always be a coffee mug)
*
* @param Input_1 input item number 1
* @param Input_2 input item number 2
* @param Input_2 input item number 3
* @param Output the recipes output
*/
public void AddRecipe(ItemStack Input, ItemStack Input1, ItemStack Output)
{
/**
* Gets the result for a recipe in the coffee maker
*
* @param item_1 input item number 1
* @param item_2 input item number 2
* @param item_2 input item number 3
* @param item_4
* @return the result (null if nothing)
*/
public ItemStack GetResult(ItemStack item_1, ItemStack item_2, ItemStack item_3, ItemStack item_4)
{
Same way as I showed in the tutorial, but if you want it extensible to any number of inputs, then I recommend putting the output stack as the first parameter. Then you can do something like this:
public void addRecipe(ItemStack output, ItemStack... inputs) {
List<Integer> inputData = new ArrayList<Integer>();
for (ItemStack stack : inputs) {
// update to 1.7.2 by using Item.getIdFromItem(stack.getItem())
inputData.add(stack.itemID);
inputData.add(stack.getItemDamage());
}
metaInfusingList.put(inputData, output);
}
public ItemStack getRecipe(ItemStack... inputs) {
List<Integer> inputData = new ArrayList<Integer>();
for (ItemStack stack : inputs) {
// update to 1.7.2 by using Item.getIdFromItem(stack.getItem())
inputData.add(stack.itemID);
inputData.add(stack.getItemDamage());
}
return metaInfusingList.get(inputData);
}
In Java, Object... args can take any number of Objects and place them into an array; by saying "ItemStack... inputs" we limit the Object type to ItemStack, so it gives an array of ItemStacks that can then be iterated through, automating the process of adding all the IDs and damage values (and stack size too if you want) to the List of Integers that is used as the HashMap key for the output.
This isn't limited to my preference for using List<Integer>, either; you could do exactly the same thing using Maxcloud's suggestion of implementing hashcode and equals for ItemStacks if you wanted.
how would an "public ItemStack getResults(ItemStack output)" method look like ?
sorry for the billion questions and thank you for the billion answers, im kinda new to this stuff... thanks to you and tm1990x from misc items and blocks taking the time to speak to me and show me things, ive learnt how to create 70% of the content most mods make ill be sure to credit you appropriately when i release my mod
this is how ive seen one can get a result (this method is from tileentity class) but there isnt a get result method in my recipe class so im not sure how to substitute or create it
this is how ive seen one can get a result (this method is from tileentity class) but there isnt a get result method in my recipe class so im not sure how to substitute or create it
If a method doesn't exist, you can just create it. The method I wrote above "getRecipe" does the same thing as "getResult"; the name is not so important as the function, though it's good to have names that match the function. "getResult" is probably a better name than "getRecipe", since it's not returning a recipe but the result of said recipe. Just change the name of my method above and you've got what you need for as many inputs as you throw at it.
hmm if thats the case then i have no clue why the machine isnt doing anything... ive set up a new recipe, but when i put said recipe into the machine nothing happens at all it just sits there i thought it may of been what i just asked about but its obviously not so im not sure then
hmm if thats the case then i have no clue why the machine isnt doing anything... ive set up a new recipe, but when i put said recipe into the machine nothing happens at all it just sits there i thought it may of been what i just asked about but its obviously not so im not sure then
If it's not working, that's typically the result of a logic error somewhere - often some of the more troublesome errors to find. Best place to start looking is your TileEntity's onUpdate method; follow all the steps as they go and see if you can't find where it breaks.
I've a question on the logic behind these sort of machines.
I have my own code to merge the outputted product with what's already in the output slots, it's actually smart and will skip over an empty slot to see if any other slots could be added to.
But there is one problem I need to solve.
What happens when the outputted product is multiple items, and the machine is near full ?
eg output is:
A + A
or A + B
and there is only space for on of A
Only thought I have is to make a temp copy of the inv ItemStacks, and only copy it to the real one if there is no overflow.
Is there another way to cope with this sort of thing ?
Only thought I have is to make a temp copy of the inv ItemStacks, and only copy it to the real one if there is no overflow.
Is there another way to cope with this sort of thing ?
You don't need to do any copying if you check first that the full transaction can occur, so in your A+B with only one A slot open scenario, the machine checks and realizes that there is only one A slot open which is insufficient to process the input, and thus the machine stops.
But really, the logic of your machine is whatever you make it to be - there is no template for that sort of thing
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
There's no @Override above :/
I can post my actual tile entity class if you need
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIn your Block class, did you create a method to update the 'furnace' state? e.g. from idle to active? If you've ever made a Furnace-type block before, you should already be familiar with that.
In your TileEntity class, there absolutely SHOULD be @Override above the updateEntity method; in Java, case matters. UpdateEntity is NOT the same as updateEntity.
{
int l = p_149931_1_.getBlockMetadata(p_149931_2_, p_149931_3_, p_149931_4_);
TileEntity tileentity = p_149931_1_.getTileEntity(p_149931_2_, p_149931_3_, p_149931_4_);
field_149934_M = true;
if (p_149931_0_)
{
p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Blocks.lit_furnace);
}
else
{
p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Blocks.furnace);
}
field_149934_M = false;
p_149931_1_.setBlockMetadataWithNotify(p_149931_2_, p_149931_3_, p_149931_4_, l, 2);
if (tileentity != null)
{
tileentity.validate();
p_149931_1_.setTileEntity(p_149931_2_, p_149931_3_, p_149931_4_, tileentity);
}
}
if you or anyone is able to provide the method for me deobfuscated i would really apreciate it
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumLol, yeah, that sure is an eyesore. The parameters are exactly the same as they were in 1.6.4:
The first parameter is what determines the block to place: lit or unlit; the rest are pretty self-explanatory. All the method does is get the block's metadata, get the tile entity, then set "keepInventory" to true. This is important because calling setBlock will "break" the block currently there, and "keepInventory" determines whether or not to spill all the contents. So now the block gets set to either the lit or unlit furnace based on the first parameter, keepInventory is set back to false so other blocks will work properly, and the metadata and tile entity for the "new" block are set with the correct values. Finally, it validates the tile entity.
Basically you just copy that exact code into your Block class, change the name if you want, and make sure to account for "keepInventory" in your Block's breakBlock method. If you need more explanations and have some time, I recommend checking out pretty much any 1.6.4 tutorial on creating a custom furnace - it's all still quite pertinent and mostly the same in 1.7.2.
public void breakBlock(World World, int x, int y, int z, Block id, int meta)
{
TileEntity tile = World.getTileEntity(x, y, z);
if(tile != null && tile instanceof IInventory){
IInventory inv = (IInventory)tile;
for(int i = 0; i < inv.getSizeInventory(); i++){
ItemStack stack = inv.getStackInSlotOnClosing(i);
if(stack != null){
float spawnX = x + World.rand.nextFloat();
float spawnY = y + World.rand.nextFloat();
float spawnZ = z + World.rand.nextFloat();
EntityItem droppedItem = new EntityItem(World, spawnX, spawnY, spawnZ, stack);
float mult = 0.05F;
droppedItem.motionX = (-0.5 + World.rand.nextFloat()) * mult;
droppedItem.motionY = (4 + World.rand.nextFloat()) * mult;
droppedItem.motionZ = (-0.5 + World.rand.nextFloat()) * mult;
World.spawnEntityInWorld(droppedItem);
super.breakBlock(World, x, y, z, id, meta);
}
}
}
}
{
if (!field_149934_M)
{
TileEntityFurnace tileentityfurnace = (TileEntityFurnace)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
if (tileentityfurnace != null)
{
for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1)
{
ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
if (itemstack != null)
{
float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int j1 = this.field_149933_a.nextInt(21) + 10;
if (j1 > itemstack.stackSize)
{
j1 = itemstack.stackSize;
}
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(p_149749_1_, (double)((float)p_149749_2_ + f), (double)((float)p_149749_3_ + f1), (double)((float)p_149749_4_ + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
float f3 = 0.05F;
entityitem.motionX = (double)((float)this.field_149933_a.nextGaussian() * f3);
entityitem.motionY = (double)((float)this.field_149933_a.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double)((float)this.field_149933_a.nextGaussian() * f3);
p_149749_1_.spawnEntityInWorld(entityitem);
}
}
}
p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
}
}
super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
}
you wouldnt by any chance have your block class handy would you ? :/
this is my whole block class (be warned its probably atrocious and completely wrong)
import java.util.Random;
import com.MCR.MinecraftReloaded.Blocks.Machines.TileEntityCoffeeMachine;
import com.MCR.MinecraftReloaded.Blocks.Machines.TileEntityCoffeeMaker;
import com.MCR.MinecraftReloaded.Main.MinecraftReloaded;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
public class ModBlockCoffeeMachine extends BlockContainer{
private final Random field_149933_a = new Random();
private static boolean field_149934_M;
@SideOnly(Side.CLIENT)
private IIcon field_149935_N;
@SideOnly(Side.CLIENT)
private IIcon field_149936_O;
private static final String __OBFID = "CL_00000248";
protected ModBlockCoffeeMachine() {
super(Material.iron);
}
public static void updateCoffeeMachineState(boolean p_149931_0_, World p_149931_1_, int p_149931_2_, int p_149931_3_, int p_149931_4_)
{
int l = p_149931_1_.getBlockMetadata(p_149931_2_, p_149931_3_, p_149931_4_);
TileEntity tileentity = p_149931_1_.getTileEntity(p_149931_2_, p_149931_3_, p_149931_4_);
field_149934_M = true;
if (p_149931_0_)
{
p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Blocks.lit_furnace);
}
else
{
p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Blocks.furnace);
}
field_149934_M = false;
p_149931_1_.setBlockMetadataWithNotify(p_149931_2_, p_149931_3_, p_149931_4_, l, 2);
if (tileentity != null)
{
tileentity.validate();
p_149931_1_.setTileEntity(p_149931_2_, p_149931_3_, p_149931_4_, tileentity);
}
}
@Override
public TileEntity createNewTileEntity(World world, int i) {
return new TileEntityCoffeeMachine();
}
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (par1World.isRemote)
{
return true;
}
else
{
FMLNetworkHandler.openGui(par5EntityPlayer, MinecraftReloaded.instance, 0, par1World, par2, par3, par4);
return true;
}
}
public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
{
return Item.getItemFromBlock(ModBlocks.CoffeeMachine);
}
@Override
public void breakBlock(World World, int x, int y, int z, Block id, int meta)
{
TileEntity tile = World.getTileEntity(x, y, z);
if(tile != null && tile instanceof IInventory){
IInventory inv = (IInventory)tile;
for(int i = 0; i < inv.getSizeInventory(); i++){
ItemStack stack = inv.getStackInSlotOnClosing(i);
if(stack != null){
float spawnX = x + World.rand.nextFloat();
float spawnY = y + World.rand.nextFloat();
float spawnZ = z + World.rand.nextFloat();
EntityItem droppedItem = new EntityItem(World, spawnX, spawnY, spawnZ, stack);
float mult = 0.05F;
droppedItem.motionX = (-0.5 + World.rand.nextFloat()) * mult;
droppedItem.motionY = (4 + World.rand.nextFloat()) * mult;
droppedItem.motionZ = (-0.5 + World.rand.nextFloat()) * mult;
World.spawnEntityInWorld(droppedItem);
super.breakBlock(World, x, y, z, id, meta);
}
}
}
}
}
for my earlier issue
{
flag1 = true;
ModBlockCoffeeMachine.updateCoffeeMachineState(this.currentBrewTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
the issue was nothing to do with my block class, nothing to do with the @Override or the "@Override
public void updateEntity()"
method ...... it was simply me being an idiot and putting ModBlocks.CoffeeMaker where i should of put "ModBlockCoffeeMaker" in the line
{
flag1 = true;
ModBlockCoffeeMachine.updateCoffeeMachineState(this.currentBrewTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
to put it in context i register localize and set creative tab in the class ModBlocks and almost everywhere i reference a block as ModBlocks.WhateverBlock LOL so i made blonde mistake when trying to adapt the code
but thank you for helping anyway coolALIAS you in fact raised the problem of my Block class
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumHeh, those are the worst and the best mistakes to have
In your breakBlock method, however, you will want to either copy the vanilla furnace code directly, or just look for how it uses "field_149934_M" within and replicate that in yours (that's "keepInventory", btw, if you wanted to use a readable name).
in the container class, where you had "
else if (itemstack1 == ArcaneInscriber.Blank_Scroll.ItemID)
{
if (!this.mergeItemStack(itemstack1, BLANK_SCROLL, BLANK_SCROLL+1, false))
{
return null;
}
}
"
i changed "ArcaneInscriber.Blank_Scroll.ItemID" to ModItems.Empty_Mug.ItemID but there is an error on "ItemID" ive tried deleting it no luck :/ i assume its a 1.6.2 to 1.7.2 update that causes the error cause its done differently
error is itemID cannot be resolved or is not a field
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThat should be "else if (itemstack1.itemID == ArcaneLegacy.scrollBlank.itemID)", not just "itemstack1 == ..."
But anyway, yes, the itemID (and blockID) has been removed in 1.7; I thought everyone was aware of that... the solution is usually just to replace it with something like "ItemStack.getItem() == YourMod.someItem".
Thanks though
import net.minecraft.item.ItemStack;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import com.MCR.MinecraftReloaded.Items.ModItemEmpty_Mug;
public class CoffeeMachineRecipes
{
private static final CoffeeMachineRecipes instance = new CoffeeMachineRecipes();
private HashMap<List<Integer>, ItemStack> Recipes = new HashMap<List<Integer>, ItemStack>();
public static final CoffeeMachineRecipes instance()
{
return instance;
}
/**
* Registers a recipes for the squeezer (the main item will always be a coffee mug)
*
* @param Input_1 input item number 1
* @param Input_2 input item number 2
* @param Input_2 input item number 3
* @param Output the recipes output
*/
public void AddRecipe(ItemStack Input, ItemStack Input1, ItemStack Output)
{
Recipes.put(Arrays.asList(Input.getItem().getIdFromItem(Input.getItem()), Input.getItemDamage()), Output);
}
/**
* Gets the result for a recipe in the coffee maker
*
* @param item_1 input item number 1
* @param item_2 input item number 2
* @param item_2 input item number 3
* @param item_4
* @return the result (null if nothing)
*/
public ItemStack GetResult(ItemStack item_1, ItemStack item_2, ItemStack item_3, ItemStack item_4)
{
if(item_1 == null || item_2 == null || item_3 == null || item_4 == null)
{
return null;
}
if(item_1.getItem() instanceof ModItemEmpty_Mug){
ItemStack result = (ItemStack)Recipes.get(Arrays.asList(item_2.getItem().getIdFromItem(item_2.getItem()), item_2.getItemDamage()));
return result;
}
return null;
}
}
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumpublic void addRecipe(ItemStack output, ItemStack... inputs) { List<Integer> inputData = new ArrayList<Integer>(); for (ItemStack stack : inputs) { // update to 1.7.2 by using Item.getIdFromItem(stack.getItem()) inputData.add(stack.itemID); inputData.add(stack.getItemDamage()); } metaInfusingList.put(inputData, output); } public ItemStack getRecipe(ItemStack... inputs) { List<Integer> inputData = new ArrayList<Integer>(); for (ItemStack stack : inputs) { // update to 1.7.2 by using Item.getIdFromItem(stack.getItem()) inputData.add(stack.itemID); inputData.add(stack.getItemDamage()); } return metaInfusingList.get(inputData); }In Java, Object... args can take any number of Objects and place them into an array; by saying "ItemStack... inputs" we limit the Object type to ItemStack, so it gives an array of ItemStacks that can then be iterated through, automating the process of adding all the IDs and damage values (and stack size too if you want) to the List of Integers that is used as the HashMap key for the output.
This isn't limited to my preference for using List<Integer>, either; you could do exactly the same thing using Maxcloud's suggestion of implementing hashcode and equals for ItemStacks if you wanted.
sorry for the billion questions and thank you for the billion answers, im kinda new to this stuff... thanks to you and tm1990x from misc items and blocks taking the time to speak to me and show me things, ive learnt how to create 70% of the content most mods make
{
if(this.getStackInSlot(0) != null && this.getStackInSlot(1) != null){
ItemStack finiem = CoffeeMachineRecipes.instance().getResult(getStackInSlot(0), getStackInSlot(1));
if(finiem != null){
if(WorkTime >= FinishTime){
WorkTime = 0;
if(finiem != null){
this.decrStackSize(0, 1);
this.decrStackSize(1, 1);
if(this.getStackInSlot(2) == null || Inv[2].stackSize <= 0){
this.setInventorySlotContents(2, finiem);
}else{
Inv[2].stackSize = Inv[2].stackSize + 1;
}
}
}else{
WorkTime++;
}
}else{
WorkTime = 0;
}
}else{
WorkTime = 0;
}
}
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf a method doesn't exist, you can just create it. The method I wrote above "getRecipe" does the same thing as "getResult"; the name is not so important as the function, though it's good to have names that match the function. "getResult" is probably a better name than "getRecipe", since it's not returning a recipe but the result of said recipe. Just change the name of my method above and you've got what you need for as many inputs as you throw at it.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf it's not working, that's typically the result of a logic error somewhere - often some of the more troublesome errors to find. Best place to start looking is your TileEntity's onUpdate method; follow all the steps as they go and see if you can't find where it breaks.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumI have my own code to merge the outputted product with what's already in the output slots, it's actually smart and will skip over an empty slot to see if any other slots could be added to.
But there is one problem I need to solve.
What happens when the outputted product is multiple items, and the machine is near full ?
eg output is:
A + A
or A + B
and there is only space for on of A
Only thought I have is to make a temp copy of the inv ItemStacks, and only copy it to the real one if there is no overflow.
Is there another way to cope with this sort of thing ?
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYou don't need to do any copying if you check first that the full transaction can occur, so in your A+B with only one A slot open scenario, the machine checks and realizes that there is only one A slot open which is insufficient to process the input, and thus the machine stops.
But really, the logic of your machine is whatever you make it to be - there is no template for that sort of thing