Jump to content

Recommended Posts

Posted (edited)

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
Posted
@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.

Posted

Dang, feels like it's just staring me in the face now that I've seen it. Added an ObjectHolder for my item in the block class and replaced all instances of new ItemGlowstoneBowl with it, works like a charm. Thank you!

Posted

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)

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 want to create block with entity, that will have height of 3 or more(configurable) and I tried to change first VoxelShape by increasing collision box on height I want and for changing block height on visual side i tried to configure BlockModelBuilder:  base.element() .from(0, 0, 0) .to(16f, 48f, 16f) .face(Direction.UP).texture("#top").end() .face(Direction.DOWN).texture("#bottom").end() .face(Direction.NORTH).texture("#side").end() .face(Direction.SOUTH).texture("#side").end() .face(Direction.WEST).texture("#side").end() .face(Direction.EAST).texture("#side").end() .end(); but, getting crash with next error: Position y out of range, must be within [-16, 32]. Found: %d [48.0]; Looks like game wont to block height modified by more than 32. Is there any way to fix that problem?
    • As long as the packets you are sending aren't lost, there's nothing wrong with what you're currently doing. Although, this sounds like something that would benefit from you making your own datapack registry instead of trying to arbitrarily sync static maps. Check out `DataPackRegistryEvent.NewRegistry`.
    • Hey all, I've been working a lot with datapacks lately, and I'm wondering what the most efficient way to get said data from server to client is.  I'm currently using packets, but given that a lot of the data I'm storing involves maps along the lines of Map<ResourceLocation, CustomDataType>, it can easily start to get messy if I need to transmit a lot of that data all at once. Recently I started looking into the ReloadableServerResources class, which is where Minecraft stores its built-ins.  I see you can access it via the server from the server's resources.managers, and it seems like this can be done even from the client to appropriately retrieve data from the server, unless I'm misunderstanding.  However, from what I can tell, this only works via built-in methods such as getRecipeManager() or getLootTables(), etc.  These are all SimpleJsonResourceReloadListeners, just like my datapack entries are, so it seems like it could be possible for me to access my datapack entries similarly?  But I don't see anywhere in ReloadableServerResources that stores loaded modded entries, so either I'm looking in the wrong place or it doesn't seem to be a thing. Are packets really the best way of doing this, or am I missing a method that would let me use ReloadableServerResources or something similar?
    • Hi, everyone! I'm new to minecraft modding stuff and want ask you some questions. 1. I checked forge references and saw there com.mojang and net.minecraft (not net.minecraftforge) and as I understand it's original game packages with all minecraft logic inside including renderers and so on, right? 2. Does it mean that forge has a limited set of instruments which doesn't cover all the aspects of the game? If make my question more specific then does forge provide such instruments that allow me totally change minecraft itself, like base mechanics and etc.? Or I have to use "original game packages" to implement such things? 3. I actively learning basic concepts with forge documentation and tutorials. So in my plans make different inventory system like in diabloids. Is that possible with forge? 4. It is last question related to the second one. So how deeply I can change minecraft with forge? I guess all my questions above because of that I haven't globally understanding what forge is and how it works inside and how it works with minecraft. It would be great if you provide some links or topics about it or explain it by yourself but I guess it's to big to be explained in that post at once. Anyway, thank you all for any help!
    • Im trying add to block a hole in center, just a usual block and in center of it on up side, there is should be a hole. I tried to add it via BlockModelBuilder, but its not working. Problem is that it only can change block size outside. I tried it to do with VoxelShape and its working, but its has been on server side and looks like its just changed collision shape, but for client, there is a texture covering this hole. I tried to use: base.renderType("cutout"); and removed some pixels from texture. I thought its should work, but game optimization makes block inside looks transparent. So, only custom model?
  • Topics

×
×
  • Create New...

Important Information

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