Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.1] Teleport In Line of Sight


urbanxx001
 Share

Recommended Posts

In the following effect method, I'd like the player to teleport to a block that's within their line of site. It does so by iterating over positions in the sight vector over a distance (16 in this case). There's no response in game however. Alternatively, I tested setPositionAndUpdate without flag3, which is the raw function used in attemptTeleport, but this gives wild results, with teleports that don't match the line of sight and often clip under the world. Any help is appreciated.

@Override
public void performEffect(LivingEntity entityLiving, int amplifier) {
    Minecraft instance = Minecraft.getInstance();

    final Vector3d vLook = entityLiving.getLook(1.0F);
    int d = 16;

    for (int i = 1; i <= d; i++) {
        double bX = vLook.getX() * i;
        double bY = vLook.getY() * i;
        double bZ = vLook.getY() * i;

        BlockPos.Mutable blockpos$mutable = new BlockPos.Mutable(bX, bY, bZ);
        assert instance.world != null;
        boolean flag1 = instance.world.getBlockState(blockpos$mutable).getMaterial().blocksMovement();
        boolean flag2 = i == d;
        boolean flag3 = entityLiving.attemptTeleport(bX, bY, bZ, true);

        if ((flag1 || flag2) && flag3) {
            //entityLiving.setPositionAndUpdate(bX, bY, bZ);
            SoundEvent soundevent = SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT;
            instance.world.playSound(null, entityLiving.prevPosX, entityLiving.prevPosY, entityLiving.prevPosZ, soundevent, SoundCategory.PLAYERS, 1.0F, 1.0F);
            entityLiving.playSound(soundevent, 1.0F, 1.0F);
        }
    }
}

 

Edited by urbanxx001
Link to comment
Share on other sites

42 minutes ago, urbanxx001 said:

BlockPos.Mutable blockpos$mutable = new BlockPos.Mutable(bX, bY, bZ);

Why are you suing a mutable blockpos when you aren't reusing it?

 

43 minutes ago, urbanxx001 said:

assert instance.world != null;

What the fuck.

43 minutes ago, urbanxx001 said:

        boolean flag1 = instance.world.getBlockState(blockpos$mutable).getMaterial().blocksMovement();
        boolean flag2 = i == d;
        boolean flag3 = entityLiving.attemptTeleport(bX, bY, bZ, true);

        if ((flag1 || flag2) && flag3) {

Jesus christ. Inline this garbage or use intelligent variable names.

44 minutes ago, urbanxx001 said:

if ((flag1 || flag2) && flag3) {


"If the block blocks movement (player is not allowed to stand there) or we've reached max distance (we don't fucking care), then put the player inside that block. Yes, INSIDE the NON WALKABLE BLOCK."

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

12 minutes ago, Draco18s said:

Why are you suing a mutable blockpos when you aren't reusing it?

Originally used for updating the Blockstate Y position in another loop. Was playing around with the loop, but removed it. The world null line is just to suppress a message that pops up in the editor. 

16 minutes ago, Draco18s said:

Inline this garbage or use intelligent variable names.

Flag is a good name as that's what they're used for. But I guess what you're saying is that their purpose isn't immediately obvious to someone else reviewing the code. 

21 minutes ago, Draco18s said:

Yes, INSIDE the NON WALKABLE BLOCK."

You're right it should tp around that position instead, thanks for catching that. Will fix it. 

Link to comment
Share on other sites

1 minute ago, urbanxx001 said:

Flag is a good name as that's what they're used for.

"flag" tells you nothing about what the variable means. Without looking at their definitions, can you tell me what flag1, flag2 and flag3 do? No.

Without looking at its definition, can you tell me what playerInsideBlock means? Yes. That is what makes a good variable name.

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.