use of net.minecraft.text.ClickEvent in project Carrier by GabrielOlvH.
the class Carrier method onInitialize.
@Override
public void onInitialize() {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
File file = new File(FabricLoader.getInstance().getConfigDir().toFile(), "carrier.json");
if (!file.exists()) {
try {
if (!file.createNewFile())
throw new IOException("Failed to create file");
FileUtils.write(file, gson.toJson(CONFIG), StandardCharsets.UTF_8);
} catch (IOException e) {
LogManager.getLogger("Carrier").error("Failed to create carrier config");
throw new RuntimeException(e);
}
} else {
try {
String lines = String.join("\n", FileUtils.readLines(file, StandardCharsets.UTF_8));
CONFIG = gson.fromJson(lines, Config.class);
} catch (IOException e) {
LogManager.getLogger("Carrier").error("Failed to read config");
throw new RuntimeException(e);
}
}
ServerTickEvents.END_WORLD_TICK.register(new ServerWorldTickCallback());
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_cow"), new CarriableCow());
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_chicken"), new CarriableChicken());
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_parrot"), new CarriableParrot());
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_pig"), new CarriablePig());
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_rabbit"), new CarriableRabbit());
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_sheep"), new CarriableSheep());
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_turtle"), new CarriableTurtle());
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_wolf"), new CarriableWolf());
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_spawner"), new CarriableSpawner(new Identifier(MOD_ID, "minecraft_spawner")));
CarriableRegistry.INSTANCE.register(new Identifier(MOD_ID, "minecraft_enchanting_table"), new CarriableEnchantingTable(new Identifier(MOD_ID, "minecraft_enchanting_table")));
Registry.BLOCK.forEach((block) -> {
Identifier id = Registry.BLOCK.getId(block);
Identifier type = new Identifier("carrier", id.getNamespace() + "_" + id.getPath());
registerGenericCarriable(block, type);
});
RegistryEntryAddedCallback.event(Registry.BLOCK).register((rawId, id, block) -> {
Identifier type = new Identifier("carrier", id.getNamespace() + "_" + id.getPath());
registerGenericCarriable(block, type);
});
Registry.register(Registry.ITEM, new Identifier(MOD_ID, "glove"), ITEM_GLOVE);
if (CONFIG.doGlovesExist()) {
RuntimeResourcePack resourcePack = RuntimeResourcePack.create(MOD_ID + ":gloves");
resourcePack.addRecipe(new Identifier(MOD_ID, "gloves"), JRecipe.shaped(JPattern.pattern("L ", "LL "), JKeys.keys().key("L", JIngredient.ingredient().item("minecraft:leather")), JResult.item(ITEM_GLOVE)));
RRPCallback.EVENT.register(packs -> packs.add(resourcePack));
}
ServerSidePacketRegistry.INSTANCE.register(SET_CAN_CARRY_PACKET, (ctx, buf) -> {
boolean canCarry = buf.readBoolean();
ctx.getTaskQueue().execute(() -> ((CarrierPlayerExtension) ctx.getPlayer()).setCanCarry(canCarry));
});
CommandRegistrationCallback.EVENT.register((commandDispatcher, b) -> commandDispatcher.register(CommandManager.literal("carrierinfo").executes((ctx) -> {
ServerPlayerEntity player = ctx.getSource().getPlayer();
NbtCompound tag = new NbtCompound();
HOLDER.get(player).writeToNbt(tag);
ctx.getSource().sendFeedback(new LiteralText(tag.toString()), false);
return 1;
})));
CommandRegistrationCallback.EVENT.register((commandDispatcher, b) -> commandDispatcher.register(CommandManager.literal("carrierdelete").executes((ctx) -> {
ServerPlayerEntity player = ctx.getSource().getPlayer();
CarrierComponent component = HOLDER.get(player);
NbtCompound tag = new NbtCompound();
component.writeToNbt(tag);
component.setCarryingData(null);
ctx.getSource().sendFeedback(new LiteralText("Deleted ").append(new LiteralText(tag.toString()).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, tag.toString())))), false);
return 1;
})));
CommandRegistrationCallback.EVENT.register((commandDispatcher, b) -> commandDispatcher.register(CommandManager.literal("carrierplace").executes((ctx) -> {
ServerPlayerEntity player = ctx.getSource().getPlayer();
CarrierComponent component = HOLDER.get(player);
Carriable<Object> carriable = CarriableRegistry.INSTANCE.get(component.getCarryingData().getType());
BlockPos pos = player.getBlockPos().offset(player.getHorizontalFacing());
ServerWorld world = ctx.getSource().getWorld();
if (!world.getBlockState(pos).getMaterial().isReplaceable()) {
ctx.getSource().sendFeedback(new LiteralText("Could not place! Make sure you have empty space in front of you."), false);
return 1;
}
CarriablePlacementContext placementCtx = new CarriablePlacementContext(component, carriable, pos, player.getHorizontalFacing().getOpposite(), player.getHorizontalFacing());
carriable.tryPlace(component, world, placementCtx);
component.setCarryingData(null);
return 1;
})));
}
use of net.minecraft.text.ClickEvent in project KahzerxMod by otakucraft.
the class ExchangeCommand method register.
public void register(CommandDispatcher<ServerCommandSource> dispatcher, ShopExtension extension) {
dispatcher.register(literal("exchange").requires(server -> extension.extensionSettings().isEnabled()).then(literal("confirm").then(argument("count", IntegerArgumentType.integer(0)).then(argument("item", StringArgumentType.string()).executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
Item item = player.getMainHandStack().getItem();
String sentItem = StringArgumentType.getString(context, "item");
int count = player.getMainHandStack().getCount();
int sentCount = IntegerArgumentType.getInteger(context, "count");
if (!basicVerify(context, player)) {
return 1;
}
if (count != sentCount || !item.getTranslationKey().equals(sentItem)) {
context.getSource().sendFeedback(MarkEnum.CROSS.appendMessage("El stack de tu mano ha cambiado!"), false);
return 1;
}
extension.updateFounds(player, Exchange.getValue(item) * count);
extension.logExchange(player, item, count);
player.setStackInHand(Hand.MAIN_HAND, new ItemStack(Items.AIR));
context.getSource().sendFeedback(MarkEnum.TICK.appendMessage("Añadidos ").append(MarkEnum.OTAKU_COIN.appendMessage(String.valueOf(Exchange.getValue(item) * count))), false);
return 1;
})))).then(literal("abort").then(argument("count", IntegerArgumentType.integer(0)).then(argument("item", StringArgumentType.string()).executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
Item item = player.getMainHandStack().getItem();
String sentItem = StringArgumentType.getString(context, "item");
int count = player.getMainHandStack().getCount();
int sentCount = IntegerArgumentType.getInteger(context, "count");
if (count == sentCount || item.getTranslationKey().equals(sentItem)) {
context.getSource().sendFeedback(MarkEnum.TICK.appendMessage("Exchange cancelado!"), false);
}
return 1;
})))).executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
Item item = player.getMainHandStack().getItem();
int count = player.getMainHandStack().getCount();
if (!basicVerify(context, player)) {
return 1;
}
context.getSource().sendFeedback(MarkEnum.INFO.appendMessage(String.format("Vas a cambiar %d %s por ", count, item.getName().getString())).append(MarkEnum.OTAKU_COIN.appendMessage(String.format("%d", Exchange.getValue(item) * count))), false);
context.getSource().sendFeedback(MarkEnum.QUESTION.appendMessage("Confirmar exchange? ").append(new LiteralText("[Sí]").styled(style -> style.withColor(Formatting.GREEN).withBold(true).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/exchange confirm %d %s", count, item.getTranslationKey()))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("confirmar exchange"))))).append(new LiteralText(" ").styled(style -> style.withColor(Formatting.WHITE))).append(new LiteralText("[No]").styled(style -> style.withColor(Formatting.DARK_RED).withBold(true).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/exchange abort %d %s", count, item.getTranslationKey()))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("cancelar exchange"))))), false);
return 1;
}).then(literal("info").executes(context -> {
context.getSource().sendFeedback(MarkEnum.OTAKU_COIN.appendMessage("a"), false);
return 1;
})));
}
use of net.minecraft.text.ClickEvent in project meteor-client by MeteorDevelopment.
the class NbtCommand method build.
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("add").then(argument("nbt_data", CompoundNbtTagArgumentType.nbtTag()).executes(s -> {
ItemStack stack = mc.player.getInventory().getMainHandStack();
if (validBasic(stack)) {
NbtCompound tag = CompoundNbtTagArgumentType.getTag(s, "nbt_data");
NbtCompound source = stack.getOrCreateNbt();
if (tag != null) {
source.copyFrom(tag);
setStack(stack);
} else {
error("Some of the NBT data could not be found, try using: " + Config.get().prefix.get() + "nbt set {nbt}");
}
}
return SINGLE_SUCCESS;
})));
builder.then(literal("set").then(argument("nbt_data", CompoundNbtTagArgumentType.nbtTag()).executes(s -> {
ItemStack stack = mc.player.getInventory().getMainHandStack();
if (validBasic(stack)) {
NbtCompound tag = s.getArgument("nbt_data", NbtCompound.class);
stack.setNbt(tag);
setStack(stack);
}
return SINGLE_SUCCESS;
})));
builder.then(literal("remove").then(argument("nbt_path", NbtPathArgumentType.nbtPath()).executes(s -> {
ItemStack stack = mc.player.getInventory().getMainHandStack();
if (validBasic(stack)) {
NbtPathArgumentType.NbtPath path = s.getArgument("nbt_path", NbtPathArgumentType.NbtPath.class);
path.remove(stack.getNbt());
}
return SINGLE_SUCCESS;
})));
builder.then(literal("get").executes(s -> {
ItemStack stack = mc.player.getInventory().getMainHandStack();
if (stack == null) {
error("You must hold an item in your main hand.");
} else {
NbtCompound tag = stack.getNbt();
String nbt = tag == null ? "{}" : tag.asString();
BaseText copyButton = new LiteralText("NBT");
copyButton.setStyle(copyButton.getStyle().withFormatting(Formatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, this.toString("copy"))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Copy the NBT data to your clipboard."))));
BaseText text = new LiteralText("");
text.append(copyButton);
text.append(new LiteralText(": " + nbt));
info(text);
}
return SINGLE_SUCCESS;
}));
builder.then(literal("copy").executes(s -> {
ItemStack stack = mc.player.getInventory().getMainHandStack();
if (stack == null) {
error("You must hold an item in your main hand.");
} else {
NbtCompound tag = stack.getOrCreateNbt();
mc.keyboard.setClipboard(tag.toString());
BaseText nbt = new LiteralText("NBT");
nbt.setStyle(nbt.getStyle().withFormatting(Formatting.UNDERLINE).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(tag.toString()))));
BaseText text = new LiteralText("");
text.append(nbt);
text.append(new LiteralText(" data copied!"));
info(text);
}
return SINGLE_SUCCESS;
}));
builder.then(literal("count").then(argument("count", IntegerArgumentType.integer(-127, 127)).executes(context -> {
ItemStack stack = mc.player.getInventory().getMainHandStack();
if (validBasic(stack)) {
int count = IntegerArgumentType.getInteger(context, "count");
stack.setCount(count);
setStack(stack);
info("Set mainhand stack count to %s.", count);
}
return SINGLE_SUCCESS;
})));
}
use of net.minecraft.text.ClickEvent in project meteor-client by MeteorDevelopment.
the class CommandsCommand method getCommandText.
private BaseText getCommandText(Command command) {
// Hover tooltip
BaseText tooltip = new LiteralText("");
tooltip.append(new LiteralText(Utils.nameToTitle(command.getName())).formatted(Formatting.BLUE, Formatting.BOLD)).append("\n");
BaseText aliases = new LiteralText(Config.get().prefix.get() + command.getName());
if (command.getAliases().size() > 0) {
aliases.append(", ");
for (String alias : command.getAliases()) {
if (alias.isEmpty())
continue;
aliases.append(Config.get().prefix.get() + alias);
if (!alias.equals(command.getAliases().get(command.getAliases().size() - 1)))
aliases.append(", ");
}
}
tooltip.append(aliases.formatted(Formatting.GRAY)).append("\n\n");
tooltip.append(new LiteralText(command.getDescription()).formatted(Formatting.WHITE));
// Text
BaseText text = new LiteralText(Utils.nameToTitle(command.getName()));
if (command != Commands.get().getAll().get(Commands.get().getAll().size() - 1))
text.append(new LiteralText(", ").formatted(Formatting.GRAY));
text.setStyle(text.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip)).withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, Config.get().prefix.get() + command.getName())));
return text;
}
use of net.minecraft.text.ClickEvent in project carpet-discarpet by replaceitem.
the class DiscarpetCommand method register.
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("discarpet").requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2)).executes(commandContext -> {
String version = FabricLoader.getInstance().getModContainer("discarpet").get().getMetadata().getVersion().getFriendlyString();
MutableText text = new LiteralText("Discarpet version " + version).formatted(Formatting.BLUE);
text.append("\nFor help, see the ");
text.append(new LiteralText("documentation").setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/replaceitem/carpet-discarpet/blob/master/docs/Full.md")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to get to the Discarpet documentation"))).withFormatting(Formatting.UNDERLINE).withColor(Formatting.DARK_BLUE)));
commandContext.getSource().sendFeedback(text, true);
return 1;
}).then(literal("list").executes(commandContext -> {
Set<String> botIDs = Discarpet.discordBots.keySet();
final LiteralText t;
if (botIDs.size() == 0) {
t = (LiteralText) new LiteralText("There are no bots active:\n").formatted(Formatting.RED);
} else {
t = (LiteralText) new LiteralText("There are " + botIDs.size() + " bots active\n").formatted(Formatting.GREEN);
}
botIDs.forEach(id -> t.append(new LiteralText(id + "\n").formatted(Formatting.BLUE)));
commandContext.getSource().sendFeedback(t, true);
return botIDs.size();
})).then(literal("getInvite").then(CommandManager.argument("id", StringArgumentType.string()).suggests(BOTS).executes(commandContext -> {
String id = StringArgumentType.getString(commandContext, "id");
String invite = Discarpet.discordBots.get(id).getInvite();
Text text = ((new LiteralText("Click here to get the invite link for the bot")).styled((style) -> {
return style.withColor(Formatting.BLUE).withFormatting(Formatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, invite)).withHoverEvent(new HoverEvent(net.minecraft.text.HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to open the invite link"))).withInsertion(invite);
}));
commandContext.getSource().sendFeedback(text, false);
return 1;
}))).then(literal("reload").executes(commandContext -> {
Discarpet.loadConfig(commandContext.getSource());
return 1;
})));
}
Aggregations