本文整理汇总了Java中net.minecraft.util.text.event.ClickEvent.getAction方法的典型用法代码示例。如果您正苦于以下问题:Java ClickEvent.getAction方法的具体用法?Java ClickEvent.getAction怎么用?Java ClickEvent.getAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.util.text.event.ClickEvent
的用法示例。
在下文中一共展示了ClickEvent.getAction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseClicked
import net.minecraft.util.text.event.ClickEvent; //导入方法依赖的package包/类
@Override
public boolean mouseClicked(int mouseX, int mouseY, int y, int virtualWidth) {
ITextComponent hoveredComponent = getHoveredComponent(virtualWidth, y, mouseX, mouseY);
if (hoveredComponent != null) {
ClickEvent clickEvent = hoveredComponent.getStyle().getClickEvent();
if (clickEvent != null && clickEvent.getAction() == ClickEvent.Action.CHANGE_PAGE) {
String value = clickEvent.getValue();
String name = null;
if (value.contains("=")) {
int equalsIndex = value.indexOf('=');
name = value.substring(0, equalsIndex);
value = value.substring(equalsIndex + 1);
}
CommandHelpManager.getInstance().displayHelpScreen(name, value);
return true;
} else {
return GeneralUtils.handleClickEvent(clickEvent);
}
} else
return false;
}
示例2: mouseClicked
import net.minecraft.util.text.event.ClickEvent; //导入方法依赖的package包/类
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
int info2Start = (this.height / 2) - 50;
if (orderPressed && !isSure && mouseY >= info2Start && mouseY <= info2Start + fontRendererObj.FONT_HEIGHT)
{
ITextComponent comp = getComponent(mouseX, mouseY);
ClickEvent clickevent = comp.getStyle().getClickEvent();
if (clickevent != null && clickevent.getAction() == ClickEvent.Action.OPEN_URL)
{
try
{
URI uri = new URI(clickevent.getValue());
Class<?> oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop").invoke(null);
oclass.getMethod("browse", URI.class).invoke(object, uri);
}
catch (Throwable t)
{
CreeperHost.logger.error("Can\'t open url for " + clickevent, t);
}
return;
}
}
for (TextFieldDetails field : this.fields)
{
field.myMouseClicked(mouseX, mouseY, mouseButton);
}
}
示例3: handleComponentClick
import net.minecraft.util.text.event.ClickEvent; //导入方法依赖的package包/类
/**
* Executes the click event specified by the given chat component
*/
protected boolean handleComponentClick(ITextComponent component) {
ClickEvent clickevent = component.getStyle().getClickEvent();
if (clickevent == null) {
return false;
} else if (clickevent.getAction() == ClickEvent.Action.CHANGE_PAGE) {
String s = clickevent.getValue();
try {
int i = Integer.parseInt(s) - 1;
if (i >= 0 && i < this.bookTotalPages && i != this.currPage) {
this.currPage = i;
this.updateButtons();
return true;
}
} catch (Throwable var5) {
;
}
return false;
} else {
boolean flag = super.handleComponentClick(component);
if (flag && clickevent.getAction() == ClickEvent.Action.RUN_COMMAND) {
this.mc.displayGuiScreen((GuiScreen)null);
}
return flag;
}
}
示例4: handleComponentClick
import net.minecraft.util.text.event.ClickEvent; //导入方法依赖的package包/类
/**
* Executes the click event specified by the given chat component
*/
protected boolean handleComponentClick(ITextComponent component)
{
ClickEvent clickevent = component.getStyle().getClickEvent();
if (clickevent == null)
{
return false;
}
else if (clickevent.getAction() == ClickEvent.Action.CHANGE_PAGE)
{
String s = clickevent.getValue();
try
{
int i = Integer.parseInt(s) - 1;
if (i >= 0 && i < this.bookTotalPages && i != this.currPage)
{
this.currPage = i;
this.updateButtons();
return true;
}
}
catch (Throwable var5)
{
;
}
return false;
}
else
{
boolean flag = super.handleComponentClick(component);
if (flag && clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
{
this.mc.displayGuiScreen((GuiScreen)null);
}
return flag;
}
}
示例5: executeCommand
import net.minecraft.util.text.event.ClickEvent; //导入方法依赖的package包/类
public boolean executeCommand(final EntityPlayer playerIn)
{
ICommandSender icommandsender = new ICommandSender()
{
public String getName()
{
return playerIn.getName();
}
public ITextComponent getDisplayName()
{
return playerIn.getDisplayName();
}
public void addChatMessage(ITextComponent component)
{
}
public boolean canCommandSenderUseCommand(int permLevel, String commandName)
{
return permLevel <= 2;
}
public BlockPos getPosition()
{
return TileEntitySign.this.pos;
}
public Vec3d getPositionVector()
{
return new Vec3d((double)TileEntitySign.this.pos.getX() + 0.5D, (double)TileEntitySign.this.pos.getY() + 0.5D, (double)TileEntitySign.this.pos.getZ() + 0.5D);
}
public World getEntityWorld()
{
return playerIn.getEntityWorld();
}
public Entity getCommandSenderEntity()
{
return playerIn;
}
public boolean sendCommandFeedback()
{
return false;
}
public void setCommandStat(CommandResultStats.Type type, int amount)
{
if (TileEntitySign.this.world != null && !TileEntitySign.this.world.isRemote)
{
TileEntitySign.this.stats.setCommandStatForSender(TileEntitySign.this.world.getMinecraftServer(), this, type, amount);
}
}
public MinecraftServer getServer()
{
return playerIn.getServer();
}
};
for (ITextComponent itextcomponent : this.signText)
{
Style style = itextcomponent == null ? null : itextcomponent.getStyle();
if (style != null && style.getClickEvent() != null)
{
ClickEvent clickevent = style.getClickEvent();
if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
{
playerIn.getServer().getCommandManager().executeCommand(icommandsender, clickevent.getValue());
}
}
}
return true;
}
示例6: handleClickEvent
import net.minecraft.util.text.event.ClickEvent; //导入方法依赖的package包/类
/**
* A static alternative to
* {@link GuiScreen#handleComponentClick(IChatComponent)}, with the
* additional functionality that click events from elsewhere can be handled
*
* @param event
* @return
*/
public static boolean handleClickEvent(ClickEvent event) {
if (event != null) {
if (event.getAction() == ClickEvent.Action.OPEN_URL) {
if (!Minecraft.getMinecraft().gameSettings.chatLinks) {
return false;
}
try {
final URI webUri = new URI(event.getValue());
String protocol = webUri.getScheme();
if (protocol == null) {
throw new URISyntaxException(event.getValue(), "Missing protocol");
}
if (!PROTOCOLS.contains(protocol.toLowerCase())) {
throw new URISyntaxException(event.getValue(),
"Unsupported protocol: " + protocol.toLowerCase());
}
if (Minecraft.getMinecraft().gameSettings.chatLinksPrompt) {
final GuiScreen prevScreen = Minecraft.getMinecraft().currentScreen;
GuiYesNoCallback callback = new GuiYesNoCallback() {
@Override
public void confirmClicked(boolean result, int id) {
if (id == 31102009) {
if (result) {
openWebLink(webUri);
}
Minecraft.getMinecraft().displayGuiScreen(prevScreen);
}
}
};
Minecraft.getMinecraft()
.displayGuiScreen(new GuiConfirmOpenLink(callback, event.getValue(), 31102009, false));
} else {
openWebLink(webUri);
}
} catch (URISyntaxException e) {
MC_LOGGER.error("Can't open url for " + event, e);
}
} else if (event.getAction() == ClickEvent.Action.OPEN_FILE) {
URI fileUri = new File(event.getValue()).toURI();
openWebLink(fileUri);
} else if (event.getAction() == ClickEvent.Action.SUGGEST_COMMAND) {
// Can't do insertion
} else if (event.getAction() == ClickEvent.Action.RUN_COMMAND) {
if (Minecraft.getMinecraft().player != null)
Minecraft.getMinecraft().player.sendChatMessage(event.getValue());
} else {
MC_LOGGER.error("Don't know how to handle " + event);
}
return true;
}
return false;
}