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

I was moving my mod from 1.12.2 to 1.16.4 and fixed all bugs and problems except this one.

This is an item that teleports you (onItemUseFinish) to coords that player set before (onItemUse (LShift while clicking)). When you set coords, item writes name of dimension to nbt. It teleports you only if dimensions' names are equal. But they are not for some reason. I was printing names and using debug, and these 2 strings are equal, but "IF" doesn't think so and "minecraft:overworld" doesn't equal to "minecraft:overworld".

@Override
public ActionResultType onItemUse(ItemUseContext context) {
  PlayerEntity player = context.getPlayer();
  World world = context.getWorld();
  Hand hand = context.getHand();
  ItemStack itemStack = context.getItem();
  BlockPos pos = context.getPos();
  Vector3d hit = context.getHitVec();
  if(player.isSneaking()) {
    if (world.isRemote == false) {
      ItemStack item = player.getHeldItem(hand);
      CompoundNBT nbt;
      if(itemStack.getTag() != null)
        nbt = item.getTag();
      else
        nbt = new CompoundNBT();
      
      nbt.putDouble("posX", pos.getX()/2 + hit.x);
      nbt.putDouble("posY", pos.getY()/2 + hit.y);
      nbt.putDouble("posZ", pos.getZ()/2 + hit.z);
      nbt.putString("world", world.getDimensionKey().getLocation().toString());
      item.setTag(nbt);
      
      SubstanceAndMind.LOGGER.info(item.getTag().getString("world"));
    }
    return ActionResultType.SUCCESS;
  }
  return ActionResultType.PASS;
}
@Override
  public ItemStack onItemUseFinish(ItemStack stack, World world, LivingEntity entityLiving)
{
  if(entityLiving.isSneaking() == false && entityLiving.getActiveItemStack().hasTag() && entityLiving.getActiveItemStack().getTag().contains("posX") && entityLiving.getActiveItemStack().getTag().contains("posY") && entityLiving.getActiveItemStack().getTag().contains("posZ") && entityLiving.getActiveItemStack().getTag().contains("world"))
  {
    if(world.isRemote == false)
    {
      if (world.getDimensionKey().getLocation().toString() == entityLiving.getActiveItemStack().getTag().getString("world"))
      {
        ItemStack itemStack = entityLiving.getActiveItemStack();
        CompoundNBT tag = itemStack.getTag();
        ((ServerPlayerEntity) entityLiving).setPositionAndUpdate(tag.getDouble("posX"), tag.getDouble("posY"), tag.getDouble("posZ"));
        ((ServerPlayerEntity) entityLiving).getCooldownTracker().setCooldown(this, 80);
      }
    }
  }
  return stack;
}

sorry for bad english.

Edited by Unreal_Uzbek

  • Author

Thanks, i hate Java.

And thanks, it helped me. And I immediately go to hell because this is from basic knowledge of Java.

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.