Jump to content

[Solved] World entity crash


Rekkyn

Recommended Posts

I've got an interesting problem for you. Minecraft crashes seemingly randomly when my arrow-like entity is in the world. It only happens occasionally and at any point of the flight path.

 

The weird part is that the console says the crash was caused by some other entity, like a sheep, creeper, etc. instead of my entity.

I have no idea what I've done wrong so I've come to the experts.

 

Here's an example of the crash log:

 

2013-05-14 18:14:50 [iNFO] [sTDERR] net.minecraft.util.ReportedException: Ticking entity

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.world.World.updateEntities(World.java:2158)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1849)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:831)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:756)

2013-05-14 18:14:50 [iNFO] [sTDERR] at java.lang.Thread.run(Thread.java:680)

2013-05-14 18:14:50 [iNFO] [sTDERR] Caused by: java.lang.NullPointerException

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.entity.Entity.moveEntity(Entity.java:762)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.entity.EntityLiving.moveEntityWithHeading(EntityLiving.java:1578)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:1875)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:37)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:856)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:45)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.entity.monster.EntitySpider.onUpdate(EntitySpider.java:34)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2327)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.world.World.updateEntity(World.java:2289)

2013-05-14 18:14:50 [iNFO] [sTDERR] at net.minecraft.world.World.updateEntities(World.java:2143)

2013-05-14 18:14:50 [iNFO] [sTDERR] ... 4 more

 

 

 

And here's my entity class:

 

 

package rekkyn.spacetime.entity;

 

import java.util.List;

 

import net.minecraft.block.Block;

import net.minecraft.enchantment.EnchantmentThorns;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.IProjectile;

import net.minecraft.entity.monster.EntityEnderman;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.network.packet.Packet70GameEvent;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MathHelper;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.util.Vec3;

import net.minecraft.world.World;

import rekkyn.spacetime.particles.ParticleEffects;

