Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.