Jump to content

[1.7.10] Making a autosmelt pickaxe


2FastAssassin

Recommended Posts

Im trying to make a autosmelt pickaxe and when ever i mine a bloc it crashes please help

 

Pickaxe:

 

package wearethewarriorsmod.tools;

 

import java.util.ArrayList;

 

import net.minecraft.block.Block;

import net.minecraft.enchantment.Enchantment;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.item.EntityItem;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemPickaxe;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.FurnaceRecipes;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.world.World;

 

public class dragonpickaxe extends ItemPickaxe {

 

public dragonpickaxe(ToolMaterial material) {

super(material);

}

 

@Override

public boolean onBlockDestroyed(ItemStack itemStack, World world,

Block block, int x, int y, int z, EntityLivingBase player) {

 

ItemStack stack = FurnaceRecipes.smelting()

.getSmeltingResult(new ItemStack(block)).copy();

 

if(world.isRemote){

return false;

}

 

if (stack != null) {

System.out.println(stack);

world.setBlockToAir(x, y, z);

player.entityDropItem(stack, 1);

 

}

 

return true;

 

}

}

 

 

Crash Report:

 

---- Minecraft Crash Report ----

// Hey, that tickles! Hehehe!

 

Time: 23/06/15 2:58 PM

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at wearethewarriorsmod.tools.dragonpickaxe.onBlockDestroyed(dragonpickaxe.java:29)

at net.minecraft.item.ItemStack.func_150999_a(ItemStack.java:381)

at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerDestroyBlock(PlayerControllerMP.java:169)

at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerDamageBlock(PlayerControllerMP.java:288)

at net.minecraft.client.Minecraft.func_147115_a(Minecraft.java:1428)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:2047)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028)

at net.minecraft.client.Minecraft.run(Minecraft.java:951)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at wearethewarriorsmod.tools.dragonpickaxe.onBlockDestroyed(dragonpickaxe.java:29)

at net.minecraft.item.ItemStack.func_150999_a(ItemStack.java:381)

at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerDestroyBlock(PlayerControllerMP.java:169)

at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerDamageBlock(PlayerControllerMP.java:288)

at net.minecraft.client.Minecraft.func_147115_a(Minecraft.java:1428)

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityClientPlayerMP['Player869'/291, l='MpServer', x=-129.55, y=80.62, z=130.25]]

Chunk stats: MultiplayerChunkCache: 280, 280

Level seed: 0

Level generator: ID 00 - default, ver 1. Features enabled: false

Level generator options:

Level spawn location: World: (-124,64,240), Chunk: (at 4,4,0 in -8,15; contains blocks -128,0,240 to -113,255,255), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Level time: 26273 game time, 33360 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false

Forced entities: 104 total; [EntitySpider['Spider'/63, l='MpServer', x=-209.63, y=19.00, z=74.16], EntityClientPlayerMP['Player869'/291, l='MpServer', x=-129.55, y=80.62, z=130.25], EntityCreeper['Creeper'/73, l='MpServer', x=-209.54, y=40.00, z=97.69], EntityCreeper['Creeper'/78, l='MpServer', x=-209.63, y=15.00, z=138.31], EntityZombie['Zombie'/79, l='MpServer', x=-208.40, y=15.00, z=138.48], EntitySkeleton['Skeleton'/93, l='MpServer', x=-204.09, y=38.00, z=69.47], EntitySquid['Squid'/95, l='MpServer', x=-195.22, y=48.37, z=76.47], EntityCreeper['Creeper'/97, l='MpServer', x=-207.41, y=40.00, z=98.00], EntityBat['Bat'/98, l='MpServer', x=-200.75, y=39.10, z=119.75], EntityCreeper['Creeper'/99, l='MpServer', x=-205.93, y=14.00, z=137.33], EntityEnderman['Enderman'/100, l='MpServer', x=-193.66, y=37.00, z=134.53], EntitySkeleton['Skeleton'/101, l='MpServer', x=-202.53, y=34.00, z=151.89], EntityZombie['Zombie'/102, l='MpServer', x=-203.22, y=13.00, z=173.31], EntityPig['Pig'/103, l='MpServer', x=-204.06, y=66.00, z=180.97], EntitySkeleton['Skeleton'/109, l='MpServer', x=-185.66, y=28.00, z=61.50], EntitySpider['Spider'/110, l='MpServer', x=-187.59, y=20.00, z=53.38], EntityBat['Bat'/111, l='MpServer', x=-184.25, y=19.02, z=61.69], EntityBat['Bat'/116, l='MpServer', x=-191.69, y=28.20, z=65.56], EntitySquid['Squid'/117, l='MpServer', x=-184.37, y=48.38, z=73.83], EntitySquid['Squid'/119, l='MpServer', x=-176.26, y=53.38, z=68.54], EntitySquid['Squid'/122, l='MpServer', x=-183.09, y=50.42, z=65.87], EntityCreeper['Creeper'/123, l='MpServer', x=-179.41, y=23.00, z=161.00], EntityPig['Pig'/124, l='MpServer', x=-183.41, y=70.00, z=188.03], EntityPig['Pig'/125, l='MpServer', x=-188.38, y=65.00, z=202.13], EntitySkeleton['Skeleton'/129, l='MpServer', x=-161.50, y=24.00, z=54.50], EntityZombie['Zombie'/131, l='MpServer', x=-164.88, y=23.00, z=70.41], EntityZombie['Zombie'/132, l='MpServer', x=-167.47, y=22.00, z=65.84], EntitySkeleton['Skeleton'/133, l='MpServer', x=-172.13, y=26.00, z=64.53], EntitySquid['Squid'/134, l='MpServer', x=-166.75, y=50.00, z=80.88], EntitySquid['Squid'/135, l='MpServer', x=-164.55, y=47.38, z=95.02], EntitySquid['Squid'/136, l='MpServer', x=-173.64, y=49.19, z=88.18], EntitySquid['Squid'/137, l='MpServer', x=-168.83, y=50.00, z=79.14], EntitySquid['Squid'/138, l='MpServer', x=-163.13, y=49.34, z=90.67], EntitySquid['Squid'/139, l='MpServer', x=-175.23, y=49.00, z=85.50], EntitySquid['Squid'/140, l='MpServer', x=-171.72, y=50.13, z=82.27], EntitySquid['Squid'/141, l='MpServer', x=-165.53, y=47.37, z=100.60], EntitySquid['Squid'/142, l='MpServer', x=-162.37, y=48.00, z=105.53], EntityCreeper['Creeper'/143, l='MpServer', x=-170.00, y=30.00, z=132.63], EntityWitch['Witch'/144, l='MpServer', x=-172.63, y=23.00, z=156.13], EntityCreeper['Creeper'/145, l='MpServer', x=-166.41, y=23.00, z=155.00], EntityPig['Pig'/146, l='MpServer', x=-169.47, y=69.00, z=190.47], EntityCreeper['Creeper'/148, l='MpServer', x=-172.50, y=24.00, z=198.50], EntityPig['Pig'/149, l='MpServer', x=-169.50, y=66.00, z=198.28], EntityBat['Bat'/152, l='MpServer', x=-158.44, y=23.10, z=64.25], EntitySquid['Squid'/153, l='MpServer', x=-149.48, y=49.38, z=77.92], EntitySkeleton['Skeleton'/154, l='MpServer', x=-156.13, y=28.00, z=92.50], EntityCreeper['Creeper'/155, l='MpServer', x=-149.50, y=28.00, z=99.50], EntitySkeleton['Skeleton'/156, l='MpServer', x=-156.66, y=28.00, z=99.53], EntitySkeleton['Skeleton'/157, l='MpServer', x=-157.53, y=29.00, z=100.10], EntityBat['Bat'/158, l='MpServer', x=-142.97, y=26.92, z=102.28], EntitySquid['Squid'/159, l='MpServer', x=-160.54, y=47.00, z=104.50], EntitySquid['Squid'/160, l='MpServer', x=-158.14, y=50.37, z=100.32], EntitySkeleton['Skeleton'/161, l='MpServer', x=-155.66, y=23.00, z=152.34], EntityCreeper['Creeper'/162, l='MpServer', x=-160.03, y=23.00, z=152.97], EntityCreeper['Creeper'/163, l='MpServer', x=-147.56, y=23.00, z=150.72], EntityBat['Bat'/164, l='MpServer', x=-155.84, y=44.02, z=175.06], EntityBat['Bat'/165, l='MpServer', x=-156.44, y=46.89, z=170.22], EntityZombie['Zombie'/166, l='MpServer', x=-152.50, y=57.00, z=169.50], EntityCreeper['Creeper'/167, l='MpServer', x=-144.72, y=45.00, z=179.47], EntityBat['Bat'/168, l='MpServer', x=-154.03, y=45.32, z=181.25], EntityBat['Bat'/169, l='MpServer', x=-147.31, y=47.42, z=181.03], EntityBat['Bat'/170, l='MpServer', x=-148.28, y=56.00, z=185.91], EntitySquid['Squid'/174, l='MpServer', x=-134.88, y=48.19, z=72.65], EntityItem['item.item.Itemdragonpickaxe'/175, l='MpServer', x=-128.78, y=65.13, z=121.81], EntityItem['item.item.Itemdragonpickaxe'/176, l='MpServer', x=-128.59, y=66.13, z=122.56], EntityItem['item.item.Itemdragonpickaxe'/177, l='MpServer', x=-128.19, y=66.13, z=121.94], EntityItem['item.item.Itemdragonpickaxe'/178, l='MpServer', x=-128.66, y=66.13, z=122.31], EntityItem['item.item.Itemdragonpickaxe'/179, l='MpServer', x=-128.63, y=65.13, z=121.88], EntityItem['item.item.Itemdragonpickaxe'/180, l='MpServer', x=-128.84, y=66.13, z=122.09], EntityItem['item.tile.stonebrick'/181, l='MpServer', x=-143.88, y=78.13, z=141.88], EntityItem['item.tile.gravel'/182, l='MpServer', x=-142.13, y=80.13, z=141.88], EntityCreeper['Creeper'/183, l='MpServer', x=-132.28, y=45.00, z=181.66], EntityBat['Bat'/184, l='MpServer', x=-149.75, y=46.17, z=181.78], EntitySquid['Squid'/194, l='MpServer', x=-125.95, y=53.44, z=80.09], EntityCow['Cow'/195, l='MpServer', x=-114.66, y=68.57, z=105.79], EntityCow['Cow'/196, l='MpServer', x=-123.53, y=84.00, z=137.53], EntityCow['Cow'/197, l='MpServer', x=-117.56, y=85.00, z=136.25], EntityCow['Cow'/198, l='MpServer', x=-121.41, y=81.00, z=133.25], EntityZombie['Zombie'/199, l='MpServer', x=-121.66, y=66.00, z=157.41], EntityZombie['Zombie'/200, l='MpServer', x=-119.56, y=66.00, z=155.41], EntitySkeleton['Skeleton'/202, l='MpServer', x=-125.59, y=66.00, z=174.16], EntityCow['Cow'/203, l='MpServer', x=-127.50, y=80.00, z=166.38], EntityBat['Bat'/204, l='MpServer', x=-123.75, y=51.10, z=182.25], EntityCreeper['Creeper'/210, l='MpServer', x=-101.50, y=27.00, z=58.50], EntitySquid['Squid'/212, l='MpServer', x=-105.52, y=50.62, z=79.67], EntitySquid['Squid'/214, l='MpServer', x=-102.26, y=54.34, z=78.12], EntitySquid['Squid'/215, l='MpServer', x=-93.38, y=54.36, z=72.02], EntitySquid['Squid'/216, l='MpServer', x=-110.47, y=54.34, z=71.34], EntitySquid['Squid'/217, l='MpServer', x=-96.47, y=54.71, z=82.57], EntityCow['Cow'/219, l='MpServer', x=-100.97, y=80.00, z=138.09], EntitySquid['Squid'/221, l='MpServer', x=-87.50, y=53.00, z=74.99], EntityCow['Cow'/222, l='MpServer', x=-80.63, y=63.00, z=77.25], EntityCow['Cow'/223, l='MpServer', x=-90.84, y=75.00, z=106.03], EntityBat['Bat'/227, l='MpServer', x=-84.31, y=61.10, z=156.72], EntityCow['Cow'/231, l='MpServer', x=-64.78, y=67.00, z=62.62], EntityCow['Cow'/232, l='MpServer', x=-74.69, y=64.00, z=72.44], EntityCow['Cow'/233, l='MpServer', x=-78.66, y=73.00, z=85.72], EntityCow['Cow'/234, l='MpServer', x=-74.84, y=78.00, z=102.19], EntityCow['Cow'/236, l='MpServer', x=-77.31, y=81.00, z=159.25], EntityCow['Cow'/237, l='MpServer', x=-77.34, y=82.00, z=164.03], EntityCow['Cow'/238, l='MpServer', x=-62.38, y=71.00, z=69.59], EntityCow['Cow'/239, l='MpServer', x=-62.94, y=76.00, z=135.97], EntityCow['Cow'/240, l='MpServer', x=-60.88, y=77.00, z=151.97], EntityCow['Cow'/241, l='MpServer', x=-55.94, y=77.00, z=174.88]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2555)

