Jump to content

Recommended Posts

Posted (edited)

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

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.