Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 {
	@SubscribeEvent
	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) {
							event.getDrops().remove(drop);
							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)); }
								smelted.setCount(fortune_bonus);
							}
							event.getDrops().add(smelted);
							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.")); }
			}
		}
	}
}

 

  • Author

Problem was this needed to be replaced

smelted.setCount(fortune_bonus);

with this 

smelted = new ItemStack(smelted.getItem(), fortune_bonus);

 

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.