EmeraldJelly Posted April 5, 2018 Author Share Posted April 5, 2018 ok but the problem isnt exactly that, its not adding the items it recognizes to my list. The crash only happened when I threw on the items, otherwise, it didnt crash or do anything. Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 6, 2018 Share Posted April 6, 2018 Use the debugger. Quote 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 More sharing options...
EmeraldJelly Posted April 7, 2018 Author Share Posted April 7, 2018 On 4/5/2018 at 8:26 PM, Draco18s said: Use the debugger. Ok. I managed to get it working using the debugger.. Sort of. But the one issue that I have is that it does not go through the entire recipe, and it does not let me use the recipe twice, I assume because it still thinks it has more stuff in it but idk. Say the recipe calls for WAX and a SNOWBALL. Once I throw in the Wax, it instantly thinks its a complete recipe and outputs the correct item. That is not what I am aiming for. Here is my code, really would appreciate one last consultation to tell me what is going wrong because I cannot figure that out. Cauldron Recpies Spoiler package emeraldjelly.mystica.util.recipe.cauldron; import emeraldjelly.mystica.api.ICauldronRecipe; import emeraldjelly.mystica.blocks.tileentity.TileEntitySorcerersCauldron; import emeraldjelly.mystica.init.ModItems; import emeraldjelly.mystica.util.recipe.recipetypes.CauldronRecipe; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import paulscode.sound.ICodec; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class CauldronRecipes { public static void init() { RECIPES.add(EMPTYLACRIMA); } public static List<ICauldronRecipe> RECIPES = new ArrayList<ICauldronRecipe>(); public static final CauldronRecipe EMPTYLACRIMA = new CauldronRecipe(new ArrayList<Item> (Arrays.asList(ModItems.WAX, ModItems.LACRIMITESHARDS)), new ItemStack(ModItems.EMPTYLACRIAMA)); public static ItemStack getResult(List<Item> items) { for (ICauldronRecipe recipe : RECIPES) { if (items.isEmpty()) { return ItemStack.EMPTY; } if (recipe.matches(items)) { CauldronRecipe.items.clear(); if (recipe.getCraftingResult() != null) { TileEntitySorcerersCauldron.items.clear(); return new ItemStack(recipe.getCraftingResult().getItem()); } } } return ItemStack.EMPTY; } } TE Spoiler package emeraldjelly.mystica.blocks.tileentity; import emeraldjelly.mystica.api.ICauldronRecipe; import emeraldjelly.mystica.blocks.SorcerersCauldron; import emeraldjelly.mystica.util.recipe.cauldron.CauldronRecipes; import emeraldjelly.mystica.util.recipe.recipetypes.CauldronRecipe; import net.minecraft.client.Minecraft; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EntitySelectors; import net.minecraft.util.ITickable; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.items.ItemStackHandler; import org.lwjgl.Sys; import java.util.ArrayList; import java.util.List; public class TileEntitySorcerersCauldron extends TileEntity implements ITickable { //Do i need to Implement anything else? public static List<Item> items = new ArrayList<>(); private int cooldown; private ItemStackHandler handler; public TileEntitySorcerersCauldron() { this.cooldown = 0; this.handler = new ItemStackHandler(5); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setInteger("Cooldown", this.cooldown); compound.setTag("ItemStackHandler", this.handler.serializeNBT()); return super.writeToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { this.cooldown = compound.getInteger("Cooldown"); this.handler.deserializeNBT(compound.getCompoundTag("ItemStackHandler")); super.readFromNBT(compound); } @Override public void update() { this.cooldown++; this.cooldown %= 100; } public void onCollideAddItems(EntityItem item) { items.add(item.getItem().getItem()); item.setDead(); checkAndCraft(items); } public void checkAndCraft(List<Item> itemsList) { EntityItem entityItem = new EntityItem(world, Minecraft.getMinecraft().player.getPosition().getX(), Minecraft.getMinecraft().player.getPosition().getY(), Minecraft.getMinecraft().player.getPosition().getZ(), CauldronRecipes.getResult(itemsList)); spawnItem(entityItem); } public void spawnItem(EntityItem entityItem) { if (!world.isRemote) { Minecraft.getMinecraft().world.spawnEntity(entityItem); } } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); int metadata = getBlockMetadata(); return new SPacketUpdateTileEntity(this.pos, metadata, nbt); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { this.readFromNBT(pkt.getNbtCompound()); } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); return nbt; } @Override public void handleUpdateTag(NBTTagCompound tag) { this.readFromNBT(tag); } @Override public NBTTagCompound getTileData() { NBTTagCompound nbt = new NBTTagCompound(); this.writeToNBT(nbt); return nbt; } } Cauldron Recipe Spoiler package emeraldjelly.mystica.util.recipe.recipetypes; ; import emeraldjelly.mystica.api.ICauldronRecipe; import emeraldjelly.mystica.init.ModItems; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class CauldronRecipe implements ICauldronRecipe { //What am Missing in this class? Where do I make all of this code happen? public static ItemStack resultItem = ItemStack.EMPTY; public static List<Item> items = new ArrayList<Item>(); public CauldronRecipe(List<Item> items, ItemStack output) { this.resultItem = output; this.items = items; } @Override public boolean matches(List<Item> itemStacks) { List<Item> items1 = items; for (int i = 0; i < itemStacks.size(); i++) { Item itemstack = itemStacks.get(i); if (itemstack != null) { boolean flag = false; for (Item itemstack1 : items1) { if (itemstack == itemstack1 && ( itemstack1.getMetadata(new ItemStack(itemstack1)) == OreDictionary.WILDCARD_VALUE || itemstack.getMetadata(new ItemStack(itemstack)) == itemstack1.getMetadata(new ItemStack(itemstack1)))) { flag = true; itemStacks.remove(itemstack1); break; } } if (!flag) { return false; } } } return itemStacks.isEmpty(); } @Override public ItemStack getCraftingResult() { return resultItem; } } Block Class Spoiler package emeraldjelly.mystica.blocks; import emeraldjelly.mystica.blocks.tileentity.TileEntitySorcerersCauldron; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nullable; public class SorcerersCauldron extends BlockBase implements ITileEntityProvider { public static AxisAlignedBB AABB = new AxisAlignedBB(0, 0, 0, 1, 0.5625D, 1); public SorcerersCauldron(String name, Material material) { super(name, material); setHardness(3F); setResistance(3F); setHarvestLevel("pickaxe", 3); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntitySorcerersCauldron(); } @Override public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn); if (entityIn instanceof EntityItem) { TileEntitySorcerersCauldron tile = (TileEntitySorcerersCauldron) worldIn.getTileEntity(pos); tile.onCollideAddItems((EntityItem) entityIn); ((EntityItem) entityIn).lifespan = 0; } } @Override public boolean isTopSolid(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) { return AABB; } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return AABB; } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullBlock(IBlockState state) { return false; } public static AxisAlignedBB getAABB() { return AABB; } } Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 7, 2018 Share Posted April 7, 2018 21 minutes ago, EmeraldJelly said: List<Item> items1 = items; This is not how you clone a list. Both of these variables reference the SAME list: if you modify one... 22 minutes ago, EmeraldJelly said: itemStacks.remove(itemstack1); ...you modify the other. Plus, you aren't modifying the right list anyway. By removing any of the recipe items from the list given, you... 23 minutes ago, EmeraldJelly said: return itemStacks.isEmpty(); Which it is, as it contains zero items. But you didn't see the second item in the recipe! This is why it is so important to clone and modify the ingredients required list. Quote 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 More sharing options...
EmeraldJelly Posted April 7, 2018 Author Share Posted April 7, 2018 (edited) List<Item> items1 = ((List) ((ArrayList) items).clone()); Better? It still does the same thing. Edited April 7, 2018 by EmeraldJelly Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 7, 2018 Share Posted April 7, 2018 1 hour ago, Draco18s said: Plus, you aren't modifying the right list anyway. By removing any of the recipe items from the list given, you... 1 hour ago, EmeraldJelly said: return itemStacks.isEmpty(); Which it is, as it contains zero items. But you didn't see the second item in the recipe! This is why it is so important to clone and modify the ingredients required list. Quote 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 More sharing options...
EmeraldJelly Posted April 7, 2018 Author Share Posted April 7, 2018 (edited) 2 minutes ago, Draco18s said: itemStacks.remove(items1); return items1.isEmpty(); Edited April 7, 2018 by EmeraldJelly Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 7, 2018 Share Posted April 7, 2018 7 minutes ago, Draco18s said: you (still) aren't modifying the right list Quote 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 More sharing options...
EmeraldJelly Posted April 7, 2018 Author Share Posted April 7, 2018 (edited) oh shit my bad itemStacks.remove(itemStacks); Still doesn't work btw.. Edited April 7, 2018 by EmeraldJelly Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 7, 2018 Share Posted April 7, 2018 Hit the debugger again, try and figure out what piece of logic isn't doing what you expect. Quote 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 More sharing options...
EmeraldJelly Posted April 7, 2018 Author Share Posted April 7, 2018 46 minutes ago, Draco18s said: Hit the debugger again, try and figure out what piece of logic isn't doing what you expect. In the time it took you to respond I did, I still do not have any clue what it's doing, its being weird... Can't explain it.. Ill send the code that has changed. Spoiler package emeraldjelly.mystica.util.recipe.recipetypes; ; import emeraldjelly.mystica.api.ICauldronRecipe; import emeraldjelly.mystica.init.ModItems; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class CauldronRecipe implements ICauldronRecipe { //What am Missing in this class? Where do I make all of this code happen? public static ItemStack resultItem = ItemStack.EMPTY; public static List<Item> items = new ArrayList<Item>(); public CauldronRecipe(List<Item> items, ItemStack output) { this.resultItem = output; this.items = items; } @Override public boolean matches(List<Item> itemStacks) { List<Item> items1 = ((List) ((ArrayList) items).clone()); for (int i = 0; i < itemStacks.size(); i++) { Item itemstack = itemStacks.get(i); if (itemstack != null) { boolean flag = false; for (Item itemstack1 : items1) { if (itemstack == itemstack1 && ( itemstack1.getMetadata(new ItemStack(itemstack1)) == OreDictionary.WILDCARD_VALUE || itemstack.getMetadata(new ItemStack(itemstack)) == itemstack1.getMetadata(new ItemStack(itemstack1)))) { flag = true; itemStacks.remove(itemStacks); break; } } if (!flag) { return false; } } } return itemStacks.isEmpty(); } @Override public ItemStack getCraftingResult() { return resultItem; } } Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 7, 2018 Share Posted April 7, 2018 35 minutes ago, EmeraldJelly said: itemStacks.remove(itemStacks); 2 hours ago, Draco18s said: you (still) aren't modifying the right list Quote 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 More sharing options...
EmeraldJelly Posted April 7, 2018 Author Share Posted April 7, 2018 15 minutes ago, Draco18s said: What list then Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 8, 2018 Share Posted April 8, 2018 You remember the one you clone? You want to remove items from the clone, then check if you've removed everything. Quote 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 More sharing options...
EmeraldJelly Posted April 8, 2018 Author Share Posted April 8, 2018 (edited) Ok items1.remove(itemstack); Then return items1.isEmpty(); Still does not work. Edited April 8, 2018 by EmeraldJelly Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 8, 2018 Share Posted April 8, 2018 ItemStack does not override Equals or HashCode, so you need to remove the object that's actually in the list. itemstack1 Quote 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 More sharing options...
EmeraldJelly Posted April 8, 2018 Author Share Posted April 8, 2018 3 minutes ago, Draco18s said: ItemStack does not override Equals or HashCode, so you need to remove the object that's actually in the list. itemstack1 Yeah ok I did that, still does not work. Quote Link to comment Share on other sites More sharing options...
loordgek Posted April 8, 2018 Share Posted April 8, 2018 in the method checkAndCraft you do is client side that will not work the TileEntity already has the world and the pos. and for the recipe take a look at this NOTE this is code form 1.7.10 https://github.com/BCA-Team/Buildcraft-Additions/blob/2.2.x/src/main/java/buildcraftAdditions/recipe/refinery/RefineryRecipe.java https://github.com/BCA-Team/Buildcraft-Additions/blob/2.2.x/src/main/java/buildcraftAdditions/recipe/refinery/RefineryRecipeManager.java Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.