Jump to content

Why In The World Does This Happen!?!??!? (Weird teleportation?)


Recommended Posts

Posted

Here is an image showing my player on some wood blocks at the highest build limit:

3JQGliG.png

 

Here is an image showing my player after shift right clicking with an orb in my hand and looking towards the seams of the logs:

xKtryhf.png

 

What happens:

When doing this with logs (I haven't found anything else *so far*) I can position my player atop a minimum of 4 logs. Then shift right click and my player will be pulled through all obstruction (including bedrock) to what shows up as 6 when pressing f3. Like an instant downward obstruction free teleportation method. I have done this in multiple worlds at different heights leading to the same result.

 

The thing is, is that I honestly don't know WHY it happens. I know how to reproduce it. But that still doesn't add up to why this happens xD. (It is definately an interesting way to reach lower levels of minecraft though).

I would really like to know if there is a way to add obstructions in the way of it so I could make a downward travel system with multiple floors, its still cool either way. There is not anything in my code relating to teleporting of any kind. (its odd)

 

Here is the entirety of the orb itself:

item:

 

package guru.tbe.item;

import guru.tbe.entity.EntityAetherOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;

public class ItemAetherOrb extends Item
{
    public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
    {
        if (!playerIn.capabilities.isCreativeMode)
        {
            --itemStackIn.stackSize;
        }
        worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.4F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
        if (!worldIn.isRemote && !playerIn.isSneaking())
        {
            EntityAetherOrb entitythrowable = new EntityAetherOrb(worldIn, playerIn);
            entitythrowable.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
            worldIn.spawnEntityInWorld(entitythrowable);
        }
        else if (!worldIn.isRemote && playerIn.isSneaking())
        {
        	
        	EntityAetherOrb entitythrowable = new EntityAetherOrb(worldIn, playerIn);
        	playerIn.posY = 0;
        	playerIn.posY = 6.8;
            entitythrowable.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 0.001F, 0.0F);
            entitythrowable.addVelocity(0.0, -0.1, 0.0); 
            worldIn.spawnEntityInWorld(entitythrowable);
        }
        playerIn.addStat(StatList.getObjectUseStats(this));
        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
    }
}

 

 

Entity:

 

package guru.tbe.entity;

import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityAetherOrb extends EntityOrb2
{
public EntityAetherOrb(World worldIn)
    {
        super(worldIn);
    } 
    public EntityAetherOrb(World worldIn, EntityLivingBase throwerIn)
    {
        super(worldIn, throwerIn);
    } 
    public void onUpdate()
    {
    	super.onUpdate();
    	++ticksExisted;
        if (this.ticksExisted >= 114)
        {
        	this.worldObj.spawnParticle(EnumParticleTypes.REDSTONE, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / 2 - worldObj.rand.nextFloat()) / 2, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 4, -1, -1, 1);
        	this.setDead();
        }
    	this.worldObj.spawnParticle(EnumParticleTypes.SPELL_MOB_AMBIENT, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / -2 - worldObj.rand.nextFloat()) / -1, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / -1.0, -1d, -1d, 1d);
    }
    public float getGravityVelocity()
    {
	return 0.0F;
    }
    public EntityAetherOrb(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }    
    protected void onImpact(RayTraceResult result)
    {
        if (result.entityHit != null)
        {
            int i = 0;
            if (result.entityHit instanceof EntityLivingBase)
            {
                i = 0;
                ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1));
                ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3));
                ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5));
                ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7));
                ((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2));
                
            }
            
            if (result.entityHit instanceof EntityPlayer)
            {
            	i = 0;
            	((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 200, 1));
                ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.INSTANT_HEALTH, 10, 3));
                ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 5));
                ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 200, 7));
                ((EntityPlayer)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.SPEED, 200, 2));
            }
            result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
            worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 0.8F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));
        }
        for (int j = 0; j < 8; ++j)
        {
        	this.worldObj.spawnParticle(EnumParticleTypes.SPELL_MOB, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / -2 - worldObj.rand.nextFloat()) / -1, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / -1.0, -1d, -1d, 1d);
        }
        if (!this.worldObj.isRemote)
        {
            this.doBlockCollisions();
        }
    }
    public float getBrightness(float partialTicks)
    {
        return 0.001F;
    }
    @SideOnly(Side.CLIENT)
    public int getBrightnessForRender(float partialTicks)
    {
    	return 15728880;
    }
}

 

 

