Jump to content

Recommended Posts

Posted

Hey

 

Ive got my portal and telepoter kinda working but whenever i touch my portal block it Crashes minecraft with this:

 

 

 

2013-02-03 15:15:26 [iNFO] [ForgeModLoader] Unloading dimension 0

2013-02-03 15:15:26 [iNFO] [ForgeModLoader] Unloading dimension -1

2013-02-03 15:15:26 [iNFO] [ForgeModLoader] Unloading dimension 1

2013-02-03 15:15:26 [iNFO] [ForgeModLoader] Unloading dimension 2

2013-02-03 15:15:26 [iNFO] [sTDERR] java.lang.ClassCastException: net.minecraft.client.particle.EntityDiggingFX cannot be cast to net.minecraft.entity.player.EntityPlayerMP

2013-02-03 15:15:26 [iNFO] [sTDERR] at skycraft.blocks.PortalBlock.onEntityCollidedWithBlock(PortalBlock.java:46)

2013-02-03 15:15:26 [iNFO] [sTDERR] at net.minecraft.entity.Entity.doBlockCollisions(Entity.java:1011)

2013-02-03 15:15:26 [iNFO] [sTDERR] at net.minecraft.entity.Entity.moveEntity(Entity.java:955)

2013-02-03 15:15:26 [iNFO] [sTDERR] at net.minecraft.client.particle.EntityFX.onUpdate(EntityFX.java:145)

2013-02-03 15:15:26 [iNFO] [sTDERR] at net.minecraft.client.particle.EffectRenderer.updateEffects(EffectRenderer.java:90)

2013-02-03 15:15:26 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1903)

2013-02-03 15:15:26 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:846)

2013-02-03 15:15:26 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:771)

2013-02-03 15:15:26 [iNFO] [sTDERR] at java.lang.Thread.run(Unknown Source)

2013-02-03 15:15:36 [iNFO] [sTDOUT] Stopping!

2013-02-03 15:15:36 [iNFO] [sTDOUT] SoundSystem shutting down...

2013-02-03 15:15:37 [iNFO] [sTDOUT]    Author: Paul Lamb, www.paulscode.com

 

 

 

Here's my portal block code:

 

 

 

package skycraft.blocks;

 

import java.util.Iterator;

import java.util.List;

import java.util.Random;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.entity.Entity;

import net.minecraft.entity.item.EntityItem;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.item.Item;

import net.minecraft.item.ItemMonsterPlacer;

import net.minecraft.item.ItemStack;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import skycraft.SkyCraft;

import skycraft.SkyCraftBlocks;

import skycraft.core.client.ClientProxySkyCraft;

import skycraft.core.common.CommonProxySkyCraft;

import skycraft.skydimension.SkyTeleporter;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class PortalBlock extends Block

{

public PortalBlock(int id, int texture, Material material)

    {

    super(id, texture, material);

    this.setBlockName("Portal");

    this.setStepSound(Block.soundGlassFootstep);

    this.setLightValue(0.75F);

    this.setHardness(-1.0F);

    this.setCreativeTab(SkyCraft.tabSkyCraftBlocks);

    this.setTickRandomly(true);

    }

 

public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)

