Jump to content

[1.7.10] Unreported exception thrown when setting blockbounds


Jstylezzz

Recommended Posts

Hello everyone

 

This is my first post here, so my apologies in advance if I do anything wrong! So, I've been following a few tutorials and things seem to go pretty smooth. The only problem that I have is when I set the blockbounds of a block inside the AxisAlignedBB function. In the crash log I get 'Unreported exception thrown'.

Here is my full crash thingie that I get in the Eclipse console:

 

 

[13:01:05] [Client thread/FATAL]: Unreported exception thrown!
java.lang.NullPointerException
at com.jstylezzz.allincluded.block.UICopperCable.getCollisionBoundingBoxFromPool(UICopperCable.java:40) ~[uICopperCable.class:?]
at net.minecraft.world.World.canPlaceEntityOnSide(World.java:3647) ~[World.class:?]
at net.minecraft.item.ItemBlock.func_150936_a(ItemBlock.java:172) ~[itemBlock.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:383) ~[PlayerControllerMP.class:?]
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1519) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2034) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1029) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]
at GradleStart.main(GradleStart.java:45) [start/:?]
[13:01:05] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----
// Hey, that tickles! Hehehe!

Time: 1/25/15 1:01 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at com.jstylezzz.allincluded.block.UICopperCable.getCollisionBoundingBoxFromPool(UICopperCable.java:40)
at net.minecraft.world.World.canPlaceEntityOnSide(World.java:3647)
at net.minecraft.item.ItemBlock.func_150936_a(ItemBlock.java:172)
at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:383)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1519)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2034)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1029)
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(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)

 

 

 

It only happens when the following function is not commented out:

this.setBlockBounds(11*pixel/2, 11*pixel/2, 11*pixel/2-(cable.connections[3] !=null?(11*pixel/2):0), 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2);

 

The whole callback is as follows

public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
{
	TileEntityCable cable = (TileEntityCable) world.getTileEntity(x, y, z);
	float pixel = 1F/16;
	this.setBlockBounds(11*pixel/2, 11*pixel/2, 11*pixel/2-(cable.connections[3] !=null?(11*pixel/2):0), 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2);
	return AxisAlignedBB.getBoundingBox((double)x+minX, (double)y+minY,(double)z+minZ, (double)x+maxX, (double)y+maxY, (double)z+maxZ);
}

 

Note, that Minecraft only crashes if I place the block down. If a block is already placed down in the world, it does not make minecraft crash, but it also doesn't change the blockbounds.

 

I'm sure that there is something that I'm doing wrong, but I really can't seem to find out what it is..

 

I hope someone here knows what's going on, all the help is much appreciated.

Thanks in advance!

 

EDIT: lol, I'm sorry for those posts (which I removed again), it seems I pressed the wrong button :$

Link to comment
Share on other sites

No, the

connections

array is null, so when trying to access

connections[3]

, it will throw a NPE.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Ah I see, thanks for the heads up :) I'm not really sure what I should change though, the 'connections' is basically this

public ForgeDirection [] connections = new ForgeDirection[6];

//and then

public void updateConnections() //Called on updateEntity
{
	if(worldObj.getTileEntity(xCoord, yCoord+1, zCoord) instanceof TileEntityCable) connections[0] = ForgeDirection.UP;
	else connections[0] = null;

	if(worldObj.getTileEntity(xCoord, yCoord-1, zCoord) instanceof TileEntityCable) connections[1] = ForgeDirection.DOWN;
	else connections[1] = null;

	if(worldObj.getTileEntity(xCoord, yCoord, zCoord-1) instanceof TileEntityCable) connections[2] = ForgeDirection.NORTH;
	else connections[2] = null;

	if(worldObj.getTileEntity(xCoord+1, yCoord, zCoord) instanceof TileEntityCable) connections[3] = ForgeDirection.EAST;
	else connections[3] = null;

	if(worldObj.getTileEntity(xCoord, yCoord, zCoord+1) instanceof TileEntityCable) connections[4] = ForgeDirection.SOUTH;
	else connections[4] = null;

	if(worldObj.getTileEntity(xCoord-1, yCoord, zCoord) instanceof TileEntityCable) connections[5] = ForgeDirection.WEST;
	else connections[5] = null;

}

 

Is there a way to get around that NPE?

 

Thanks for the answers so far :)

Link to comment
Share on other sites

Then the only other thing that can be null on that line is

cable

. Can you post your full block class?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Sure I can :)

package com.jstylezzz.allincluded.block;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;

import com.jstylezzz.allincluded.AllIncluded;
import com.jstylezzz.allincluded.entity.TileEntityCable;

public class UICopperCable extends BlockContainer {

public UICopperCable() {
	super(Material.cloth);
	setStepSound(Block.soundTypeStone);
	setCreativeTab(CreativeTabs.tabBlock);
	setCreativeTab(AllIncluded.allIncluded);
	setBlockName("uiCopperCable");
	setBlockTextureName("allincluded:uiCopperCable");
	setHardness(1.0f);
	useNeighborBrightness=true;
	float pixel = 1F/16;
	setBlockBounds(11*pixel/2, 11*pixel/2, 11*pixel/2, 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2);

}

public TileEntity createNewTileEntity(World world, int i)
{
	return new TileEntityCable();
}

public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
{
	TileEntityCable cable = (TileEntityCable) world.getTileEntity(x, y, z);
	float pixel = 1F/16;
	float f = 0;
	if(cable.connections[3] == null) f = 0;
	else f = 11*pixel/2;

	this.setBlockBounds(11*pixel/2,  11*pixel/2, 11*pixel/2-(f), 1-11*pixel/2, 1-11*pixel/2, 1-11*pixel/2);
	return AxisAlignedBB.getBoundingBox((double)x+minX, (double)y+minY,(double)z+minZ, (double)x+maxX, (double)y+maxY, (double)z+maxZ);
}

public int getRenderType(){
	return -1;
}
public boolean isOpaqueCube(){
	return false;
}
public boolean renderAsNormalBlock()
{
	return false;
}
}

 

Here is the UICopperCable class.

 

if connections[x] != null 
    do it with the connection
else
    do something else

?

 

I tried something like this, but it still doesn't like it very much. Thanks anyways!

Link to comment
Share on other sites

You need to have the

public boolean hasTileEntity(int meta)

in your block class and make it return true.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Ah, now I see the issue. You have called your method

createNewTileEntity

while it should be

createTileEntity

. In the future, add the

@Override

annotation to all your methods you expect to override a method, as it will throw an error if the method doesn't exist in one of the super classes.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Ah, thanks a lot for looking :) I think we nearly solved this problem, yey

 

I added the override

@Override
public TileEntity createNewTileEntity(World world, int i)
{
	return new TileEntityCable();
}

 

When I change createNewTileEntity to createTileEntity it gives me an error, so I tried it like I paste above. It still crashes on me though :|

Thanks for helping me, and sorry for being so difficult!

Link to comment
Share on other sites

So this is giving you an error?

@Override
public TileEntity createTileEntity(World world, int meta)
{
    return new TileEntityCable();
}

It should work if it's like that. You still have the

hasTileEntity

method?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Yeah, I still have it. This is what Eclipse says: 'The type UICopperCable must implement the inherited abstract method ITileEntityProvider.createNewTileEntity(World, int)'. It has the option to add the unimplemented method, but that just adds the createNewTileEntity thing that we just changed..

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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