Entity Orb2 which it extends:

 

package guru.tbe.entity;

import java.util.List;
import java.util.UUID;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public abstract class EntityOrb2 extends Entity implements IProjectile
{
    private int xTile;
    private int yTile;
    private int zTile;
    private Block inTile;
    protected boolean inGround;
    public int throwableShake;
    private EntityLivingBase thrower;
    private String throwerName;
    private int ticksInGround;
    private int ticksInAir;
    public Entity field_184539_c;
    private int field_184540_av;

    public EntityOrb2(World worldIn)
    {
        super(worldIn);
        this.xTile = -1;
        this.yTile = -1;
        this.zTile = -1;
        this.setSize(0.41F, 0.41F);
    }
    public EntityOrb2(World worldIn, double x, double y, double z)
    {
        this(worldIn);
        this.setPosition(x, y, z);
    }
    public EntityOrb2(World worldIn, EntityLivingBase throwerIn)
    {
        this(worldIn, throwerIn.posX, throwerIn.posY + (double)throwerIn.getEyeHeight() - 0.10000000149011612D, throwerIn.posZ);
        this.thrower = throwerIn;
    }
    public boolean canRenderOnFire()
    {
    	return false;
    }
    protected void entityInit()
    {
    }
    @SideOnly(Side.CLIENT)
    public boolean isInRangeToRenderDist(double distance)
    {
        double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D;
        if (Double.isNaN(d0))
        {
            d0 = 4.0D;
        }
        d0 = d0 * 64.0D;
        return distance < d0 * d0;
    }
    public void func_184538_a(Entity p_184538_1_, float p_184538_2_, float p_184538_3_, float p_184538_4_, float p_184538_5_, float p_184538_6_)
    {
        float f = -MathHelper.sin(p_184538_3_ * 0.017453292F) * MathHelper.cos(p_184538_2_ * 0.017453292F);
        float f1 = -MathHelper.sin((p_184538_2_ + p_184538_4_) * 0.017453292F);
        float f2 = MathHelper.cos(p_184538_3_ * 0.017453292F) * MathHelper.cos(p_184538_2_ * 0.017453292F);
        this.setThrowableHeading((double)f, (double)f1, (double)f2, p_184538_5_, p_184538_6_);
        this.motionX += p_184538_1_.motionX;
        this.motionZ += p_184538_1_.motionZ;
        if (!p_184538_1_.onGround)
        {
            this.motionY += p_184538_1_.motionY;
        }
    }
    public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy)
    {
        float f = MathHelper.sqrt_double(x * x + y * y + z * z);
        x = x / (double)f;
        y = y / (double)f;
        z = z / (double)f;
        x = x + this.rand.nextGaussian() * 0.0D * (double)inaccuracy;
        y = y + this.rand.nextGaussian() * 0.0D * (double)inaccuracy;
        z = z + this.rand.nextGaussian() * 0.0D * (double)inaccuracy;
        x = x * (double)velocity;
        y = y * (double)velocity;
        z = z * (double)velocity;
        this.motionX = x;
        this.motionY = y;
        this.motionZ = z;
        float f1 = MathHelper.sqrt_double(x * x + z * z);
        this.prevRotationYaw = this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
        this.prevRotationPitch = this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
        this.ticksInGround = 0;
    }
    @SideOnly(Side.CLIENT)
    public void setVelocity(double x, double y, double z)
    {
        this.motionX = x;
        this.motionY = y;
        this.motionZ = z;
        if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
        {
            float f = MathHelper.sqrt_double(x * x + z * z);
            this.prevRotationYaw = this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
            this.prevRotationPitch = this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
        }
    }
    public void onUpdate()
    {
        this.lastTickPosX = this.posX;
        this.lastTickPosY = this.posY;
        this.lastTickPosZ = this.posZ;
        super.onUpdate();
        if (this.throwableShake > 0)
        {
            --this.throwableShake;
        }
        if (this.inGround)
        {
            if (this.worldObj.getBlockState(new BlockPos(this.xTile, this.yTile, this.zTile)).getBlock() == this.inTile)
            {
                ++this.ticksInGround;
                if (this.ticksInGround == 1200)
                {
                    this.setDead();
                }
                return;
            }
            this.inGround = false;
            this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
            this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
            this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
            this.ticksInGround = 0;
            this.ticksInAir = 0;
        }
        else
        {
            ++this.ticksInAir;
        }
        Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        RayTraceResult raytraceresult = this.worldObj.rayTraceBlocks(vec3d, vec3d1);
        vec3d = new Vec3d(this.posX, this.posY, this.posZ);
        vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        if (raytraceresult != null)
        {
            vec3d1 = new Vec3d(raytraceresult.hitVec.xCoord, raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
        }
        Entity entity = null;
        List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expandXyz(1.0D));
        double d0 = 0.0D;
        boolean flag = false;
        for (int i = 0; i < list.size(); ++i)
        {
            Entity entity1 = (Entity)list.get(i);
            if (entity1.canBeCollidedWith())
            {
                if (entity1 == this.field_184539_c)
                {
                    flag = true;
                }
                else if (this.ticksExisted < 2 && this.field_184539_c == null)
                {
                    this.field_184539_c = entity1;
                    flag = true;
                }
                else
                {
                    flag = false;
                    AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expandXyz(0.30000001192092896D);
                    RayTraceResult raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
                    if (raytraceresult1 != null)
                    {
                        double d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec);
                        if (d1 < d0 || d0 == 0.0D)
                        {
                            entity = entity1;
                            d0 = d1;
                        }
                    }
                }
            }
        }
        if (this.field_184539_c != null)
        {
            if (flag)
            {
                this.field_184540_av = 2;
            }
            else if (this.field_184540_av-- <= 0)
            {
                this.field_184539_c = null;
            }
        }
        if (entity != null)
        {
            raytraceresult = new RayTraceResult(entity);
        }
        if (raytraceresult != null)
        {
            if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && this.worldObj.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.PORTAL)
            {
                this.setPortal(raytraceresult.getBlockPos());
            }
            else
            {
                this.onImpact(raytraceresult);
            }
        }
        this.posX += this.motionX;
        this.posY += this.motionY;
        this.posZ += this.motionZ;
        float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
        this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
        for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
        while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
        {
            this.prevRotationPitch += 360.0F;
        }
        while (this.rotationYaw - this.prevRotationYaw < -180.0F)
        {
            this.prevRotationYaw -= 360.0F;
        }
        while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
        {
            this.prevRotationYaw += 360.0F;
        }
        this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
        this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
        float f1 = 0.95F;
        float f2 = this.getGravityVelocity();
        if (this.isInWater())
        {
            for (int j = 0; j < 4; ++j)
            {
                float f3 = 0.0F;
                this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / -2 - worldObj.rand.nextFloat()) / -1, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, 0, 0, 0);
            }
            f1 = 0.8F;
        }
        this.motionX *= (double)f1;
        this.motionY *= (double)f1;
        this.motionZ *= (double)f1;
        this.motionY -= (double)f2;
        this.setPosition(this.posX, this.posY, this.posZ);
    }
    protected float getGravityVelocity()
    {
        return 0.0F;
    }
    protected abstract void onImpact(RayTraceResult result);
    public void writeEntityToNBT(NBTTagCompound tagCompound)
    {
        tagCompound.setInteger("xTile", this.xTile);
        tagCompound.setInteger("yTile", this.yTile);
        tagCompound.setInteger("zTile", this.zTile);
        ResourceLocation resourcelocation = (ResourceLocation)Block.REGISTRY.getNameForObject(this.inTile);
        tagCompound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
        tagCompound.setByte("shake", (byte)this.throwableShake);
        tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
        if ((this.throwerName == null || this.throwerName.isEmpty()) && this.thrower instanceof EntityPlayer)
        {
            this.throwerName = this.thrower.getName();
        }
        tagCompound.setString("ownerName", this.throwerName == null ? "" : this.throwerName);
    }
    public void readEntityFromNBT(NBTTagCompound tagCompund)
    {
        this.xTile = tagCompund.getInteger("xTile");
        this.yTile = tagCompund.getInteger("yTile");
        this.zTile = tagCompund.getInteger("zTile");
        if (tagCompund.hasKey("inTile", )
        {
            this.inTile = Block.getBlockFromName(tagCompund.getString("inTile"));
        }
        else
        {
            this.inTile = Block.getBlockById(tagCompund.getByte("inTile") & 255);
        }
        this.throwableShake = tagCompund.getByte("shake") & 255;
        this.inGround = tagCompund.getByte("inGround") == 1;
        this.thrower = null;
        this.throwerName = tagCompund.getString("ownerName");
        if (this.throwerName != null && this.throwerName.isEmpty())
        {
            this.throwerName = null;
        }
        this.thrower = this.getThrower();
    }
    public EntityLivingBase getThrower()
    {
        if (this.thrower == null && this.throwerName != null && !this.throwerName.isEmpty())
        {
            this.thrower = this.worldObj.getPlayerEntityByName(this.throwerName);

            if (this.thrower == null && this.worldObj instanceof WorldServer)
            {
                try
                {
                    Entity entity = ((WorldServer)this.worldObj).getEntityFromUuid(UUID.fromString(this.throwerName));
                    if (entity instanceof EntityLivingBase)
                    {
                        this.thrower = (EntityLivingBase)entity;
                    }
                }
                catch (Throwable var2)
                {
                    this.thrower = null;
                }
            }
        }     
        return this.thrower;
    }
}

 

