Advertisement
Guest User

Untitled

a guest
Feb 19th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. public class TeleportCrystalItem extends Item {
  2.  
  3. public TeleportCrystalItem(Properties pProperties) {
  4. super(pProperties);
  5. }
  6.  
  7. @Override
  8. public InteractionResult useOn(UseOnContext context) {
  9. Level world = context.getLevel();
  10. Player player = context.getPlayer();
  11. BlockPos pos = context.getClickedPos();
  12.  
  13. if(player.isCrouching() || player.isShiftKeyDown()) {
  14. ItemStack stack = player.getMainHandItem();
  15. CompoundTag tags = stack.getTag();
  16. if(stack.getTag() == null) {
  17. stack.setTag(new CompoundTag());
  18. tags = stack.getTag();
  19. }
  20.  
  21. tags.putString("hasInfo", "hasInfo");
  22. tags.putInt("x", pos.getX());
  23. tags.putInt("y", pos.getY());
  24. tags.putInt("z", pos.getZ());
  25. ResourceKey resourceKey = player.level.dimension();
  26. ResourceLocation name = resourceKey.location();
  27. tags.putString(Constants.DIMENSION, name.toString());
  28. tags.putString(Constants.DIMENSION_NAME, name.getPath());
  29.  
  30. if(!world.isClientSide) {
  31. player.sendMessage(new TextComponent(ChatFormatting.GREEN + "This crystal is linked at: " +
  32. tags.getInt("x") + ", " +
  33. tags.getInt("y") + ", " +
  34. tags.getInt("z")), player.getUUID());
  35. }
  36. player.playSound(SoundEvents.ENDERMAN_TELEPORT, 1,1);
  37.  
  38. return InteractionResult.SUCCESS;
  39. }
  40. return InteractionResult.PASS;
  41. }
  42.  
  43. @Override
  44. public void appendHoverText(ItemStack stack, @Nullable Level pLevel, List<Component> tooltip, TooltipFlag pIsAdvanced) {
  45. CompoundTag tags = stack.getTag();
  46. if(Screen.hasShiftDown()) {
  47. if(tags == null) {
  48. tooltip.add(new TextComponent(ChatFormatting.RED + "Unlinked"));
  49. tooltip.add(new TextComponent(ChatFormatting.BLUE + "Sneak + Right click a block to link."));
  50. } else {
  51. if(tags.contains("x")) {
  52. tooltip.add(new TextComponent(ChatFormatting.GREEN + "Linked: "));
  53. tooltip.add(new TextComponent(ChatFormatting.YELLOW + "Dimension: " + TotisPlayerUtils.getDimensionName(stack)));
  54. tooltip.add(new TextComponent(ChatFormatting.LIGHT_PURPLE + "Position: " + tags.getInt("x") + ", " + tags.getInt("y") + ", " + tags.getInt("z")));
  55. } else {
  56. tooltip.add(new TextComponent(ChatFormatting.RED + "Unlinked"));
  57. tooltip.add(new TextComponent(ChatFormatting.BLUE + "Sneak + Right click a block to link."));
  58. }
  59. }
  60. } else {
  61. tooltip.add(new TextComponent("Hold " + ChatFormatting.YELLOW + "SHIFT" + ChatFormatting.RESET + " for more information"));
  62. }
  63. super.appendHoverText(stack, pLevel, tooltip, pIsAdvanced);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement