Posted August 17, 20205 yr Hello! RayTracing is still a very new concept to me so this code may be very bad. I am making a mod that adds an enchantment that is supposed to teleport the player where the are looking when holding a certain item, enderdust. Currently it works, however the teleportation is very janky. I get teleported backards, side to side, into blocks, and almost never directly where I am looking. Any help would be appreciated. Code for the teleportation event: public class TeleBootEvent { @SubscribeEvent public void teleBoot(PlayerInteractEvent.RightClickItem event) { PlayerEntity player = event.getPlayer(); Vector3d eyePos = player.getEyePosition(1.0F); BlockRayTraceResult result = player.getEntityWorld().rayTraceBlocks(new RayTraceContext(eyePos, player.getLookVec(), RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, player)); double x = result.getPos().getX(); double y = result.getPos().getY(); double z = result.getPos().getZ(); ItemStack armor = player.getItemStackFromSlot(EquipmentSlotType.FEET); ItemStack enderdust = new ItemStack(ObjectHolderStorage.ENDERDUST); if (EnchantmentHelper.getEnchantmentLevel(ObjectHolderStorage.TELEBLINK, armor) > 0) { if (result.getType() == RayTraceResult.Type.BLOCK) { if (player.getHeldItemMainhand().isItemEqual(enderdust)) { player.setPosition(x, y + 0.5, z); } } } } } Edited August 17, 20205 yr by Giga_5
August 17, 20205 yr 1st: In 1.15 the 2nd parameter of RayTraceContext#new was not a direction, but rather another position. If that is still the case, then in your case you would have to do something like: new RayTraceContext(eyePos, eyePos.add(player.getLookVec().scale(RANGE)), RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, player) 2nd: Out of curiosity: Why are you using ItemStack#isItemEqual instead of just comparing the items? Is NBT important here? https://github.com/CAS-ual-TY/Visibilis [1.14] How to Villagers, Trades, Professions, Fix Trades https://minecraft.curseforge.com/projects/gun-customization-infinity / https://github.com/CAS-ual-TY/GunCus https://minecraft.curseforge.com/projects/ygo-dueling-mod https://minecraft.curseforge.com/projects/mundus-magicus https://minecraft.curseforge.com/projects/deuf-duplicate-entity-uuid-fix
August 17, 20205 yr Author Ahh it worked! thank you for the help. 5 hours ago, CAS_ual_TY said: 2nd: Out of curiosity: Why are you using ItemStack#isItemEqual instead of just comparing the items? Is NBT important here? I plan on adding different "types" of enderdust soon to teleport different lengths, I just havent done the NBT stuff yet
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.