Posted

You might be teleporting to Y=6... Because you specifically make your code teleport to Y=6...

playerIn.posY = 6.8;

You know.. Just possibly

 

I have discovered I can hold shift and right click then spam it to reproduce without the logs. (it functions differently with the logs)

It does not happen if there is no spam clicking... the entity is spawned in 6.8 above my player and then comes down, and hits him.

 

Like I can walk around and shift right click all day as long as I don't spam it. Do it as many times as I like, the buff is applied and I run around. But when spammed, the story is completely different resulting in being teleported to 6.8.

 

Sure it says my player is at y=6.8, but I'm basically lieing to my entity, saying that I'm 6.8 above where I am.

The entity is spawned in 6.8 above my players head. (something like that anyways.)

 

This also has very different results from the workspace forge src than after I've built it and ran it on the real deal.

In the workspace if I stand on a flat roof and do this, I will go down to where there is open space. (like roof top to inside of a room). Not y=6. With built version though, this doesn't function and instead teleports me to 6.8 only if I spam it.

Posted

Don't change the player's position.

EntityThrowable

has a method called

setPosition(x, y, z)

.

After you create your entity, but before you spawn it, use said method to change it's y-level. Don't mess with the player's position for something like this.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

Don't change the player's position.

EntityThrowable

has a method called

setPosition(x, y, z)

.

After you create your entity, but before you spawn it, use said method to change it's y-level. Don't mess with the player's position for something like this.

 

Are there consequences?

Posted

Don't change the player's position.

EntityThrowable

has a method called

setPosition(x, y, z)

.

After you create your entity, but before you spawn it, use said method to change it's y-level. Don't mess with the player's position for something like this.

 

Are there consequences?

 

Other than the fact the player is sucked down the Y levels unexpectedly which if you're not in a super flat world, could be sucked into blocks. And die.

 

else if (!worldIn.isRemote && playerIn.isSneaking())

        {

       

        EntityAetherOrb entitythrowable = new EntityAetherOrb(worldIn, playerIn);

        playerIn.posY = 0; // Don't do this

        playerIn.posY = 6.8; // or This

            entitythrowable.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 0.001F, 0.0F);

            entitythrowable.addVelocity(0.0, -0.1, 0.0);

            worldIn.spawnEntityInWorld(entitythrowable);

        }

 

Matryoshika has given you the correct fix for this issue.

When dealing with any POSTITION change if you want it to be "Relative" it should always be:

 

newPos = oldPos + offSet;

 

using things like you did of "newPos = offSet" is magically force it to that coord.

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.