Jump to content

[1.12.2] Help with furnace issue


Recommended Posts

I've been messing around with modding on forge a lot today and wanted to make some enchantments. I've made bukkit plugins for a long time so it was a bit of a change and the stuff i'm making has been working as intended until this. I made an enchantment to smelt ores that dropped anything containing the name "Ore". The issue is after I apply fortune to that enchantment the furnace gets updated to also smelt to the last amount dropped. For instance: I mine a gold ore with the "smelting" enchantment on it and it decides weather to give me a fortune bonus or not. Lets say it does and it gives me 3 gold ingots instead of one. If I go to the furnace and smelt a gold ore after this it will also give me 3. I'm lost as to why though.

Here's my code: 

public class SmelterEnchantmentListener {
	public static void onBlockHarvest(HarvestDropsEvent event) {
		if(event.getHarvester() != null) {
			boolean triggered_smelting = false;
			ItemStack held_item = event.getHarvester().getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
			if(held_item != null && held_item.getItem() instanceof ItemPickaxe && EnchantmentUtil.doesItemHaveEnchantment(held_item, DodRegistry.ENCHANTMENT_SMELTING)) {
				for(ItemStack drop : event.getDrops()) {
					if(drop.getDisplayName().contains("Ore")) {
						ItemStack smelted = FurnaceRecipes.instance().getSmeltingResult(drop);
						if(smelted != null) {
							if(DomainOfDagon.DEBUG_MODE) { event.getHarvester().sendMessage(new TextComponentString("Smelted Item: " + drop.getDisplayName())); }
							if(EnchantmentUtil.doesItemHaveEnchantment(held_item, Enchantments.FORTUNE)) {
								int fortune_bonus = new Random().nextInt(event.getFortuneLevel()) + 1;
								if(DomainOfDagon.DEBUG_MODE) { event.getHarvester().sendMessage(new TextComponentString("Fortune Modified Count: " + fortune_bonus)); }
							int xpAmmount = Math.round(FurnaceRecipes.instance().getSmeltingExperience(smelted));
							if(DomainOfDagon.DEBUG_MODE) { event.getHarvester().sendMessage(new TextComponentString("Dropping Smelted Xp: " + xpAmmount)); }
							ItemStack chestplate = event.getHarvester().getItemStackFromSlot(EntityEquipmentSlot.CHEST);
							if(chestplate != null && EnchantmentUtil.doesItemHaveEnchantment(chestplate, DodRegistry.ENCHANTMENT_GEOLOGY)) {
								if(new Random().nextInt(100) < 25) {//25% Chance to trigger
									int newXP = xpAmmount * EnchantmentUtil.getEnchantmentLevel(chestplate, DodRegistry.ENCHANTMENT_GEOLOGY);
									if(DomainOfDagon.DEBUG_MODE) { event.getHarvester().sendMessage(new TextComponentString("Geology enchantment triggered. {OldXP: " + xpAmmount + ", NewXP: " + newXP + "}")); }
									xpAmmount = newXP;
							event.getWorld().spawnEntity(new EntityXPOrb(event.getWorld(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), xpAmmount));
							triggered_smelting = true;
				if(DomainOfDagon.DEBUG_MODE && triggered_smelting) { event.getHarvester().sendMessage(new TextComponentString("Smelter enchantment triggered.")); }


Link to comment
Share on other sites

This topic is now closed to further replies.


  • Create New...

Important Information

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