All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.hendrixshen.magiclib.util.minecraft.TextUtil Maven / Gradle / Ivy

There is a newer version: 0.6.59
Show newest version
/*
 * This file is part of the Carpet TIS Addition project, licensed under the
 * GNU Lesser General Public License v3.0
 *
 * Copyright (C) 2023  Fallen_Breath and contributors
 *
 * Carpet TIS Addition is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Carpet TIS Addition is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Carpet TIS Addition.  If not, see .
 */

package top.hendrixshen.magiclib.util.minecraft;

import net.minecraft.class_1297;
import net.minecraft.class_1657;
import net.minecraft.class_1923;
import net.minecraft.class_2248;
import net.minecraft.class_2259;
import net.minecraft.class_2382;
import net.minecraft.class_243;
import net.minecraft.class_2680;
import net.minecraft.class_2769;
import org.jetbrains.annotations.NotNull;
import top.hendrixshen.magiclib.impl.compat.minecraft.world.level.dimension.DimensionWrapper;

/**
 * Reference to Carpet-TIS-Addition
 *
 * 

* Minecraft related stuffs -> String */ public class TextUtil { public static String tp(@NotNull class_243 pos) { return String.format("/tp %s %s %s", pos.method_10216(), pos.method_10214(), pos.method_10215()); } public static String tp(@NotNull class_2382 pos) { return String.format("/tp %d %d %d", pos.method_10263(), pos.method_10264(), pos.method_10260()); } public static String tp(@NotNull class_1923 pos) { return String.format("/tp %d ~ %d", pos.field_9181 * 16 + 8, pos.field_9180 * 16 + 8); } public static @NotNull String tp(class_243 pos, DimensionWrapper dimensionType) { return String.format("/execute in %s run", dimensionType) + TextUtil.tp(pos).replace('/', ' '); } public static @NotNull String tp(class_2382 pos, DimensionWrapper dimensionType) { return String.format("/execute in %s run", dimensionType) + TextUtil.tp(pos).replace('/', ' '); } public static @NotNull String tp(class_1923 pos, DimensionWrapper dimensionType) { return String.format("/execute in %s run", dimensionType) + TextUtil.tp(pos).replace('/', ' '); } public static String tp(class_1297 entity) { if (entity instanceof class_1657) { String name = ((class_1657) entity).method_7334().getName(); return String.format("/tp %s", name); } String uuid = entity.method_5667().toString(); return String.format("/tp %s", uuid); } public static String coordinate(@NotNull class_243 pos) { return String.format("[%.1f, %.1f, %.1f]", pos.method_10216(), pos.method_10214(), pos.method_10215()); } public static String coordinate(@NotNull class_2382 pos) { return String.format("[%d, %d, %d]", pos.method_10263(), pos.method_10264(), pos.method_10260()); } public static String coordinate(@NotNull class_1923 pos) { return String.format("[%d, %d]", pos.field_9181, pos.field_9180); } public static String vector(@NotNull class_243 vec, int digits) { return String.format("(%s, %s, %s)", StringUtil.fractionDigit(vec.method_10216(), digits), StringUtil.fractionDigit(vec.method_10214(), digits), StringUtil.fractionDigit(vec.method_10215(), digits)); } public static String vector(class_243 vec) { return TextUtil.vector(vec, 2); } public static String block(class_2248 block) { return ResourceLocationUtil.id(block).toString(); } public static @NotNull String block(class_2680 blockState) { return class_2259.method_9685(blockState); } @SuppressWarnings("unchecked") public static > String property(@NotNull class_2769 property, Object value) { return property.method_11901((T) value); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy