Jump to content

Recommended Posts

Posted

In 1.8 I use an event handler to add functionality for an automatic smelting enchantment.

 

 

if (player != null && !player.capabilities.isCreativeMode && EnchantmentHelper.getEnchantmentLevel(this.effectId, player.getHeldItem()) > 0) {
HarvestDropsEvent event = (HarvestDropsEvent) baseEvent;
ItemStack drop = event.drops.size() == 0 ? null : event.drops.get(0);
if (drop != null) {
	ItemStack smeltStack = new ItemStack(drop.getItem(), 1, drop.getMetadata());
	ItemStack smeltResult = FurnaceRecipes.instance().getSmeltingResult(smeltStack);
	if (smeltResult != null) {
		smeltResult.stackSize *= drop.stackSize;
		event.drops.clear();
		event.drops.add(smeltResult);
	}
}
}

This code works only the first time breaking a certain block. After that, nothing drops. For example, the first time breaking an iron ore yielded one iron ingot. Tries after that all yielded nothing. This is done using the HarvestDropsEvent.

Maker of the Craft++ mod.

Posted

Always use itemStack.copy() when editing it. (stacks are mutable)

 

When pulling ItemStack from any kind of registry or something - 1st do something like ItemStack tempStack = stack.copy();

Also:

HarvestDropsEvent event = (HarvestDropsEvent) baseEvent;

Wtf? I really hope you are actually doing it as event, not like this.

And:

ItemStack drop = event.drops.size() == 0 ? null : event.drops.get(0);

drops can be bigger than just size==1 and then you do event.drops.clear(); which clears them all, kinda bad design in my opinion.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted
  On 6/28/2015 at 3:46 AM, Ernio said:

Always use itemStack.copy() when editing it. (stacks are mutable)

 

When pulling ItemStack from any kind of registry or something - 1st do something like ItemStack tempStack = stack.copy();

Also:

HarvestDropsEvent event = (HarvestDropsEvent) baseEvent;

Wtf? I really hope you are actually doing it as event, not like this.

And:

ItemStack drop = event.drops.size() == 0 ? null : event.drops.get(0);

drops can be bigger than just size==1 and then you do event.drops.clear(); which clears them all, kinda bad design in my opinion.

This is part of a method called from my event handler. I'll try the .copy() method out.

UPDATE: Worked like a charm! Thanks.

Maker of the Craft++ mod.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • i was playing a custom modpack and i cant open the world anymore.  here are the logs :  [15:28:31] [Server thread/ERROR]:Encountered an unexpected exception net.minecraftforge.fml.config.ConfigFileTypeHandler$ConfigLoadingException: Failed loading config file jei-server.toml of type SERVER for modid jei at net.minecraftforge.fml.config.ConfigFileTypeHandler.lambda$reader$1(ConfigFileTypeHandler.java:47) ~[fmlcore-1.20.1-47.4.0.jar%23305!/:?] at net.minecraftforge.fml.config.ConfigTracker.openConfig(ConfigTracker.java:60) ~[fmlcore-1.20.1-47.4.0.jar%23305!/:?] at net.minecraftforge.fml.config.ConfigTracker.lambda$loadConfigs$1(ConfigTracker.java:50) ~[fmlcore-1.20.1-47.4.0.jar%23305!/:?] at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] at java.util.Collections$SynchronizedCollection.forEach(Collections.java:2131) ~[?:?] at net.minecraftforge.fml.config.ConfigTracker.loadConfigs(ConfigTracker.java:50) ~[fmlcore-1.20.1-47.4.0.jar%23305!/:?] at net.minecraftforge.server.ServerLifecycleHooks.handleServerAboutToStart(ServerLifecycleHooks.java:96) ~[forge-1.20.1-47.4.0-universal.jar%23309!/:?] at net.minecraft.client.server.IntegratedServer.m_7038_(IntegratedServer.java:62) ~[client-1.20.1-20230612.114412-srg.jar%23304!/:?] at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:634) ~[client-1.20.1-20230612.114412-srg.jar%23304!/:?] at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[client-1.20.1-20230612.114412-srg.jar%23304!/:?] at java.lang.Thread.run(Thread.java:840) ~[?:?] Caused by: com.electronwill.nightconfig.core.io.ParsingException: Not enough data available at com.electronwill.nightconfig.core.io.ParsingException.notEnoughData(ParsingException.java:22) ~[core-3.6.4.jar%2393!/:?] at com.electronwill.nightconfig.core.io.ReaderInput.directReadChar(ReaderInput.java:36) ~[core-3.6.4.jar%2393!/:?] at com.electronwill.nightconfig.core.io.AbstractInput.readChar(AbstractInput.java:49) ~[core-3.6.4.jar%2393!/:?] at com.electronwill.nightconfig.core.io.AbstractInput.readCharsUntil(AbstractInput.java:123) ~[core-3.6.4.jar%2393!/:?] at com.electronwill.nightconfig.toml.TableParser.parseKey(TableParser.java:166) ~[toml-3.6.4.jar%2394!/:?] at com.electronwill.nightconfig.toml.TableParser.parseDottedKey(TableParser.java:145) ~[toml-3.6.4.jar%2394!/:?] at com.electronwill.nightconfig.toml.TableParser.parseNormal(TableParser.java:55) ~[toml-3.6.4.jar%2394!/:?] at com.electronwill.nightconfig.toml.TomlParser.parse(TomlParser.java:44) ~[toml-3.6.4.jar%2394!/:?] at com.electronwill.nightconfig.toml.TomlParser.parse(TomlParser.java:37) ~[toml-3.6.4.jar%2394!/:?] at com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:113) ~[core-3.6.4.jar%2393!/:?] at com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:219) ~[core-3.6.4.jar%2393!/:?] at com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:202) ~[core-3.6.4.jar%2393!/:?] at com.electronwill.nightconfig.core.file.WriteSyncFileConfig.load(WriteSyncFileConfig.java:73) ~[core-3.6.4.jar%2393!/:?] at com.electronwill.nightconfig.core.file.AutosaveCommentedFileConfig.load(AutosaveCommentedFileConfig.java:85) ~[core-3.6.4.jar%2393!/:?] at net.minecraftforge.fml.config.ConfigFileTypeHandler.lambda$reader$1(ConfigFileTypeHandler.java:43) ~[fmlcore-1.20.1-47.4.0.jar%23305!/:?] ... 10 more [15:28:31] [Server thread/FATAL]:Preparing crash report with UUID 2a3982ea-90f2-492d-85e7-f1cb63906dcb [15:28:31] [Server thread/ERROR]:This crash report has been saved to: C:\Users\gueri\curseforge\minecraft\Instances\modpack je sais pas\crash-reports\crash-2025-05-29_15.28.31-server.txt [15:28:31] [Server thread/INFO]:Stopping server [15:28:31] [Server thread/INFO]:Saving players [15:28:31] [Server thread/INFO]:Saving worlds [15:28:31] [Server thread/ERROR]:Exception stopping the server java.lang.NullPointerException: Cannot invoke "net.minecraft.server.level.ServerLevel.m_6857_()" because "serverlevel2" is null at net.minecraft.server.MinecraftServer.m_129885_(MinecraftServer.java:513) ~[client-1.20.1-20230612.114412-srg.jar%23304!/:?] at net.minecraft.server.MinecraftServer.m_7041_(MinecraftServer.java:584) ~[client-1.20.1-20230612.114412-srg.jar%23304!/:?] at net.minecraft.client.server.IntegratedServer.m_7041_(IntegratedServer.java:187) ~[client-1.20.1-20230612.114412-srg.jar%23304!/:?] at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:689) ~[client-1.20.1-20230612.114412-srg.jar%23304!/:?] at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[client-1.20.1-20230612.114412-srg.jar%23304!/:?] at java.lang.Thread.run(Thread.java:840) ~[?:?]
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • I recently updated my mods for prominence 2 and instead of opening like usual it just crashes. I already disable any incompatible mods and I don't know what to do. If anyone could help that would be nice. Thanks Latest log:https://mclo.gs/jsuIlZX
    • I dont know how I can elaborate more, just every time I try to create a new instance where its forge, its 1.20.1 and the forge version is 47.4.1 it doesnt work. Im really confused because it works for my friend he even showed it to me. This is on modrinth btw
  • Topics

×
×
  • Create New...

Important Information

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