Jump to content

[Solved] [1.12.2] Crash with custom block drop


ProspectPyxis

Recommended Posts

I've been trying to make my block drop a modded item when broken, either manually or when a block is broken from under it (the block can only be placed on the ground). However, upon trying to break the block, it just spawns a big untextured block item that immediately crashes the game when picked up.

 

Crash log:

Spoiler

---- Minecraft Crash Report ----
// Oh - I know what I did wrong!

Time: 10/9/18 6:27 PM
Description: Ticking player

java.lang.ArrayIndexOutOfBoundsException: -1
	at net.minecraft.stats.StatList.getObjectsPickedUpStats(StatList.java:123)
	at net.minecraft.entity.item.EntityItem.onCollideWithPlayer(EntityItem.java:451)
	at net.minecraft.entity.player.EntityPlayer.collideWithPlayer(EntityPlayer.java:664)
	at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:635)
	at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2398)
	at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:272)
	at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:423)
	at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:185)
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:212)
	at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307)
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
	at java.lang.Thread.run(Thread.java:748)


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

-- Head --
Thread: Server thread
Stacktrace:
	at net.minecraft.stats.StatList.getObjectsPickedUpStats(StatList.java:123)
	at net.minecraft.entity.item.EntityItem.onCollideWithPlayer(EntityItem.java:451)
	at net.minecraft.entity.player.EntityPlayer.collideWithPlayer(EntityPlayer.java:664)
	at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:635)
	at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2398)
	at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:272)

-- Player being ticked --
Details:
	Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
	Entity ID: 0
	Entity Name: Player708
	Entity's Exact location: -6.65, 4.49, 1.14
	Entity's Block location: World: (-7,4,1), Chunk: (at 9,0,1 in -1,0; contains blocks -16,0,0 to -1,255,15), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
	Entity's Momentum: 0.00, 0.00, 0.00
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
	at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:423)
	at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:185)
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:212)
	at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307)

-- Ticking connection --
Details:
	Connection: net.minecraft.network.NetworkManager@6ae156ea
Stacktrace:
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
	at java.lang.Thread.run(Thread.java:748)

-- System Details --
Details:
	Minecraft Version: 1.12.2
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_181, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 215192744 bytes (205 MB) / 719847424 bytes (686 MB) up to 1870135296 bytes (1783 MB)
	JVM Flags: 0 total; 
	IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
	FML: MCP 9.42 Powered by Forge 14.23.4.2765 5 mods loaded, 5 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

	| State     | ID            | Version      | Source                           | Signature |
	|:--------- |:------------- |:------------ |:-------------------------------- |:--------- |
	| UCHIJAAAA | minecraft     | 1.12.2       | minecraft.jar                    | None      |
	| UCHIJAAAA | mcp           | 9.42         | minecraft.jar                    | None      |
	| UCHIJAAAA | FML           | 8.0.99.99    | forgeSrc-1.12.2-14.23.4.2765.jar | None      |
	| UCHIJAAAA | forge         | 14.23.4.2765 | forgeSrc-1.12.2-14.23.4.2765.jar | None      |
	| UCHIJAAAA | glowinglights | 0.1          | GlowingLights-0.1.jar            | None      |

	Loaded coremods (and transformers): 
	GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
	Profiler Position: N/A (disabled)
	Player Count: 1 / 8; [EntityPlayerMP['Player708'/0, l='blab2', x=-6.65, y=4.49, z=1.14]]
	Type: Integrated Server (map_client.txt)
	Is Modded: Definitely; Client brand changed to 'fml,forge'

 

BlockGlowstoneBowl (the block in question, ItemGlowstoneBowl just extends ItemBlockSpecial and works fine on its own):

Spoiler

package prospectpyxis.glowinglights.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockFence;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import prospectpyxis.glowinglights.items.ItemGlowstoneBowl;

import java.util.Random;

public class BlockGlowstoneBowl extends BlockBase {

    protected static final AxisAlignedBB GLOWSTONE_BOWL_AABB = new AxisAlignedBB(0.125d, 0.0d, 0.125d, 0.875d, 0.3125d, 0.875d);

    public BlockGlowstoneBowl() {
        super(Material.GROUND, "glowstone_bowl", 0.4f, 15f, MapColor.SAND);
        this.lightValue = 15;
        this.lightOpacity = 255;
        this.fullBlock = false;
        this.blockSoundType = SoundType.WOOD;
    }

    @Override
    @SuppressWarnings("deprecation")
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
        return GLOWSTONE_BOWL_AABB;
    }

    @Override
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
        BlockPos blockPos = pos.offset(EnumFacing.DOWN);
        IBlockState state = worldIn.getBlockState(blockPos);

        if (state.isSideSolid(worldIn, blockPos, EnumFacing.UP) || state.getBlockFaceShape(worldIn, blockPos, EnumFacing.UP) == BlockFaceShape.SOLID) {
            return state.getBlock() != Blocks.END_GATEWAY;
        }
        else {
            return state.getBlock() instanceof BlockFence || state.getBlock() == Blocks.GLASS || state.getBlock() == Blocks.COBBLESTONE_WALL || state.getBlock() == Blocks.STAINED_GLASS;
        }
    }

    @Override
    public Item createItemBlock() {
        return new ItemBlock(this).setRegistryName("glowstone_bowl");
    }

    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        return new ItemGlowstoneBowl();
    }

    @Override
    @SuppressWarnings("deprecation")
    public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {

        BlockPos blockPos = pos.offset(EnumFacing.DOWN);

        if (worldIn.getBlockState(blockPos).getBlockFaceShape(worldIn, blockPos, EnumFacing.UP) != BlockFaceShape.SOLID) {
            EntityItem selfDrop = new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.STICK));
            if (!worldIn.isRemote) {
                worldIn.spawnEntity(selfDrop);
            }
            worldIn.setBlockToAir(pos);
        }

    }

    @Override
    @SuppressWarnings("deprecation")
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

    @Override
    @SuppressWarnings("deprecation")
    public boolean isFullCube(IBlockState state) {
        return false;
    }

    @Override
    @SuppressWarnings("deprecation")
    public boolean isFullBlock(IBlockState state) {
        return false;
    }

    @Override
    @SuppressWarnings("deprecation")
    public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) {
        return BlockFaceShape.BOWL;
    }

    @Override
    public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
        return new ItemStack(new ItemGlowstoneBowl());
    }
}

 

From what I've seen (and I'm not even 100% sure about this), the error happens because blocks are registered before items and therefore the block is actually dropping a null item, but I haven't found a working solution for this myself. Any help?

Edited by ProspectPyxis
Spoiler formatting mistake, ignore this
Link to comment
Share on other sites

@Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        return new ItemGlowstoneBowl();
    }

You can't just create a new item and be done with it, you must provide an existing, registered item. 

@Override
    public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
        return new ItemStack(new ItemGlowstoneBowl());
    }

Same here. The new keyword creates a new object(and you need an existing one). This is basic OOP.

 

To obtain a reference to a registered object use ObjectHolders.

Link to comment
Share on other sites

Items are Singletons. There is only ever one of each

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.

×
×
  • Create New...

Important Information

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