本文整理汇总了Java中net.minecraft.util.text.Style类的典型用法代码示例。如果您正苦于以下问题:Java Style类的具体用法?Java Style怎么用?Java Style使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Style类属于net.minecraft.util.text包,在下文中一共展示了Style类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printMessageNaked
import net.minecraft.util.text.Style; //导入依赖的package包/类
public static void printMessageNaked(String startWith, String message, Style firstStyle, Style secondStyle) {
if(getLocalPlayer() != null && !Strings.isNullOrEmpty(message)) {
if(message.contains("\n")) {
Scanner scanner = new Scanner(message);
scanner.useDelimiter("\n");
Style s1 = firstStyle;
Style s2 = secondStyle;
while (scanner.hasNext()) {
printMessageNaked(startWith, scanner.next(), s1, s2);
// alternate between colors each newline
Style cpy = s1;
s1 = s2;
s2 = cpy;
}
} else {
TextComponentString string = new TextComponentString(startWith + message.replaceAll("\r", ""));
string.setStyle(firstStyle);
getLocalPlayer().sendMessage(string);
}
}
}
示例2: displayGui
import net.minecraft.util.text.Style; //导入依赖的package包/类
public void displayGui(IInteractionObject guiOwner)
{
if (guiOwner instanceof ILootContainer && ((ILootContainer)guiOwner).getLootTable() != null && this.isSpectator())
{
this.addChatMessage((new TextComponentTranslation("container.spectatorCantOpen", new Object[0])).setStyle((new Style()).setColor(TextFormatting.RED)));
}
else
{
this.getNextWindowId();
this.connection.sendPacket(new SPacketOpenWindow(this.currentWindowId, guiOwner.getGuiID(), guiOwner.getDisplayName()));
this.openContainer = guiOwner.createContainer(this.inventory, this);
this.openContainer.windowId = this.currentWindowId;
this.openContainer.addListener(this);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open(this, this.openContainer));
}
}
示例3: deleteDimension
import net.minecraft.util.text.Style; //导入依赖的package包/类
public void deleteDimension(ICommandSender sender, int dimensionID)
{
if (!dimensionInfo.containsKey(dimensionID))
{
sender.sendMessage(new TextComponentString("The dimension associated with that id is not from the SimpleDimensions mod").setStyle(new Style().setColor(TextFormatting.RED)));
return;
}
World worldObj = DimensionManager.getWorld(dimensionID);
if (worldObj.playerEntities.size() > 0)
{
sender.sendMessage(new TextComponentString("Can't delete a dimension with players inside it").setStyle(new Style().setColor(TextFormatting.RED)));
return;
}
Entity entitySender = sender.getCommandSenderEntity();
toBeDeleted.put(dimensionID, entitySender != null ? entitySender.getUniqueID() : null);
DimensionManager.unloadWorld(dimensionID);
}
示例4: getTextComponent
import net.minecraft.util.text.Style; //导入依赖的package包/类
public ITextComponent getTextComponent() {
String message = String.format(
"%s, Version %s - " + "Please note that this is an early Alpha version!"
+ " For sending suggestions and bug reports please visit ",
context.getName(), context.getVersion());
WolAnnouncementMessage result = new WolAnnouncementMessage(message);
result.appendSibling(newChatWithLinks(context.getUrl()));
String recommendedVersion = context.getRecommendedVersion();
if (recommendedVersion != null) {
TextComponentString component =
new TextComponentString("\n New version " + recommendedVersion + " available!");
component.setStyle((new Style()).setColor(TextFormatting.GREEN));
result.appendSibling(component);
}
return result;
}
示例5: format
import net.minecraft.util.text.Style; //导入依赖的package包/类
private ITextComponent format(Iterable<SpellEntity> spells) {
// TODO I18n
WolAnnouncementMessage result = new WolAnnouncementMessage("Active spells:\n");
for (SpellEntity spell : spells) {
TextComponentString name = new TextComponentString(spell.getSid() + ": ");
name.setStyle((new Style()).setColor(TextFormatting.DARK_GREEN));
String description = spell.getProgram().getCode();
if (description.length() > 40) {
description = description.substring(0, 40) + "...";
}
TextComponentString codeMsg = new TextComponentString(description + "\n");
codeMsg.setStyle((new Style()).setColor(TextFormatting.WHITE));
result.appendSibling(name);
result.appendSibling(codeMsg);
}
return result;
}
示例6: execute
import net.minecraft.util.text.Style; //导入依赖的package包/类
@Override
public void execute(MinecraftServer minecraftServer, ICommandSender sender, String[] args) throws CommandException {
GSLogger.logInfo("Player statue command received");
if (args.length >= 1) {
EnumMemorials memorialType = EnumMemorials.STONE_STEVE_STATUE;
if (StringUtils.isNotBlank(args[2])) {
try {
memorialType = EnumMemorials.getByTypeAndMaterial(EnumMemorialType.STEVE_STATUE, EnumGraveMaterial.valueOf(args[2].toUpperCase()));
} catch (Exception e) {
sender.sendMessage(new TextComponentTranslation("commands.unknown_material").setStyle(new Style().setColor(TextFormatting.RED)));
}
}
GameProfileHelper.dropItem(minecraftServer, sender, args[1], GSBlock.MEMORIAL, memorialType.ordinal());
} else {
sender.sendMessage(new TextComponentTranslation("commands.not_enough_parameters").setStyle(new Style().setColor(TextFormatting.RED)));
}
}
示例7: onBlockActivated
import net.minecraft.util.text.Style; //导入依赖的package包/类
@Override
public final boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (!worldIn.isRemote) {
if (playerIn.isSneaking() && CoreInit.isWrench(playerIn, hand)) {
worldIn.setBlockToAir(pos);
return true;
}
if (heldItem.getItem() instanceof ISwitch && ((ISwitch) heldItem.getItem()).isSwitch(heldItem, playerIn)) {
TileEntityMachineBase te = (TileEntityMachineBase) worldIn.getTileEntity(pos);
if (te.rs == ForceDeviceControlType.SWITCH) {
te.active = !te.active;
return true;
} else {
TomsModUtils.sendNoSpamTranslate(playerIn, new Style().setColor(TextFormatting.RED), "tomsMod.chat.mnotSwitchable", new TextComponentTranslation(heldItem.getUnlocalizedName() + ".name"));
}
}
}
return onBlockActivatedI(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);
}
示例8: teleportPlayer
import net.minecraft.util.text.Style; //导入依赖的package包/类
private void teleportPlayer(EntityPlayer playerIn, BlockPos pos, EnumFacing side, ItemStack stack) {
if (this.getEnergyStored(stack) >= TRANSPORTER_USAGE) {
BlockPos pos2 = pos.offset(side.getOpposite(), side == EnumFacing.UP ? 3 : 2);
IBlockState state = playerIn.world.getBlockState(pos2);
if (state == null || state.getBlock() == null || state.getBlock().isPassable(playerIn.world, pos2)) {
TomsModUtils.sendAccessGrantedMessageToWithExtraInformation(playerIn, stack.getUnlocalizedName() + ".name", "tomsMod.transmissionC");
EntityPlayerMP mp = (EntityPlayerMP) playerIn;
mp.connection.setPlayerLocation(pos2.getX() + 0.5, pos2.getY() + 0.5, pos2.getZ() + 0.5, playerIn.rotationYaw, playerIn.rotationPitch);
if (!playerIn.capabilities.isCreativeMode)
this.extractEnergy(stack, TRANSPORTER_USAGE, false);
} else {
TomsModUtils.sendNoSpamTranslateWithTag(playerIn, new Style().setColor(TextFormatting.RED), stack.getUnlocalizedName() + ".name", "tomsMod.detectedObstacle");
}
} else {
TomsModUtils.sendNoSpamTranslateWithTag(playerIn, new Style().setColor(TextFormatting.RED), stack.getUnlocalizedName() + ".name", "tomsMod.notEnoughPower");
}
}
示例9: onItemRightClick
import net.minecraft.util.text.Style; //导入依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
ItemStack itemStackIn = playerIn.getHeldItem(hand);
if (playerIn.isSneaking())
itemStackIn.setItemDamage(MultiToolType.get(itemStackIn.getItemDamage() + 1).ordinal());
else {
if (!worldIn.isRemote) {
if (MultiToolType.get(itemStackIn.getItemDamage()) == MultiToolType.ENCODER)
if (hand == EnumHand.MAIN_HAND)
playerIn.openGui(CoreInit.modInstance, GuiIDs.multitoolWriter.ordinal(), worldIn, 0, 0, 0);
else
TomsModUtils.sendNoSpamTranslateWithTag(playerIn, new Style().setColor(TextFormatting.RED), itemStackIn.getUnlocalizedName() + ".name", "tomsMod.invalidHandUseMain");
}
}
// playerIn.posX += 10;
// playerIn.posZ += 10;
return new ActionResult<>(EnumActionResult.PASS, itemStackIn);
}
示例10: onBlockActivated
import net.minecraft.util.text.Style; //导入依赖的package包/类
public void onBlockActivated(EntityPlayer player, ItemStack held) {
if (!world.isRemote) {
if (held != null && held.getItem() instanceof ISwitch && ((ISwitch) held.getItem()).isSwitch(held, player)) {
if (rsMode == ForceDeviceControlType.SWITCH) {
boolean canAccess = true;
BlockPos securityStationPos = this.getSecurityStationPos();
if (securityStationPos != null) {
TileEntity tileentity = world.getTileEntity(securityStationPos);
if (tileentity instanceof ISecurityStation) {
ISecurityStation tile = (ISecurityStation) tileentity;
canAccess = tile.canPlayerAccess(AccessType.SWITCH_DEVICES, player);
}
}
if (canAccess) {
this.active = !this.active;
} else {
TomsModUtils.sendAccessDeniedMessageTo(player, "tomsMod.chat.fieldSecurity");
}
} else {
TomsModUtils.sendNoSpamTranslate(player, new Style().setColor(TextFormatting.RED), "tomsMod.chat.mnotSwitchable", new TextComponentTranslation(held.getUnlocalizedName() + ".name"));
}
}
}
}
示例11: apply
import net.minecraft.util.text.Style; //导入依赖的package包/类
@Override
public Void apply(AutoCraftingHandler.CraftingCalculationResult input) {
if (input.e != null) {
String msg = input.e.getMessage();
currentReport = null;
calculated = true;
dataSent = false;
TomsModUtils.sendNoSpamTranslate(player, new Style().setColor(TextFormatting.RED), "tomsMod.chat.craftFail", new TextComponentTranslation(msg != null ? msg : "tomsMod.na"));
input.e.printStackTrace();
} else {
currentReport = input.c;
calculated = true;
dataSent = false;
}
return null;
}
示例12: execute
import net.minecraft.util.text.Style; //导入依赖的package包/类
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length == 0)
{
sender.addChatMessage(new TextComponentString("All online players:").setStyle(new Style().setColor(TextFormatting.GOLD)));
for (GameProfile gp : server.getPlayerList().getAllProfiles())
{
sender.addChatMessage(new TextComponentString(gp.getName() + " -> " + gp.getId()));
}
}
else
{
sender.addChatMessage(new TextComponentString("All listed players:").setStyle(new Style().setColor(TextFormatting.GOLD)));
for (String name : args)
{
EntityPlayerMP player = server.getPlayerList().getPlayerByUsername(name);
if (player == null) sender.addChatMessage(new TextComponentString("No player with name " + name).setStyle(new Style().setColor(TextFormatting.RED)));
else sender.addChatMessage(new TextComponentString(player.getDisplayNameString() + " -> " + player.getUniqueID()));
}
}
}
示例13: format
import net.minecraft.util.text.Style; //导入依赖的package包/类
@Override
public ITextBuilder format(TextFormatting f) {
checkCreated();
if (f.isColor()) {
current.getStyle().setColor(f);
} else if (f.isFancyStyling()) {
if (f == TextFormatting.BOLD) {
current.getStyle().setBold(true);
} else if (f == TextFormatting.ITALIC) {
current.getStyle().setItalic(true);
} else if (f == TextFormatting.UNDERLINE) {
current.getStyle().setUnderlined(true);
} else if (f == TextFormatting.STRIKETHROUGH) {
current.getStyle().setStrikethrough(true);
} else if (f == TextFormatting.OBFUSCATED) {
current.getStyle().setObfuscated(true);
}
} else if (f == TextFormatting.RESET) {
current.setStyle(new Style());
}
return this;
}
示例14: append
import net.minecraft.util.text.Style; //导入依赖的package包/类
/**
* Appends a string with the specified color(s) and an event
* triggered on text click and on text hover. Only one actual
* color should be specified, any other {@code TextFormatting}
* type should be styling. (Bold, Italic, Underline, Strikethrough,
* and Obfuscated)
*
* @param text The string being appended
* @param clickEvent Click event to be used
* @param hoverEvent Hover event to be used
* @param colors Color formatting
* @return This builder
*/
public final ChatBuilder append(String text, @Nullable ClickEvent clickEvent, @Nullable HoverEvent hoverEvent, TextFormatting... colors) {
TextComponentString component = new TextComponentString(text);
Style style = component.getStyle();
Arrays.stream(colors).forEach(color -> {
switch (color) {
case BOLD: {
style.setBold(true);
break;
}
case ITALIC: {
style.setItalic(true);
break;
}
case UNDERLINE: {
style.setUnderlined(true);
break;
}
case STRIKETHROUGH: {
style.setStrikethrough(true);
break;
}
case OBFUSCATED: {
style.setObfuscated(true);
break;
}
default: {
style.setColor(color);
break;
}
}
});
// noinspection ConstantConditions
style.setClickEvent(clickEvent).setHoverEvent(hoverEvent);
this.component.appendSibling(component);
return this;
}
示例15: handleOpenRequest
import net.minecraft.util.text.Style; //导入依赖的package包/类
@SideOnly(Side.SERVER)
public static void handleOpenRequest(BlockPos pos, EntityPlayerMP player) {
TileEntity te = player.world.getTileEntity(pos);
if (te instanceof ScriptyBlock.TEScriptyBlock) {
ScriptyBlock.TEScriptyBlock scriptyBlock = (ScriptyBlock.TEScriptyBlock) te;
if (scriptyBlock.getOwner() != null && scriptyBlock.getOwner().isEntityEqual(player)) {
player.sendMessage(new TextComponentString(scriptyBlock.getOwner().getName() + " is already using this Scripty block.").setStyle(new Style().setColor(TextFormatting.RED)));
return;
}
scriptyBlock.setOwner(player);
sendContentMessage(player, pos, scriptyBlock.getContent(), scriptyBlock.getLanguage(), scriptyBlock.isParsing());
}
}