import cpw.mods.fml.common.registry.IThrowableEntity;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class EntityCrossbowBolt extends Entity implements IProjectile {

    private int xTile = -1;

    private int yTile = -1;

    private int zTile = -1;

    private int inTile = 0;

    private int inData = 0;

    private boolean inGround = false;

   

    /** Seems to be some sort of timer for animating an arrow. */

    public int arrowShake = 0;

   

    /** The owner of this arrow. */

    public Entity shootingEntity;

    private int ticksInGround;

    private int ticksInAir = 0;

    private double damage = 2.0D;

   

    /** The amount of knockback an arrow applies when it hits a mob. */

    private int knockbackStrength;

   

    public EntityCrossbowBolt(World par1World) {

        super(par1World);

        renderDistanceWeight = 10.0D;

        this.setSize(0.5F, 0.5F);

    }

   

    public EntityCrossbowBolt(World world, double posX, double posY, double posZ) {

        super(world);

        renderDistanceWeight = 10.0D;

        this.setSize(0.5F, 0.5F);

        this.setPosition(posX, posY, posZ);

        yOffset = 0.0F;

    }

   

    public EntityCrossbowBolt(World world, EntityLiving shootingEntity, EntityLiving par3EntityLiving, float power,

            float par5) {

        super(world);

        renderDistanceWeight = 10.0D;

        this.shootingEntity = shootingEntity;

       

        posY = shootingEntity.posY + shootingEntity.getEyeHeight() - 0.10000000149011612D;

        double d0 = par3EntityLiving.posX - shootingEntity.posX;

        double d1 = par3EntityLiving.boundingBox.minY + par3EntityLiving.height / 3.0F - posY;

        double d2 = par3EntityLiving.posZ - shootingEntity.posZ;

        double d3 = MathHelper.sqrt_double(d0 * d0 + d2 * d2);

       

        if (d3 >= 1.0E-7D) {

            float f2 = (float) (Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;

            float f3 = (float) -(Math.atan2(d1, d3) * 180.0D / Math.PI);

            double d4 = d0 / d3;

            double d5 = d2 / d3;

            this.setLocationAndAngles(shootingEntity.posX + d4, posY, shootingEntity.posZ + d5, f2, f3);

            yOffset = 0.0F;

            float f4 = (float) d3 * 0.2F;

            this.setThrowableHeading(d0, d1 + f4, d2, power, par5);

        }

    }

   

    public EntityCrossbowBolt(World world, EntityLiving shootingEntity, float power) {

        super(world);

        renderDistanceWeight = 10.0D;

        this.shootingEntity = shootingEntity;

       

        this.setSize(0.5F, 0.5F);

        this.setLocationAndAngles(shootingEntity.posX, shootingEntity.posY + shootingEntity.getEyeHeight(),

                shootingEntity.posZ, shootingEntity.rotationYaw, shootingEntity.rotationPitch);

        posX -= MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * 0.16F;

        posY -= 0.10000000149011612D;

        posZ -= MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * 0.16F;

        this.setPosition(posX, posY, posZ);

        yOffset = 0.0F;

        motionX = -MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI)

                * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI);

        motionZ = MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI)

                * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI);

        motionY = -MathHelper.sin(rotationPitch / 180.0F * (float) Math.PI);

        this.setThrowableHeading(motionX, motionY, motionZ, power * 5.0F, 1.0F);

    }

   

    @Override

    protected void entityInit() {

        dataWatcher.addObject(16, Byte.valueOf((byte) 0));

    }

   

    /**

    * Similar to setArrowHeading, it's point the throwable entity to a x, y, z

    * direction.

    */

    @Override

    public void setThrowableHeading(double x, double y, double z, float power, float par8) {

        float f2 = MathHelper.sqrt_double(x * x + y * y + z * z);

        x /= f2;

        y /= f2;

        z /= f2;

        x += rand.nextGaussian() * (rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * par8;

        y += rand.nextGaussian() * (rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * par8;

        z += rand.nextGaussian() * (rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * par8;

        x *= power;

        y *= power;

        z *= power;

        motionX = x;

        motionY = y;

        motionZ = z;

        float f3 = MathHelper.sqrt_double(x * x + z * z);

        prevRotationYaw = rotationYaw = (float) (Math.atan2(x, z) * 180.0D / Math.PI);

        prevRotationPitch = rotationPitch = (float) (Math.atan2(y, f3) * 180.0D / Math.PI);

        ticksInGround = 0;

    }

   

    @Override

    @SideOnly(Side.CLIENT)

    /**

    * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,

    * posY, posZ, yaw, pitch

    */

    public void setPositionAndRotation2(double x, double y, double z, float par7, float par8, int par9) {

        this.setPosition(x, y, z);

        this.setRotation(par7, par8);

    }

   

    @Override

    @SideOnly(Side.CLIENT)

    /**

    * Sets the velocity to the args. Args: x, y, z

    */

    public void setVelocity(double motionX, double motionY, double motionZ) {

        this.motionX = motionX;

        this.motionY = motionY;

        this.motionZ = motionZ;

       

        if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) {

            float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);

            prevRotationYaw = rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI);

            prevRotationPitch = rotationPitch = (float) (Math.atan2(motionY, f) * 180.0D / Math.PI);

            prevRotationPitch = rotationPitch;

            prevRotationYaw = rotationYaw;

            this.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch);

            ticksInGround = 0;

        }

    }

   

    /**

    * Called to update the entity's position/logic.

    */

    @Override

    public void onUpdate() {

        super.onUpdate();

       

        if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) {

            float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);

            prevRotationYaw = rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI);

            prevRotationPitch = rotationPitch = (float) (Math.atan2(motionY, f) * 180.0D / Math.PI);

        }

       

        int i = worldObj.getBlockId(xTile, yTile, zTile);

       

        if (i > 0) {

            Block.blocksList.setBlockBoundsBasedOnState(worldObj, xTile, yTile, zTile);

            AxisAlignedBB axisalignedbb = Block.blocksList.getCollisionBoundingBoxFromPool(worldObj, xTile, yTile,

                    zTile);

           

            if (axisalignedbb != null

                    && axisalignedbb.isVecInside(worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ))) {

                inGround = true;

            }

        }

       

        if (arrowShake > 0) {

            --arrowShake;

        }

       

        if (inGround) {

            this.setDead();

            int j = worldObj.getBlockId(xTile, yTile, zTile);

            int k = worldObj.getBlockMetadata(xTile, yTile, zTile);

           

            if (j == inTile && k == inData) {

                ++ticksInGround;

               

                if (ticksInGround == 1200) {

                    this.setDead();

                }

            } else {

                inGround = false;

                motionX *= rand.nextFloat() * 0.2F;

                motionY *= rand.nextFloat() * 0.2F;

                motionZ *= rand.nextFloat() * 0.2F;

                ticksInGround = 0;

                ticksInAir = 0;

            }

        } else {

            ++ticksInAir;

            if (ticksInAir == 1200) {

                this.setDead();

            }

           

            /*if (posY >= 256) {

                this.setDead();

            }*/

           

            Vec3 vec3 = worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ);

            Vec3 vec31 = worldObj.getWorldVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ);

            MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks_do_do(vec3, vec31, false, true);

            vec3 = worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ);

            vec31 = worldObj.getWorldVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ);

           

            if (movingobjectposition != null) {

                vec31 = worldObj.getWorldVec3Pool().getVecFromPool(movingobjectposition.hitVec.xCoord,

                        movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);

            }

           

            Entity entity = null;

            List list = worldObj.getEntitiesWithinAABBExcludingEntity(this,

                    boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));

            double d0 = 0.0D;

            int l;

            float f1;

           

            for (l = 0; l < list.size(); ++l) {

                Entity entity1 = (Entity) list.get(l);

               

                if (entity1.canBeCollidedWith() && (entity1 != shootingEntity || ticksInAir >= 5)) {

                    f1 = 0.3F;

                    AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f1, f1, f1);

                    MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec3, vec31);

                   

                    if (movingobjectposition1 != null) {

                        double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

                       

                        if (d1 < d0 || d0 == 0.0D) {

                            entity = entity1;

                            d0 = d1;

                        }

                    }

                }

            }

           

            if (entity != null) {

                movingobjectposition = new MovingObjectPosition(entity);

            }

           

            if (movingobjectposition != null && movingobjectposition.entityHit != null

                    && movingobjectposition.entityHit instanceof EntityPlayer) {

                EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;

               

                if (entityplayer.capabilities.disableDamage || shootingEntity instanceof EntityPlayer

                        && !((EntityPlayer) shootingEntity).func_96122_a(entityplayer)) {

                    movingobjectposition = null;

                }

            }

           

            float f2;

            float f3;

           

            if (movingobjectposition != null) {

                if (movingobjectposition.entityHit != null) {

                    f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);

                    int i1 = MathHelper.ceiling_double_int(f2 * damage);

                   

                    DamageSource damagesource = null;

                   

                    if (shootingEntity == null) {

                        damagesource = DamageSource.causeThrownDamage(this, this);

                    } else {

                        damagesource = DamageSource.causeThrownDamage(this, shootingEntity);

                    }

                   

                    if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman)) {

                        movingobjectposition.entityHit.setFire(5);

                    }

                   

                    if (movingobjectposition.entityHit.attackEntityFrom(damagesource, i1)) {

                        if (movingobjectposition.entityHit instanceof EntityLiving) {

                            EntityLiving entityliving = (EntityLiving) movingobjectposition.entityHit;

                           

                            if (!worldObj.isRemote) {

                                entityliving.setArrowCountInEntity(entityliving.getArrowCountInEntity() + 1);

                            }

                           

                            if (knockbackStrength > 0) {

                                f3 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);

                               

                                if (f3 > 0.0F) {

                                    movingobjectposition.entityHit.addVelocity(motionX * knockbackStrength

                                            * 0.6000000238418579D / f3, 0.1D, motionZ * knockbackStrength

                                            * 0.6000000238418579D / f3);

                                }

                            }

                           

                            if (shootingEntity != null) {

                                EnchantmentThorns.func_92096_a(shootingEntity, entityliving, rand);

                            }

                           

                            if (shootingEntity != null && movingobjectposition.entityHit != shootingEntity

                                    && movingobjectposition.entityHit instanceof EntityPlayer

                                    && shootingEntity instanceof EntityPlayerMP) {

                                ((EntityPlayerMP) shootingEntity).playerNetServerHandler

                                        .sendPacketToPlayer(new Packet70GameEvent(6, 0));

                            }

                        }

                       

                        this.playSound("random.bowhit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));

                       

                        if (!(movingobjectposition.entityHit instanceof EntityEnderman)) {

                            this.setDead();

                        }

                    } else {

                        motionX *= -0.10000000149011612D;

                        motionY *= -0.10000000149011612D;

                        motionZ *= -0.10000000149011612D;

                        rotationYaw += 180.0F;

                        prevRotationYaw += 180.0F;

                        ticksInAir = 0;

                    }

                } else {

                    xTile = movingobjectposition.blockX;

                    yTile = movingobjectposition.blockY;

                    zTile = movingobjectposition.blockZ;

                    inTile = worldObj.getBlockId(xTile, yTile, zTile);

                    inData = worldObj.getBlockMetadata(xTile, yTile, zTile);

                    motionX = (float) (movingobjectposition.hitVec.xCoord - posX);

                    motionY = (float) (movingobjectposition.hitVec.yCoord - posY);

                    motionZ = (float) (movingobjectposition.hitVec.zCoord - posZ);

                    f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);

                    posX -= motionX / f2 * 0.05000000074505806D;

                    posY -= motionY / f2 * 0.05000000074505806D;

                    posZ -= motionZ / f2 * 0.05000000074505806D;

                    this.playSound("random.bowhit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));

                    inGround = true;

                    arrowShake = 7;

                   

                    if (inTile != 0) {

                        Block.blocksList[inTile].onEntityCollidedWithBlock(worldObj, xTile, yTile, zTile, this);

                    }

                }

            }

           

            posX += motionX;

            posY += motionY;

            posZ += motionZ;

            f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);

            rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI);

           

            for (rotationPitch = (float) (Math.atan2(motionY, f2) * 180.0D / Math.PI); rotationPitch

                    - prevRotationPitch < -180.0F; prevRotationPitch -= 360.0F) {

                ;

            }

           

            while (rotationPitch - prevRotationPitch >= 180.0F) {

                prevRotationPitch += 360.0F;

            }

           

            while (rotationYaw - prevRotationYaw < -180.0F) {

                prevRotationYaw -= 360.0F;

            }

           

            while (rotationYaw - prevRotationYaw >= 180.0F) {

                prevRotationYaw += 360.0F;

            }

           

            rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;

            rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;

           

            if (this.isInWater()) {

                for (int j1 = 0; j1 < 4; ++j1) {

                    f3 = 0.25F;

                    worldObj.spawnParticle("bubble", posX - motionX * f3, posY - motionY * f3, posZ - motionZ * f3,

                            motionX, motionY, motionZ);

                }

            }

           

            for (int lmnop = 0; lmnop < 50; lmnop++) {

                float rand1 = (rand.nextFloat() - 0.5F) * 2;

                System.out.println(rand1);

                ParticleEffects.spawnParticle("crossbowTrail", posX + motionX * l / 4.0D, posY + motionY * l / 4.0D,

                        posZ + motionZ * l / 4.0D, -motionX * rand1, (-motionY) * rand1, -motionZ * rand1);

            }

           

            this.setPosition(posX, posY, posZ);

            this.doBlockCollisions();

        }

    }

   

    /**

    * (abstract) Protected helper method to write subclass entity data to NBT.

    */

    @Override

    public void writeEntityToNBT(NBTTagCompound tagcompound) {

        tagcompound.setShort("xTile", (short) xTile);

        tagcompound.setShort("yTile", (short) yTile);

        tagcompound.setShort("zTile", (short) zTile);

        tagcompound.setByte("inTile", (byte) inTile);

        tagcompound.setByte("inData", (byte) inData);

        tagcompound.setByte("shake", (byte) arrowShake);

        tagcompound.setByte("inGround", (byte) (inGround ? 1 : 0));

        tagcompound.setDouble("damage", damage);

    }

   

    /**

    * (abstract) Protected helper method to read subclass entity data from NBT.

    */

    @Override

    public void readEntityFromNBT(NBTTagCompound tagcompound) {

        xTile = tagcompound.getShort("xTile");

        yTile = tagcompound.getShort("yTile");

        zTile = tagcompound.getShort("zTile");

        inTile = tagcompound.getByte("inTile") & 255;

        inData = tagcompound.getByte("inData") & 255;

        arrowShake = tagcompound.getByte("shake") & 255;

        inGround = tagcompound.getByte("inGround") == 1;

       

        if (tagcompound.hasKey("damage")) {

            damage = tagcompound.getDouble("damage");

        }

    }

   

    /**

    * returns if this entity triggers Block.onEntityWalking on the blocks they

    * walk on. used for spiders and wolves to prevent them from trampling crops

    */

    @Override

    protected boolean canTriggerWalking() {

        return false;

    }

   

    @Override

    @SideOnly(Side.CLIENT)

    public float getShadowSize() {

        return 0.0F;

    }

   

    public void setDamage(double damage) {

        this.damage = damage;

    }

   

    public double getDamage() {

        return damage;

    }

   

    /**

    * Sets the amount of knockback the arrow applies when it hits a mob.

    */

    public void setKnockbackStrength(int knockbackStrength) {

        this.knockbackStrength = knockbackStrength;

    }

   

    /**

    * If returns false, the item will not inflict any damage against entities.

    */

    @Override

    public boolean canAttackWithItem() {

        return false;

    }   

}

 

 

 

If you need to see more code you can check here: github.com/Rekkyn/spacetimemod

 

Thanks in advance!

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Wait guys, I still don't don't understand... I shall send my code -- Define the function to decrease hunger local function decreaseHunger(player)     local currentHunger = player.getHunger()          -- Check if hunger is not already zero     if currentHunger > 0 then         player.setHunger(currentHunger - 1)     end end -- Register event to decrease hunger over time script.registerEvent(EntityPlayer, function(player)     while true do         -- Decrease hunger every few seconds         decreaseHunger(player)         script.sleep(1000) -- Sleep for 1 second     end end)     Any help appriecated. It's been a while since I learnt Javascript or whatever Minecraft is made with... ... ... ... Nicknotname Hungerinpeaceful xx
    • good days  i get this error: java.lang.ClassCastException: class net.minecraft.client.player.LocalPlayer cannot be cast to class net.minecraftforge.common.extensions.IForgeServerPlayer (net.minecraft.client.player.LocalPlayer is in module minecraft@1.20.4 of loader 'TRANSFORMER' @3e8b3b79; net.minecraftforge.common.extensions.IForgeServerPlayer is in module forge@49.0.26 of loader 'TRANSFORMER' @3e8b3b79)     at mercmod.blocks.classes.panel_whit_entity_inside.use(panel_whit_entity_inside.java:576) ~[main/:?] {re:classloading}     at net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase.use(BlockBehaviour.java:826) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.performUseItemOn(MultiPlayerGameMode.java:324) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.lambda$useItemOn$4(MultiPlayerGameMode.java:292) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.startPrediction(MultiPlayerGameMode.java:251) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.multiplayer.MultiPlayerGameMode.useItemOn(MultiPlayerGameMode.java:291) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.startUseItem(Minecraft.java:1799) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.handleKeybinds(Minecraft.java:2083) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.tick(Minecraft.java:1902) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.runTick(Minecraft.java:1216) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.run(Minecraft.java:801) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:234) ~[forge-1.20.4-49.0.26_mapped_official_1.20.4-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A} ------------------------------------------------------------------------------------------------------------------   context:  im updating the briefcase from mi mod an i need to make a gui whit this image that gonna be launched from a block and from a item soo im using kapenjoe tutorials  ---------------------------------------------------------------------------------------- The problem is that tutorial is for 1.20.1 and im using 1.20.4 and i really dont get how to call and open the gui from the block nor from the item i made this based on post i made short ago everything seems find but when right click the block to open the gui it crash the game  @Override public InteractionResult use(BlockState blkstate, Level warudo, BlockPos pos, Player pe, InteractionHand hand, BlockHitResult hitresult) {     if(warudo.isClientSide()){         BlockEntity blkentity = warudo.getBlockEntity(pos);         if(blkentity instanceof Panel_BlockEntity){             //   ↓↓↓  open the menu from the block              IForgeServerPlayer ifpe = (IForgeServerPlayer)pe; //<--- this is wrong  "class net.minecraft.client.player.LocalPlayer cannot be cast to class net.minecraftforge.common.extensions.IForgeServerPlayer"             ifpe.openMenu( (Panel_BlockEntity) blkentity, pos ); //<-- i need an example of how open a gui in 1.20.4         }     } return InteractionResult.sidedSuccess(warudo.isClientSide()); } Theres nothing highlighted in red in the code like everything where right an possible but dont works  ####################################################################################################### i need to see an example, just the piece of code for the use() method of the block whit the block entity for 1.20.4  and the same  but for the item     @Override     public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level warudo, @NotNull Player pe, @NotNull InteractionHand interactionHand)     {         if (!warudo.isClientSide())         {             ItemStack heldItem = pe.getItemInHand(interactionHand);                          if (heldItem.getCapability(ForgeCapabilities.ITEM_HANDLER).isPresent())             {                 //   ↓↓↓  open the menu from the item                 NetworkHooks.openScreen((ServerPlayer) pe, this);             }         }         return super.use(warudo, pe, interactionHand);     }   thanks for your attention           
    • It depends on the data you want to save, but generally speaking you should use some custom Player Capabilities, attach to the Player and use them to store/retrieve any kind of data you want. You can find how to make them work for 1.20.x in the documentation here: https://docs.minecraftforge.net/en/latest/datastorage/capabilities/
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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