Posted January 3, 20214 yr 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 January 3, 20214 yr by Unreal_Uzbek
January 3, 20214 yr 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.