Jump to content

[1.7.10] My custom Web Block crashes with getPlayerRelativeBlockHardness


Recommended Posts

Posted

Please help!! I don't know why crash. T_T

 

 

package stevekung.mods.moreplanets.planets.fronos.blocks;

 

import java.util.ArrayList;

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.ItemSword;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import net.minecraftforge.common.ForgeHooks;

import net.minecraftforge.common.IShearable;

import stevekung.mods.moreplanets.core.MorePlanetCore;

import stevekung.mods.moreplanets.planets.fronos.items.FronosItems;

 

public class BlockCheeseWeb extends Block implements IShearable

{

public BlockCheeseWeb(String name)

{

super(Material.web);

this.setBlockName(name);

this.setLightOpacity(1);

this.setHardness(4.0F);

}

 

@Override

public CreativeTabs getCreativeTabToDisplayOn()

{

return MorePlanetCore.mpBlocksTab;

}

 

@Override

public void registerBlockIcons(IIconRegister par1IconRegister)

{

this.blockIcon = par1IconRegister.registerIcon("fronos:cheeseWeb");

}

 

@Override

public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity)

{

entity.setInWeb();

}

 

@Override

public boolean isOpaqueCube()

{

return false;

}

 

@Override

public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)

{

return null;

}

 

@Override

public int getRenderType()

{

return 1;

}

 

@Override

public int damageDropped(int meta)

{

return 9;

}

 

@Override

public boolean renderAsNormalBlock()

{

return false;

}

 

@Override

public Item getItemDropped(int meta, Random rand, int fortune)

{

return FronosItems.fronosBasicItem;

}

 

@Override

public boolean canHarvestBlock(EntityPlayer player, int metadata)

{

ItemStack stack = player.inventory.getCurrentItem();

 

if (stack == null)

{

return player.canHarvestBlock(this);

}

return stack.getItem() == Items.shears && stack.getItem() instanceof ItemSword;

}

 

@Override

public float getPlayerRelativeBlockHardness(EntityPlayer player, World world, int x, int y, int z)

{

ItemStack stack = player.inventory.getCurrentItem();

 

if (stack.getItem() instanceof ItemSword && stack.getItem() == Items.shears)

{

return 0.1F;

}

return ForgeHooks.blockStrength(this, player, world, x, y, z);

}

 

@Override

public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z)

{

return true;

}

 

@Override

public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune)

{

final ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

ret.add(new ItemStack(FronosItems.fronosBasicItem, 1, 9));

return ret;

}

}

 

Posted

Is it NPE?

 

My guess is not checking for null itemStack :)

You need to check if itemStack is not null before you cast it to any kind of item.

 

ItemStack current = inv.getCurrentItem();
if (current != null && current.getItem() instanceof SomeItem)

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

Posted

OK When I changed to this.

 

@Override

public boolean canHarvestBlock(EntityPlayer player, int metadata)

{

ItemStack stack = player.inventory.getCurrentItem();

 

if (stack.getItem() == Items.shears || stack.getItem() instanceof ItemSword)

{

return player.canHarvestBlock(this);

}

return false;

}

 

That crash again T_T

 

 

---- Minecraft Crash Report ----

// Don't be sad, have a hug! <3

 

Time: 5/1/2558, 21:41 น.

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at stevekung.mods.moreplanets.planets.fronos.blocks.BlockCheeseWeb.getPlayerRelativeBlockHardness(BlockCheeseWeb.java:105)

at net.minecraft.client.multiplayer.PlayerControllerMP.clickBlock(PlayerControllerMP.java:170)

at net.minecraft.client.Minecraft.func_147116_af(Minecraft.java:1398)

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

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

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

at net.minecraft.client.main.Main.main(SourceFile:148)

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

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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

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

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

 

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

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

 

-- Head --

Stacktrace:

at stevekung.mods.moreplanets.planets.fronos.blocks.BlockCheeseWeb.getPlayerRelativeBlockHardness(BlockCheeseWeb.java:105)

at net.minecraft.client.multiplayer.PlayerControllerMP.clickBlock(PlayerControllerMP.java:170)

at net.minecraft.client.Minecraft.func_147116_af(Minecraft.java:1398)

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [GCEntityClientPlayerMP['SteveMCCommander'/8, l='MpServer', x=-511.54, y=57.62, z=848.34]]

Chunk stats: MultiplayerChunkCache: 289, 289

Level seed: 0

Level generator: ID 01 - flat, ver 0. Features enabled: false

Level generator options:

Level spawn location: World: (-517,4,842), Chunk: (at 11,0,10 in -33,52; contains blocks -528,0,832 to -513,255,847), Region: (-2,1; contains chunks -64,32 to -33,63, blocks -1024,0,512 to -513,255,1023)

Level time: 792527 game time, 4000 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: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 1 total; [GCEntityClientPlayerMP['SteveMCCommander'/8, l='MpServer', x=-511.54, y=57.62, z=848.34]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

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

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

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

at net.minecraft.client.main.Main.main(SourceFile:148)

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

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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

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

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

-- System Details --

Details:

Minecraft Version: 1.7.10

Operating System: Windows 7 (x86) version 6.1

Java Version: 1.7.0_71, Oracle Corporation

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

Memory: 832060272 bytes (793 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 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: 0, tallocated: 0

FML: MCP v9.05 FML v7.10.85.1272 Minecraft Forge 10.13.2.1272 15 mods loaded, 15 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.1272} [Forge Mod Loader] (forgeBin-1.7.10-10.13.2.1272.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

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

Micdoodlecore{} [Micdoodle8 Core] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

GalacticraftCore{3.0.6} [Galacticraft Core] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

BiomesOPlenty{1.0} [biomes O' Plenty] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

NBTEdit{1.7.10} [in-game NBTEdit] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

GalacticraftMars{3.0.6} [Galacticraft Planets] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

BlockUtility{1.0.0} [block Utility] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

EntityGhost{1.0.0} [Entity Ghost Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

SteveIceBucket{1.0.3} [steve's Ice Bucket] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Lays{1.0.0} [Lays Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

MorePlanet{1.1.2} [More Planet's] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

TiberiumCraft{1.0.0} [Tiberium Craft] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

YouTuber{1.0.0} [YouTuber Tutorial Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Launched Version: 1.7.10

LWJGL: 2.9.1

OpenGL: GeForce 9500 GT/PCIe/SSE2 GL version 3.3.0, NVIDIA Corporation

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)

 

Posted

In #getPlayerRelativeBlockHardness()

 

ItemStack stack = player.inventory.getCurrentItem();

      if (stack != null && (stack.getItem() instanceof ItemSword || stack.getItem() == Items.shears))
      {
         return 0.1F;
      }
      return ForgeHooks.blockStrength(this, player, world, x, y, z);

 

***stack != null***

 

Also shears are not extending Sword so:

stack.getItem() == Items.shears && stack.getItem() instanceof ItemSword

Which you wrote will always be false.

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

Posted

You need to check if it's null. Also, instead of checking if the item is equal to Items.shears you should be checking if it is an instance of ItemShears, this way someone can use shears from other mods. You should also be using || (or) not && (and) because something can never be both shears and a sword.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

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.