{

if (par5Entity.ridingEntity == null && par5Entity.riddenByEntity == null)

{

  if (par5Entity instanceof EntityPlayerMP)

  {

   

  }

  EntityPlayerMP thePlayer = (EntityPlayerMP) par5Entity;

  if (par5Entity.dimension != SkyCraft.dimension)

  {

  thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, SkyCraft.dimension, new SkyTeleporter(thePlayer.mcServer.worldServerForDimension(SkyCraft.dimension)));

  }

  else

  {

  thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, 0, new SkyTeleporter(thePlayer.mcServer.worldServerForDimension(0)));

  }

}

}

 

    public int getRenderBlockPass()

    {

        return 1;

    }

   

    public boolean isOpaqueCube()

    {

        return false;

    }

   

    public boolean renderAsNormalBlock()

    {

        return false;

    }

   

    public int quantityDropped(Random par1Random)

    {

        return 0;

    }

   

    //Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been cleared to be reused)

    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)

    {

        return null;

    }

 

    //Updates the blocks bounds based on its current state. Args: world, x, y, z

    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)

    {

        if (par1IBlockAccess.getBlockId(par2 - 1, par3, par4) != this.blockID && par1IBlockAccess.getBlockId(par2 + 1, par3, par4) != this.blockID)

        {

            this.setBlockBounds(0F, 0.4F, 0F, 1F, 0.6F, 1F);

        }

        else

        {

            this.setBlockBounds(0F, 0.4F, 0F, 1F, 0.6F, 1F);

        }

    }

 

    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)

    {

        for (int var6 = 0; var6 < 4; ++var6)

        {

            double var7 = (double)((float)par2 + par5Random.nextFloat());

            double var9 = (double)((float)par3 + par5Random.nextFloat());

            double var11 = (double)((float)par4 + par5Random.nextFloat());

            double var13 = 0.0D;

            double var15 = 0.0D;

            double var17 = 0.0D;

            int var19 = par5Random.nextInt(2) * 2 - 1;

            var13 = ((double)par5Random.nextFloat() - 0.5D) * 0.5D;

            var15 = ((double)par5Random.nextFloat() - 0.5D) * 0.5D;

            var17 = ((double)par5Random.nextFloat() - 0.5D) * 0.5D;

 

            if (par1World.getBlockId(par2 - 1, par3, par4) != this.blockID && par1World.getBlockId(par2 + 1, par3, par4) != this.blockID)

            {

                var7 = (double)par2 + 0.5D + 0.25D * (double)var19;

                var13 = (double)(par5Random.nextFloat() * 2.0F * (float)var19);

            }

            else

            {

                var11 = (double)par4 + 0.5D + 0.25D * (double)var19;

                var17 = (double)(par5Random.nextFloat() * 2.0F * (float)var19);

            }

 

        }

    }

   

    //Pistons can move block = 0

    //Pistons can move on top of block = 1

    //Pistons can't move at all = 2

    public int getMobilityFlag()

    {

        return 2;

    }

   

    //Only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem

    public int idPicked(World par1World, int par2, int par3, int par4)

    {

        return 0;

    }

   

    public String getTextureFile()

    {

        return CommonProxySkyCraft.Blocks_PNG;

    }

 

}

 

 

 

Posted

The error you are getting is " java.lang.ClassCastException: net.minecraft.client.particle.EntityDiggingFX cannot be cast to net.minecraft.entity.player.EntityPlayerMP"

 

And from the log you see that it gets it right after this:

at skycraft.blocks.PortalBlock.onEntityCollidedWithBlock(PortalBlock.java:46)

 

So while trying to preform the onEntityCollidedWithBlock()  method in the PortalBlock file on line 46.

It caused this error.

 

Let's check line 46 of that file and see what it says? :)

 

Pasting your code into www.pastebin.com and setting Syntax Highlighting to Java, makes it a lot easier for others to read your code files :)

Here I created one for your code:

http://pastebin.com/cCsGd37f

 

 

Looking at line 46 it seems you are doing this:

EntityPlayerMP thePlayer = (EntityPlayerMP) par5Entity;

 

Which is causing the crash, since the par5Entity is NOT an EntityPlayerMP but an different Entity. And you are telling it to use that entity as a EntityPlayerMP!

 

What you need to do is to do a check before you do the rest of the code to see IF the par5Entity IS a EntityPlayerMP at all. To do this I suggest the following change:

 

if (par5Entity instanceof EntityPlayerMP)

{

  // All the code from line 46 untill line  54.

}

 

Now that I read the whole file, I notice that you ahve this check on line 42 but the code is not inside it, so you just need to move the whole code block into the if block :)

 

 

If you guys dont get it.. then well ya.. try harder...

Posted

One often get blind by one's own code, it's hard to see simple mistakes when it's your own code :)

You might want to check up on how a stack trace can help you with debugging, just the few lines that indicates which lines crashed it and why helps you a lot inn finding such problems ;)

If you guys dont get it.. then well ya.. try harder...

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.