Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TeleportCrystalItem extends Item {
- public TeleportCrystalItem(Properties pProperties) {
- super(pProperties);
- }
- @Override
- public InteractionResult useOn(UseOnContext context) {
- Level world = context.getLevel();
- Player player = context.getPlayer();
- BlockPos pos = context.getClickedPos();
- if(player.isCrouching() || player.isShiftKeyDown()) {
- ItemStack stack = player.getMainHandItem();
- CompoundTag tags = stack.getTag();
- if(stack.getTag() == null) {
- stack.setTag(new CompoundTag());
- tags = stack.getTag();
- }
- tags.putString("hasInfo", "hasInfo");
- tags.putInt("x", pos.getX());
- tags.putInt("y", pos.getY());
- tags.putInt("z", pos.getZ());
- ResourceKey resourceKey = player.level.dimension();
- ResourceLocation name = resourceKey.location();
- tags.putString(Constants.DIMENSION, name.toString());
- tags.putString(Constants.DIMENSION_NAME, name.getPath());
- if(!world.isClientSide) {
- player.sendMessage(new TextComponent(ChatFormatting.GREEN + "This crystal is linked at: " +
- tags.getInt("x") + ", " +
- tags.getInt("y") + ", " +
- tags.getInt("z")), player.getUUID());
- }
- player.playSound(SoundEvents.ENDERMAN_TELEPORT, 1,1);
- return InteractionResult.SUCCESS;
- }
- return InteractionResult.PASS;
- }
- @Override
- public void appendHoverText(ItemStack stack, @Nullable Level pLevel, List<Component> tooltip, TooltipFlag pIsAdvanced) {
- CompoundTag tags = stack.getTag();
- if(Screen.hasShiftDown()) {
- if(tags == null) {
- tooltip.add(new TextComponent(ChatFormatting.RED + "Unlinked"));
- tooltip.add(new TextComponent(ChatFormatting.BLUE + "Sneak + Right click a block to link."));
- } else {
- if(tags.contains("x")) {
- tooltip.add(new TextComponent(ChatFormatting.GREEN + "Linked: "));
- tooltip.add(new TextComponent(ChatFormatting.YELLOW + "Dimension: " + TotisPlayerUtils.getDimensionName(stack)));
- tooltip.add(new TextComponent(ChatFormatting.LIGHT_PURPLE + "Position: " + tags.getInt("x") + ", " + tags.getInt("y") + ", " + tags.getInt("z")));
- } else {
- tooltip.add(new TextComponent(ChatFormatting.RED + "Unlinked"));
- tooltip.add(new TextComponent(ChatFormatting.BLUE + "Sneak + Right click a block to link."));
- }
- }
- } else {
- tooltip.add(new TextComponent("Hold " + ChatFormatting.YELLOW + "SHIFT" + ChatFormatting.RESET + " for more information"));
- }
- super.appendHoverText(stack, pLevel, tooltip, pIsAdvanced);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement