Jump to content

[1.7.10] Weird bug with event.drops


AdamRobero

Recommended Posts

Hi all!

 

So last night, I received some help on another forum creating an auto-smelt enchantment. What currently happens with the enchantment is that if you mine a block with a smelting recipe, it'll only drop the smelted result. However, this only works the first time you use the enchantment on a block. What I mean is that if you mine a block of Gold Ore with auto-smelt, it'll drop a Gold Ingot. Then you could go and mine an Iron Ore and it would drop an Iron Ingot. If you were to then mine Gold Ore again, nothing would be dropped at all. Here is the event code (apologies, couldn't get the code button to work):

 

package SkyeStark.Rhencraft.main;

 

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

import net.minecraft.enchantment.EnchantmentHelper;

import net.minecraft.init.Items;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.FurnaceRecipes;

import net.minecraftforge.event.world.BlockEvent;

import scala.actors.threadpool.Arrays;

 

public class AutoSmelt {

 

int j = 0;

int i;

 

@SubscribeEvent

public void onHarvestDrops(BlockEvent.HarvestDropsEvent event)

{

System.out.println(event.drops);

System.out.println("Event has started");

 

if(event.harvester != null){

System.out.println("Harvester exists");

ItemStack heldItem = event.harvester.inventory.getCurrentItem();

 

if (heldItem != null && heldItem.getItem() == MainClass.toolRheniumPickaxe)

{

System.out.println("Found Pickaxe");

int enchantmentLevel = EnchantmentHelper.getEnchantmentLevel(MainClass.autoSmelt.effectId, heldItem);

 

if (enchantmentLevel > 0 && event.harvester.inventory.hasItem(Items.coal))

{

System.out.println("Level is more than 0");

ItemStack smelted = FurnaceRecipes.smelting().getSmeltingResult(new ItemStack(event.block).copy());

 

if (smelted != null)

{

 

System.out.println("" + smelted + " will be added to the drops");

event.drops.clear();

j = j + 1;

 

if(j >= 8){

 

j = 0;

event.harvester.inventory.consumeInventoryItem(Items.coal);

 

}

System.out.println("J is equal to " + j);

event.drops.add(smelted);

 

}

}

}

}

 

}

}

 

There is no reason why the smelted item should not be dropped, is there?

Link to comment
Share on other sites

You have a lot of debug statements in there.  When you mine a block and it doesn't drop the right thing, what does the console say?

 

(Also, what is the name of your enchantment? This is for purposes unrelated to your bug.  e.g. whatever you pass to

setName()

in your enchantment 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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