use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.
the class UnicodeGlyphButton method render.
@Override
public void render(PoseStack mStack, int mouseX, int mouseY, float partial) {
if (this.visible) {
Minecraft mc = Minecraft.getInstance();
this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
int k = this.getYImage(this.isHovered);
GuiUtils.drawContinuousTexturedBox(mStack, WIDGETS_LOCATION, this.x, this.y, 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, this.getBlitOffset());
this.renderBg(mStack, mc, mouseX, mouseY);
Component buttonText = this.createNarrationMessage();
int glyphWidth = (int) (mc.font.width(glyph) * glyphScale);
int strWidth = mc.font.width(buttonText);
int ellipsisWidth = mc.font.width("...");
int totalWidth = strWidth + glyphWidth;
if (totalWidth > width - 6 && totalWidth > ellipsisWidth)
buttonText = new TextComponent(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString().trim() + "...");
strWidth = mc.font.width(buttonText);
totalWidth = glyphWidth + strWidth;
mStack.pushPose();
mStack.scale(glyphScale, glyphScale, 1.0F);
this.drawCenteredString(mStack, mc.font, new TextComponent(glyph), (int) (((this.x + (this.width / 2) - (strWidth / 2)) / glyphScale) - (glyphWidth / (2 * glyphScale)) + 2), (int) (((this.y + ((this.height - 8) / glyphScale) / 2) - 1) / glyphScale), getFGColor());
mStack.popPose();
this.drawCenteredString(mStack, mc.font, buttonText, (int) (this.x + (this.width / 2) + (glyphWidth / glyphScale)), this.y + (this.height - 8) / 2, getFGColor());
}
}
use of net.minecraft.network.chat.TextComponent in project MyPet by xXKeyleXx.
the class CustomInventory method open.
@Override
public void open(Player player) {
ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
if (container != null) {
MenuType<?> customSize = MenuType.GENERIC_9x1;
switch(this.getContainerSize()) {
case 18:
customSize = MenuType.GENERIC_9x2;
break;
case 27:
customSize = MenuType.GENERIC_9x3;
break;
case 36:
customSize = MenuType.GENERIC_9x4;
break;
case 45:
customSize = MenuType.GENERIC_9x5;
break;
case 54:
customSize = MenuType.GENERIC_9x6;
break;
}
entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
entityPlayer.containerMenu = container;
entityPlayer.initMenu(container);
}
}
use of net.minecraft.network.chat.TextComponent in project MyPet by xXKeyleXx.
the class CustomInventory method open.
@Override
public void open(Player player) {
ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
if (container != null) {
MenuType<?> customSize = MenuType.GENERIC_9x1;
switch(this.getContainerSize()) {
case 18:
customSize = MenuType.GENERIC_9x2;
break;
case 27:
customSize = MenuType.GENERIC_9x3;
break;
case 36:
customSize = MenuType.GENERIC_9x4;
break;
case 45:
customSize = MenuType.GENERIC_9x5;
break;
case 54:
customSize = MenuType.GENERIC_9x6;
break;
}
entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
entityPlayer.containerMenu = container;
entityPlayer.initMenu(container);
}
}
use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.
the class AddPackFinderEventTest method addPackFinders.
@SubscribeEvent
public static void addPackFinders(AddPackFindersEvent event) {
try {
if (event.getPackType() == PackType.CLIENT_RESOURCES) {
var resourcePath = ModList.get().getModFileById(MODID).getFile().findResource("test_nested_resource_pack");
var pack = new PathResourcePack(ModList.get().getModFileById(MODID).getFile().getFileName() + ":" + resourcePath, resourcePath);
var metadataSection = pack.getMetadataSection(PackMetadataSection.SERIALIZER);
if (metadataSection != null) {
event.addRepositorySource((packConsumer, packConstructor) -> packConsumer.accept(packConstructor.create("builtin/add_pack_finders_test", new TextComponent("display name"), false, () -> pack, metadataSection, Pack.Position.BOTTOM, PackSource.BUILT_IN, false)));
}
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.
the class ClientCommandTest method init.
private void init(RegisterClientCommandsEvent event) {
event.getDispatcher().register(Commands.literal("clientcommandtest").then(Commands.literal("rawsuggest").then(Commands.argument("block", ResourceLocationArgument.id()).suggests((c, b) -> SharedSuggestionProvider.suggestResource(ForgeRegistries.BLOCKS.getKeys(), b)).executes(this::testCommand))).then(Commands.literal("registeredsuggest").then(Commands.argument("block", ResourceLocationArgument.id()).suggests(SuggestionProviders.AVAILABLE_BIOMES).executes(this::testCommand))).then(Commands.literal("server").executes((context) -> {
context.getSource().getServer();
context.getSource().sendSuccess(new TextComponent("Successfully called getServer should have errored"), false);
return 1;
})).then(Commands.literal("level").executes((context) -> {
context.getSource().getLevel();
context.getSource().sendSuccess(new TextComponent("Successfully called getLevel should have errored"), false);
return 1;
})).then(Commands.literal("get_objective").then(Commands.argument("objective", ObjectiveArgument.objective()).executes((context) -> {
context.getSource().sendSuccess(new TextComponent("Regular: ").append(ObjectiveArgument.getObjective(context, "objective").getFormattedDisplayName()), false);
return 1;
}))).then(Commands.literal("get_advancement").then(Commands.argument("advancement", ResourceLocationArgument.id()).executes((context) -> {
context.getSource().sendSuccess(ResourceLocationArgument.getAdvancement(context, "advancement").getChatComponent(), false);
return 1;
}))).then(Commands.literal("get_recipe").then(Commands.argument("recipe", ResourceLocationArgument.id()).executes((context) -> {
context.getSource().sendSuccess(ResourceLocationArgument.getRecipe(context, "recipe").getResultItem().getDisplayName(), false);
return 1;
}))).then(Commands.literal("get_team").then(Commands.argument("team", TeamArgument.team()).executes((context) -> {
context.getSource().sendSuccess(TeamArgument.getTeam(context, "team").getFormattedDisplayName(), false);
return 1;
}))).then(Commands.literal("get_loaded_blockpos").then(Commands.argument("blockpos", BlockPosArgument.blockPos()).executes((context) -> {
context.getSource().sendSuccess(new TextComponent(BlockPosArgument.getLoadedBlockPos(context, "blockpos").toString()), false);
return 1;
}))).then(Commands.literal("requires").requires((source) -> false).executes((context) -> {
context.getSource().sendSuccess(new TextComponent("Executed command"), false);
return 1;
})));
// Used for testing that client command redirects can only be used with client commands
LiteralArgumentBuilder<CommandSourceStack> fork = Commands.literal("clientcommandfork");
fork.fork(event.getDispatcher().getRoot(), (context) -> List.of(context.getSource(), context.getSource())).executes((context) -> {
context.getSource().sendSuccess(new TextComponent("Executing forked command"), false);
return 1;
});
event.getDispatcher().register(fork);
}
Aggregations