at net.minecraft.client.Minecraft.run(Minecraft.java:980)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

-- System Details --

Details:

Minecraft Version: 1.7.10

Operating System: Windows 7 (x86) version 6.1

Java Version: 1.8.0_25, Oracle Corporation

Java VM Version: Java HotSpot Client VM (mixed mode), Oracle Corporation

Memory: 800076952 bytes (763 MB) / 1046937600 bytes (998 MB) up to 1046937600 bytes (998 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94

FML: MCP v9.05 FML v7.10.85.1291 Minecraft Forge 10.13.2.1291 4 mods loaded, 4 mods active

mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

FML{7.10.85.1291} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Forge{10.13.2.1291} [Minecraft Forge] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

watwm{1.1.0} [We Are The Warriors] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Launched Version: 1.7.10

LWJGL: 2.9.1

OpenGL: ATI Radeon 3000 Graphics GL version 3.3.10750 Compatibility Profile Context, ATI Technologies Inc.

GL Caps: Using GL 1.3 multitexturing.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Anisotropic filtering is supported and maximum anisotropy is 16.

Shaders are available because OpenGL 2.1 is supported.

 

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs: []

Current Language: English (US)

Profiler Position: N/A (disabled)

Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

Anisotropic Filtering: Off (1)

 

 

and Im not the best at modding so dont judge please

Link to comment
Share on other sites

No, it's because the smelting result might return null, but you immediately call copy() on it:

FurnaceRecipes.smelting()
   .getSmeltingResult(new ItemStack(block)) // this returned null
   .copy() // so this crashes

Simply move the call to copy() to inside your 'if (stack != null) ' clause and you're good to go.

Link to comment
Share on other sites

so I tried to add it into my if statement and the only place I could add it in was here 'if (stack.copy() != null)' but it still crashed

Link to comment
Share on other sites

so I tried to add it into my if statement and the only place I could add it in was here 'if (stack.copy() != null)' but it still crashed

This is what I meant:

if (stack != null) {
   player.entityDropItem(stack.copy());
}

 

why don't you try using BlockEvent.HarvestDropsEvent and check if the player is using your tool then get the smelting result and drop that instead of the normal block

He could, but why do so when he already has a custom Item class ? Subscribing to Forge events should always be considered somewhat of a 'last resort', as the event handler is called for EVERY harvest, whether or not the player is wielding the pickaxe, whereas the code in the pickaxe is only called when it is actually used to break the block.

 

On the other hand, the harvest event lets you prevent the normal drop, whereas I don't think Item#onBlockDestroyed does. Hmm.

Link to comment
Share on other sites

If Item#onBlockDestroyed doesn't allow preventing then using BlockEvent.HarvestDropsEvent would be best to use

You could probably override Item#canHarvestBlock(Block) to return false if the block has a smelting result - thus preventing any normal harvesting, and then dropping the smelting result from #onBlockDestroyed.

 

@OP Of course you can drop stone instead of cobblestone - the problem you are running into, however, is that the block being destroyed is stone, which does not have a smelting result.

 

You should instead be checking the actual item dropped from the block, not the block itself. You could do this with Block#getItemDropped and Block#getDamageValue, but that may or may not produce the actual desired result, and you wouldn't be able to check for it in #canHarvestBlock due to the lack of a World and BlockPos.

 

Jedispencer's suggestion of using the HarvestDropsEvent may be your only recourse in this matter, which is fine - that's what it's there for - but it's always good to explore other options first.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • There's a scheme I got into where they promised to trade Bitcoin for me and take a cut as a commission. Seemed like a good idea at the time. But then, things went south real fast. They ended up transferring   $190,000 worth of my Bitcoin. I was devastated and felt completely helpless. That's when I stumbled upon the Wizard Web Recovery Tool. It was like a beacon of hope amid chaos. With this tool, I could finally start digging into what went wrong and hopefully get my Bitcoin back. Using Wizard Web was surprisingly easy. I just had to plug in some details about my Bitcoin account and let it do its thing. It started scanning the internet, looking for any clues about what happened to my Bitcoin. It felt like having a detective on my side, searching for answers. And guess what? Wizard Web found some leads. It uncovered evidence of the scheme's shady dealings and helped me track down the people responsible for losing my Bitcoin. Armed with this information, I took the case to court. After a long and hard-fought legal battle, the court ruled in my favor. The perpetrators were held accountable for their actions and faced criminal charges for their involvement in the scheme. It was a victory not just for me, but for anyone who's been taken advantage of by these kinds of scams. Thanks to Wizard Web Recovery, I was able to get justice and reclaim what was rightfully mine. It showed me that even in the face of adversity, there's always a way to fight back. And with the right tools and determination, anything is possible.   The following is the contact information for Wizard Web Recovery.   Email: wizard web recovery((@))programmer . net
    • Hello, good morning. I know some programming and I'm interested in mod creation. That's why I've decided to follow a tutorial guide on YouTube by TurtyWurty. https://www.youtube.com/watch?v=DhoX9cmAZqA&t=160s&ab_channel=TurtyWurty I've followed the tutorial perfectly. The problem is that when checking the food, the texture doesn't load for me. However, everything seems fine no matter how much I check. I'm sure it's something trivial, the problem is that I can't find it. Could you help me solve it, please? I leave a zip of my file so you can edit it freely. forge-1.20-Civicraft.rar
    • If you have nvidia graphics, it's important that you make sure Minecraft (and anything Minecraft-related) is set to prefer high performance graphics first. If you only update your AMD drivers it might fix the issue but cause severe performance loss vs Vanilla as it'll be running on the integrated graphics instead of dedicated nvidia graphics
    • Update your drivers: https://www.amd.com/en/support/downloads/drivers.html/processors/ryzen/ryzen-5000-series/amd-ryzen-5-5600g.html
  • Topics

×
×
  • Create New...

Important Information

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