Jump to content

Recommended Posts

Posted

Use rayTracing.

Before 1.8 client look vector was on players eyes, server one was not.

 

Since 1.8 both are from eyes, but vanilla method is for client only. Copy vanilla rayTracing method and use it on server.

Note: Find here: Entity#rayTrace

1.7.10 is no longer supported by forge, you are on your own.

Posted

I guess I got it. Only problem is, I am not sure what the two float values the method is taking do.

public MovingObjectPosition rayTrace(double p_174822_1_, float p_174822_3_)

It should be something with the direction the player is looking at, if im right. So it might be player.camerapitch/camerayaw?

Posted

Explanation from diesieben07 for partialTickTime: http://www.minecraftforge.net/forum/index.php/topic,12681.msg65852.html#msg65852.

In your case, because you don't have a partialTickTime available, you can just use 1.0F as the partialTickTime. And yes, you are right about the distance.

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/

Posted

Well. The RayTrace seems to NEVER hit an entity, even if I am spawning a whole zoo around me.

 

MovingObjectPosition pos = Methods.rayTrace(ext.getEntity(), 10f,1f);
	System.out.println(pos);
	if(pos!=null && pos.entityHit!=null)
	{
		System.out.println("call");
		Entity entityHit= pos.entityHit;
		entityHit.attackEntityFrom(DamageSource.causePlayerDamage(ext.getEntity()), 2);

	}

 

public static MovingObjectPosition rayTrace(Entity entity, double distance, float p_174822_3_)
    {
        Vec3 vec3 = entity.getPositionEyes(p_174822_3_);
        Vec3 vec31 = entity.getLook(p_174822_3_);
        Vec3 vec32 = vec3.addVector(vec31.xCoord * distance, vec31.yCoord * distance, vec31.zCoord * distance);
        return entity.worldObj.rayTraceBlocks(vec3, vec32, false, false, true);
    }

 private static Vec3 getPositionEyes(Entity entity, float p_174824_1_)
 {
	 if (p_174824_1_ == 1.0F)
	 {
		 return new Vec3(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ);
     }
	 else
     {
		 double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double)p_174824_1_;
		 double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double)p_174824_1_ + (double)entity.getEyeHeight();
		 double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)p_174824_1_;
		 return new Vec3(d0, d1, d2);
     }
 }

 

 

Posted

I never knew what is the best way to get entities, BUT I know this. Let's say your vector is arrow, you entity is some box. To know that arrow hit box you need to check if vector is "touching" box. You need to actually do that.

 

Have a look at EntityThrowable#onUpdate()

Vec3 vec3 = new Vec3(this.posX, this.posY, this.posZ);
        Vec3 vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
        vec3 = new Vec3(this.posX, this.posY, this.posZ);
        vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

        if (movingobjectposition != null)
        {
            vec31 = new Vec3(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
        }

        if (!this.worldObj.isRemote)
        {
            Entity entity = null;
            List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
            double d0 = 0.0D;
            EntityLivingBase entitylivingbase = this.getThrower();

            for (int j = 0; j < list.size(); ++j)
            {
                Entity entity1 = (Entity)list.get(j);

                if (entity1.canBeCollidedWith() && (entity1 != entitylivingbase || this.ticksInAir >= 5))
                {
                    float f = 0.3F;
                    AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand((double)f, (double)f, (double)f);
                    MovingObjectPosition movingobjectposition1 = axisalignedbb.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)
        {
            if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.worldObj.getBlockState(movingobjectposition.getBlockPos()).getBlock() == Blocks.portal)
            {
                this.setInPortal();
            }
            else
            {
                this.onImpact(movingobjectposition);
            }
        }

 

Every tick there is check if EntityThrowable's bounding box touches any other box in 1.0D "lenght" (box size).

That is the way to get the entity hit. Notice how it checks which entity was hit 1st and stuff. Pretty neat.

 

And yes - unless you want to go with VERY complicated 3D math on your own, this is best way provided by vanilla (for me at least).

1.7.10 is no longer supported by forge, you are on your own.

Posted

Guys, it is a really common misconception but the rayTrace() methods only find blocks, not entities. The confusion is that these methods return a MovingObjectPosition which contains fields for entities hit but those will always be null.

 

There is a method called getMouseOver() which ray traces both blocks and entities, but only within the reach distance of the player -- it is used to figure out whether you hit an entity.

 

So I've made my own custom mouse over method which uses the same technique as the built-in mouse over but extends the distance as far as you want. I was able to use the method to create a weapon with "infinite" reach -- basically picking off anything I could see.

 

I'm writing a tutorial on ray tracing, but for now check out my tutorial on the extended reach weapon. It will give you what you need: http://jabelarminecraft.blogspot.com/p/minecraft-modding-extending-reach-of.html

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

got it to work now, thank you jabelar!

Just one thing for your tutorial you've got a thing you should really fix.

In your messagehandler for the server side u should queue up the execution of the task to prevent server crashes.

http://greyminecraftcoder.blogspot.com.au/2015/01/thread-safety-with-network-messages.html

 

Interesting. Yeah the separate thread for networking in 1.8 has created a few gotchas. For example, the timing of packets can sometimes be different that expected which affected the way I was constructing some custom entities with sync packets. Thanks for pointing this out.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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