Jump to content

Hackbaellchen

Members
  • Posts

    111
  • Joined

  • Last visited

Everything posted by Hackbaellchen

  1. So should I check in the container, if the items are a recipe?
  2. Because I need it for the crafting recipes. The container checks if the items are arranged as the recipes added in the constructor. Where do I have to call this? EDIT: I override the method on slot click in the container class.
  3. I added this to my constructor: public MyCraftingManager() { try { Constructor<CraftingManager> constructor = CraftingManager.class.getDeclaredConstructor(new Class[0]); constructor.setAccessible(true); CraftingManager cm = constructor.newInstance(new Object[0]); } catch (Exception e) { e.printStackTrace(); } } Should I do now cm.addRecipe instead of calling my copied method? This works, but now I can craft vanilla items too and the bigger problem is that the items are still not consumed...
  4. Yes, I just want my recipes to be crafted just in my workbench.. Could you explain that?
  5. Hey, I've got my own crafting table, with it's Gui and container. I want the crafting recipes of my mod just to be crafted in the mod's workbench. So I created my own CraftingManager and used this method in my container class: @Override public void onCraftMatrixChanged(IInventory inventoryIn) { this.craftResult.setInventorySlotContents(0, MyCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); } I copied all methods from the CraftingManager to my own one and added my recipes. When I put the items in the correct shape, the result is displayed and I can take it out, but the items in the 3x3 slots are still there. I can take tons of result items, because they are not consumed. I also tried to use the forge CraftingManager. Then all works fine... I don't know what's wrong MyCraftingManager.class (I copied all methods from the original CraftingManager): public class MyCraftingManager { private static final MyCraftingManagerinstance = new MyCraftingManager(); private final List recipes = Lists.newArrayList(); public static MyCraftingManagergetInstance() { return instance; } private MyCraftingManager() { addRecipe(new ItemStack(MyBlocks.MyBlock, 2), new Object[] { "111", "111", "111", '1', Blocks.cobblestone }); Collections.sort(this.recipes, new Comparator() { public int compare(IRecipe rec1, IRecipe rec2) { return rec1 instanceof ShapelessRecipes && rec2 instanceof ShapedRecipes ? 1 : (rec2 instanceof ShapelessRecipes && rec1 instanceof ShapedRecipes ? -1 : (rec2.getRecipeSize() < rec1.getRecipeSize() ? -1 : (rec2.getRecipeSize() > rec1.getRecipeSize() ? 1 : 0))); } public int compare(Object rec1, Object rec2) { return this.compare((IRecipe) rec1, (IRecipe) rec2); } }); } public ShapedRecipes addRecipe(ItemStack stack, Object... recipeComponents) { String s = ""; int i = 0; int j = 0; int k = 0; if (recipeComponents[i] instanceof String[]) { String[] astring = (String[]) ((String[]) recipeComponents[i++]); for (int l = 0; l < astring.length; ++l) { String s1 = astring[l]; ++k; j = s1.length(); s = s + s1; } } else { while (recipeComponents[i] instanceof String) { String s2 = (String) recipeComponents[i++]; ++k; j = s2.length(); s = s + s2; } } HashMap hashmap; for (hashmap = Maps.newHashMap(); i < recipeComponents.length; i += 2) { Character character = (Character) recipeComponents[i]; ItemStack itemstack1 = null; if (recipeComponents[i + 1] instanceof Item) { itemstack1 = new ItemStack((Item) recipeComponents[i + 1]); } else if (recipeComponents[i + 1] instanceof Block) { itemstack1 = new ItemStack((Block) recipeComponents[i + 1], 1, 32767); } else if (recipeComponents[i + 1] instanceof ItemStack) { itemstack1 = (ItemStack) recipeComponents[i + 1]; } hashmap.put(character, itemstack1); } ItemStack[] aitemstack = new ItemStack[j * k]; for (int i1 = 0; i1 < j * k; ++i1) { char c0 = s.charAt(i1); if (hashmap.containsKey(Character.valueOf(c0))) { aitemstack[i1] = ((ItemStack) hashmap.get(Character.valueOf(c0))).copy(); } else { aitemstack[i1] = null; } } ShapedRecipes shapedrecipes = new ShapedRecipes(j, k, aitemstack, stack); this.recipes.add(shapedrecipes); return shapedrecipes; } public void addShapelessRecipe(ItemStack stack, Object... recipeComponents) { ArrayList arraylist = Lists.newArrayList(); Object[] aobject = recipeComponents; int i = recipeComponents.length; for (int j = 0; j < i; ++j) { Object object1 = aobject[j]; if (object1 instanceof ItemStack) { arraylist.add(((ItemStack) object1).copy()); } else if (object1 instanceof Item) { arraylist.add(new ItemStack((Item) object1)); } else { if (!(object1 instanceof Block)) { throw new IllegalArgumentException( "Invalid shapeless recipe: unknown type " + object1.getClass().getName() + "!"); } arraylist.add(new ItemStack((Block) object1)); } } this.recipes.add(new ShapelessRecipes(stack, arraylist)); } public void addRecipe(IRecipe recipe) { this.recipes.add(recipe); } public ItemStack findMatchingRecipe(InventoryCrafting inv, World world) { Iterator iterator = this.recipes.iterator(); IRecipe irecipe; do { if (!iterator.hasNext()) { return null; } irecipe = (IRecipe) iterator.next(); } while (!irecipe.matches(inv, world)); return irecipe.getCraftingResult(inv); } public ItemStack[] func_180303_b(InventoryCrafting inv, World world) { Iterator iterator = this.recipes.iterator(); while (iterator.hasNext()) { IRecipe irecipe = (IRecipe) iterator.next(); if (irecipe.matches(inv, world)) { return irecipe.getRemainingItems(inv); } } ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()]; for (int i = 0; i < aitemstack.length; ++i) { aitemstack[i] = inv.getStackInSlot(i); } return aitemstack; } public List getRecipeList() { return this.recipes; } } I think I has to do with this method, but I'm not really sure: public ItemStack[] func_180303_b(InventoryCrafting inv, World world) {}
  6. What do you want to achieve? I think he wants to give the entity hit by the projectile a potion effect.
  7. Yes, I forgot to set the bounds. But now, the border line is smaller (it disappeared). Can I set this manually without changing the bounds?
  8. This doesn't work, not with players, items, mobs.. The event seems not to be called..
  9. Hey, is there an event to detect when an item (e.g. a stick) hits a block (e.g. thrown by a player)? public class MyBlock extends Block { @Override public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) { System.out.println("collide event"); } } This works fine for players and animals/monsters, but not for items..
  10. With yours, I read 3 articles about the invisible TNT. http://www.minecraftforge.net/forum/index.php/topic,18036.0.html http://www.minecraftforge.net/forum/index.php/topic,31319.0.html I've got the same issue. Anyone on this forum must know why so many modders have exactly the same coding problem!
  11. Where did I forget it?? I allways use MyMod.MODID + ":MyBow" EDIT: Mistake found. Json files missed it.
  12. Hey, I want to create my own bow. Shooting works great, texturing not. The class extends ItemBow. getModel() method: @Override public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining) { String modid = MyMod.MODID; ModelResourceLocation mrl = new ModelResourceLocation(modid + ":MyBow", "inventory"); useRemaining = stack.getMaxItemUseDuration() - useRemaining; if (player.getItemInUse() != null) { if (useRemaining >= 18) { mrl = new ModelResourceLocation(modid + ":MyBow3", "inventory"); } else if (useRemaining > 13) { mrl = new ModelResourceLocation(modid + ":MyBow2", "inventory"); } else if (useRemaining > 0) { mrl = new ModelResourceLocation(modid + ":MyBow1", "inventory"); } } return mrl; } init() method: ModelBakery.addVariantName(MyItems.bow, MODID + ":MyBow", MODID + ":MyBow1", MODID + ":MyBow2", MODID + ":MyBow3"); And finally the error: The textures named can all be found in my resources folder! I hope you can help me.
  13. All works fine now. public class MyEntityProjectile extends EntityThrowable { public MyEntityProjectile(World par1World) { super(par1World); } public MyEntityProjectile(World par1World, EntityLivingBase par2EntityLivingBase) { super(par1World, par2EntityLivingBase); } public MyEntityProjectile(World par1World, double par2, double par4, double par6) { super(par1World, par2, par4, par6); } protected void onImpact(MovingObjectPosition movingobjectposition) { if (!this.worldObj.isRemote) { this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 4.5F, true); } } public class MyItem extends Item { public MyItem() { super(); this.setMaxDamage(50); this.setMaxStackSize(1); this.setFull3D(); } @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!world.isRemote) { world.spawnEntityInWorld(new MyEntityProjectile(world, player)); itemStack.damageItem(1, player); } return itemStack; } I've found my old code
  14. @EventHandler public void preInit(FMLPreInitializationEvent event) { EntityRegistry.registerModEntity(MyEntityProjectile.class, "MyProjectile", entityIndex++, this, 64, 10, true); } If I use public MyEntityProjectile(World world) { super(world); } instead of public MyEntityProjectile(World world, EntityLivingBase player) { super(world, player); } the entity isn't spawning.
  15. Like I told you before.. It looks like this:
  16. public class MyItem extends Item { public MyItem() { super(); this.setMaxDamage(50); this.setMaxStackSize(1); this.setFull3D(); } @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (world.isRemote) { world.spawnEntityInWorld(new MyEntityProjectile(world, player)); itemStack.damageItem(1, player); } return itemStack; } public class MyEntityProjectile extends EntityThrowable { public MyEntityProjectile(World world, EntityLivingBase entity) { super(world, entity); } public void onImpact(MovingObjectPosition movingobjectposition) { if (!this.worldObj.isRemote) { this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 4.5F, true); } } As it is now, there will be NO explosion on impact. If i remove the ! in the projectile class it will explode, but the blocks will be buggy
  17. !this.worldObj.isRemote It'll crash with the dirt background and 'Connection Lost' 'A fatal error has occured, this connection is terminatd'.
  18. @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (world.isRemote) { world.spawnEntityInWorld(new MyEntityProjectile(world, player)); itemStack.damageItem(1, player); } return itemStack; }
  19. I tried to use @SideOnly(Side.CLIENT) , but there was the same problem. I also tried public void onImpact(MovingObjectPosition movingobjectposition) { if(!this.worldObj.isRemote) { this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 4.5F, true); this.setDead(); } } but there was no explosion.
  20. Hey, I made a projectile and wanted it to explode on impact (I extended EntityThrowable). Code: protected void onImpact(MovingObjectPosition movingobjectposition) { this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 4.5F, true); this.setDead(); } But the blocks are buggy. If I fly into the crater there will be invisible blocks, which should be exploded.
  21. Look into the BlockOre.class. public int damageDropped(int p_149692_1_) { return this == Blocks.lapis_ore ? 4 : 0; } Means: If the block is a lapis ore block, the metadata will be set to 4.
  22. Hey, I want to create new horse armor. I had a look into the vanilla code and found something in the EntityHorse, but I won't edit that. Are there any ways to bypass it?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.