下面列出了怎么用net.minecraft.util.Util的API类实例代码及写法,或者点击链接到github查看源代码。
private void addLinkButtons()
{
OperatingSystem os = Util.getOperatingSystem();
new WurstOptionsButton(54, 24, () -> "Official Website",
"WurstClient.net", b -> os.open("https://www.wurstclient.net/"));
new WurstOptionsButton(54, 48, () -> "Twitter", "@Wurst_Imperium",
b -> os.open("https://twitter.com/Wurst_Imperium"));
new WurstOptionsButton(54, 72, () -> "Subreddit (NEW!)",
"r/WurstClient",
b -> os.open("https://www.reddit.com/r/WurstClient/"));
new WurstOptionsButton(54, 96, () -> "Donate",
"paypal.me/WurstImperium",
b -> os.open("https://www.wurstclient.net/donate/"));
}
public BlockState getBlockState(Random random, BlockPos pos) {
double d = Biome.FOLIAGE_NOISE.sample((double) pos.getX() / 200.0D, (double) pos.getZ() / 200.0D, false);
if (d < -0.8D) {
return (BlockState) Util.getRandom((Object[]) mix1, random);
} else {
return random.nextInt(3) > 0 ? (BlockState) Util.getRandom((Object[]) mix2, random) : Blocks.DANDELION.getDefaultState();
}
}
@Override
public void init()
{
addButton(searchButton =
new ButtonWidget(width / 2 - 100, height / 4 + 96 + 12, 200, 20,
new LiteralText("Search"), b -> searchOrCancel()));
addButton(new ButtonWidget(width / 2 - 100, height / 4 + 120 + 12, 200,
20, new LiteralText("Tutorial"),
b -> Util.getOperatingSystem().open(
"https://www.wurstclient.net/wiki/Special_Features/Server_Finder/")));
addButton(new ButtonWidget(width / 2 - 100, height / 4 + 144 + 12, 200,
20, new LiteralText("Back"), b -> client.openScreen(prevScreen)));
ipBox = new TextFieldWidget(textRenderer, width / 2 - 100,
height / 4 + 34, 200, 20, new LiteralText(""));
ipBox.setMaxLength(200);
ipBox.setSelected(true);
children.add(ipBox);
maxThreadsBox = new TextFieldWidget(textRenderer, width / 2 - 32,
height / 4 + 58, 26, 12, new LiteralText(""));
maxThreadsBox.setMaxLength(3);
maxThreadsBox.setText("128");
children.add(maxThreadsBox);
setInitialFocus(ipBox);
state = ServerFinderState.NOT_RUNNING;
WurstClient.INSTANCE.getAnalytics()
.trackPageView("/multiplayer/server-finder", "Server Finder");
}
@Inject(method = "render", at = @At("RETURN"))
private void render(int int_1, int int_2, float float_1, CallbackInfo info) {
if (!OptifabricError.hasError()) {
float fadeTime = this.doBackgroundFade ? (float) (Util.getMeasuringTimeMs() - this.backgroundFadeStart) / 1000.0F : 1.0F;
float fadeColor = this.doBackgroundFade ? MathHelper.clamp(fadeTime - 1.0F, 0.0F, 1.0F) : 1.0F;
int int_6 = MathHelper.ceil(fadeColor * 255.0F) << 24;
if ((int_6 & -67108864) != 0) {
this.drawString(this.font, OptifineVersion.version, 2, this.height - 20, 16777215 | int_6);
}
}
}
public static void checkForErrors() {
if (OptifabricError.hasError()) {
ConfirmScreen confirmScreen = new ConfirmScreen(t -> {
if (t) {
Util.getOperatingSystem().open(OptifabricError.getErrorURL());
} else {
MinecraftClient.getInstance().scheduleStop();
}
}, new LiteralText(Formatting.RED + "There was an error loading OptiFabric!"), new LiteralText(OptifabricError.getError()), Formatting.GREEN + OptifabricError.getHelpButtonText(), Formatting.RED + "Close Game");
MinecraftClient.getInstance().openScreen(confirmScreen);
}
}
public boolean onClick(double double_1, double double_2) {
if (!ChatUtil.isEmpty(this.helpUrl) && double_1 >= (double) this.startX && double_1 <= (double) this.endX && double_2 >= (double) this.startY && double_2 <= (double) this.endY) {
SandboxTitleScreen.this.minecraft.openScreen(new ConfirmChatLinkScreen((boolean_1) -> {
if (boolean_1) {
Util.getOperatingSystem().open(this.helpUrl);
}
SandboxTitleScreen.this.minecraft.openScreen(SandboxTitleScreen.this);
}, this.helpUrl, true));
return true;
} else {
return false;
}
}
@Environment(EnvType.CLIENT)
private void sendMessageClient(String s) {
ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
if (handler != null) {
try {
handler.onGameMessage(new GameMessageS2CPacket(
Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(s)), MessageType.SYSTEM, Util.NIL_UUID
));
} catch (OffThreadException ignored) {
}
}
}
public void onEnable() {
try {
Util.getOSType().openURI("https://github.com/BleachDrinker420/bleachhack-1.14");
} catch (Exception e) {e.printStackTrace();}
this.setToggled(false);
}
public void onEnable() {
try {
Util.getOperatingSystem().open("https://github.com/BleachDrinker420/bleachhack-1.14");
} catch (Exception e) {e.printStackTrace();}
this.setToggled(false);
}
public void onEnable() {
try {
Util.getOperatingSystem().open("https://github.com/BleachDrinker420/bleachhack-1.14");
} catch (Exception e) {e.printStackTrace();}
this.setToggled(false);
}
@Inject(method = "setWindowIcon", at = @At("HEAD"), cancellable = true)
private void setWindowIcon(CallbackInfo callbackInfo) {
if(Util.getOSType() != Util.EnumOS.OSX) {
final ByteBuffer[] liquidBounceFavicon = IconUtils.getFavicon();
if(liquidBounceFavicon != null) {
Display.setIcon(liquidBounceFavicon);
callbackInfo.cancel();
}
}
}
@Inject(method = "setWindowIcon", at = @At("HEAD"), cancellable = true)
private void setWindowIcon(CallbackInfo callbackInfo) {
if(Util.getOSType() != Util.EnumOS.OSX) {
final ByteBuffer[] liquidBounceFavicon = IconUtils.getFavicon();
if(liquidBounceFavicon != null) {
Display.setIcon(liquidBounceFavicon);
callbackInfo.cancel();
}
}
}
@Override
public void forceTick(BooleanSupplier isAhead)
{
timeReference = field_4557 = Util.getMeasuringTimeMs();
tick(isAhead);
while(runTask()) {Thread.yield();}
}
public void setWindowIcon() {
if (Util.getOSType() != Util.EnumOS.OSX) {
try (InputStream inputStream16x = Minecraft.class.getResourceAsStream("/assets/hyperium/icons/icon-16x.png");
InputStream inputStream32x = Minecraft.class.getResourceAsStream("/assets/hyperium/icons/icon-32x.png")) {
ByteBuffer[] icons = new ByteBuffer[]{Utils.INSTANCE.readImageToBuffer(inputStream16x), Utils.INSTANCE.readImageToBuffer(inputStream32x)};
Display.setIcon(icons);
} catch (Exception e) {
Hyperium.LOGGER.error("Couldn't set Windows Icon", e);
}
}
}
public static void handleScrapingMessage(ScrapingMessage message)
{
Minecraft.getInstance().execute(() -> {
Minecraft.getInstance().player.sendMessage(
new TranslationTextComponent("text." + SurvivalistMod.MODID + ".scraping.message1",
makeClickable(message.stack.getTextComponent()),
new StringTextComponent("" + message.ret.getCount()),
makeClickable(message.ret.getTextComponent())), Util.field_240973_b_);
});
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (!isMouseOver(mouseX, mouseY)) return false;
this.setSelectedEntry.accept(this);
if (Util.milliTime() - this.lastClickTime < 250L) {
done();
} else {
this.lastClickTime = Util.milliTime();
}
return true;
}
private static <T> T cycle(Iterable<T> iterable_1, T object_1, boolean sneaking) {
return sneaking ? Util.previous(iterable_1, object_1) : Util.next(iterable_1, object_1);
}
private void openFolder()
{
Util.getOperatingSystem().open(
WurstClient.INSTANCE.getKeybinds().getProfilesFolder().toFile());
}
@Override
public void doPrimaryAction()
{
String link = new Version(WurstClient.VERSION).getChangelogLink();
Util.getOperatingSystem().open(link);
}
private void openFolder()
{
Util.getOperatingSystem().open(setting.getFolder().toFile());
}
@Inject(at = {@At("HEAD")},
method = {
"loadSkin(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/texture/PlayerSkinProvider$SkinTextureAvailableCallback;Z)V"},
cancellable = true)
private void onLoadSkin(GameProfile profile,
PlayerSkinProvider.SkinTextureAvailableCallback callback,
boolean requireSecure, CallbackInfo ci)
{
// Can't @Inject nicely because everything is wrapped in a lambda.
// Had to replace the whole method.
Runnable runnable = () -> {
HashMap<MinecraftProfileTexture.Type, MinecraftProfileTexture> map =
Maps.newHashMap();
try
{
map.putAll(sessionService.getTextures(profile, requireSecure));
}catch(InsecureTextureException var7)
{
}
if(map.isEmpty())
{
profile.getProperties().clear();
if(profile.getId().equals(MinecraftClient.getInstance()
.getSession().getProfile().getId()))
{
profile.getProperties().putAll(
MinecraftClient.getInstance().getSessionProperties());
map.putAll(sessionService.getTextures(profile, false));
}else
{
sessionService.fillProfileProperties(profile,
requireSecure);
try
{
map.putAll(
sessionService.getTextures(profile, requireSecure));
}catch(InsecureTextureException var6)
{
}
}
}
addWurstCape(profile, map);
MinecraftClient.getInstance().execute(() -> {
RenderSystem.recordRenderCall(() -> {
ImmutableList.of(Type.SKIN, Type.CAPE).forEach((type) -> {
if(map.containsKey(type))
loadSkin(map.get(type), type, callback);
});
});
});
};
Util.getServerWorkerExecutor().execute(runnable);
ci.cancel();
}
private void openSkinFolder()
{
createSkinFolder();
Util.getOperatingSystem().open(skinFolder.toFile());
}
public void render(int int_1, int int_2, float float_1) {
if (this.backgroundFadeStart == 0L && this.doBackgroundFade) {
this.backgroundFadeStart = Util.getMeasuringTimeMs();
}
float float_2 = this.doBackgroundFade ? (float) (Util.getMeasuringTimeMs() - this.backgroundFadeStart) / 1000.0F : 1.0F;
fill(0, 0, this.width, this.height, -1);
this.backgroundRenderer.render(float_1, MathHelper.clamp(float_2, 0.0F, 1.0F));
int int_4 = this.width / 2 - 137;
this.minecraft.getTextureManager().bindTexture(PANORAMA_OVERLAY);
GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA.value, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA.value);
GlStateManager.color4f(1.0F, 1.0F, 1.0F, this.doBackgroundFade ? (float) MathHelper.ceil(MathHelper.clamp(float_2, 0.0F, 1.0F)) : 1.0F);
blit(0, 0, this.width, this.height, 0.0F, 0.0F, 16, 128, 16, 128);
float float_3 = this.doBackgroundFade ? MathHelper.clamp(float_2 - 1.0F, 0.0F, 1.0F) : 1.0F;
int int_6 = MathHelper.ceil(float_3 * 255.0F) << 24;
if ((int_6 & -67108864) != 0) {
this.minecraft.getTextureManager().bindTexture(MINECRAFT_TITLE_TEXTURE);
GlStateManager.color4f(1.0F, 1.0F, 1.0F, float_3);
if (this.field_17776) {
this.blit(int_4 + 0, 30, 0, 0, 99, 44);
this.blit(int_4 + 99, 30, 129, 0, 27, 44);
this.blit(int_4 + 99 + 26, 30, 126, 0, 3, 44);
this.blit(int_4 + 99 + 26 + 3, 30, 99, 0, 26, 44);
this.blit(int_4 + 155, 30, 0, 45, 155, 44);
} else {
this.blit(int_4 + 0, 30, 0, 0, 155, 44);
this.blit(int_4 + 155, 30, 0, 45, 155, 44);
}
this.minecraft.getTextureManager().bindTexture(EDITION_TITLE_TEXTURE);
blit(int_4 + 88, 67, 0.0F, 0.0F, 98, 14, 128, 16);
if (this.splashText != null) {
GlStateManager.pushMatrix();
GlStateManager.translatef((float) (this.width / 2 + 90), 70.0F, 0.0F);
GlStateManager.rotatef(-20.0F, 0.0F, 0.0F, 1.0F);
float float_4 = 1.8F - MathHelper.abs(MathHelper.sin((float) (Util.getMeasuringTimeMs() % 1000L) / 1000.0F * 6.2831855F) * 0.1F);
float_4 = float_4 * 100.0F / (float) (this.font.getStringWidth(this.splashText) + 32);
GlStateManager.scalef(float_4, float_4, float_4);
this.drawCenteredString(this.font, this.splashText, 0, -8, 16776960 | int_6);
GlStateManager.popMatrix();
}
String string_1 = "Minecraft " + SharedConstants.getGameVersion().getName();
if (this.minecraft.isDemo()) {
string_1 = string_1 + " Demo";
} else {
string_1 = string_1 + ("release".equalsIgnoreCase(this.minecraft.getVersionType()) ? "" : "/" + this.minecraft.getVersionType());
}
this.drawString(this.font, string_1, 2, this.height - 10, 16777215 | int_6);
this.drawString(this.font, "Copyright Mojang AB. Do not distribute!", this.copyrightTextX, this.height - 10, 16777215 | int_6);
if (int_1 > this.copyrightTextX && int_1 < this.copyrightTextX + this.copyrightTextWidth && int_2 > this.height - 10 && int_2 < this.height) {
fill(this.copyrightTextX, this.height - 1, this.copyrightTextX + this.copyrightTextWidth, this.height, 16777215 | int_6);
}
if (this.warning != null) {
this.warning.render(int_6);
}
Iterator var11 = this.buttons.iterator();
while (var11.hasNext()) {
AbstractButtonWidget abstractButtonWidget_1 = (AbstractButtonWidget) var11.next();
abstractButtonWidget_1.setAlpha(float_3);
}
super.render(int_1, int_2, float_1);
}
}
public boolean mouseClicked(double double_1, double double_2, int int_1) {
if (!windows.get(0).closed) {
int x = windows.get(0).x1,
y = windows.get(0).y1 + 10,
w = width / 2,
h = height / 2;
if (double_1 > x + 20 && double_1 < x + 35 && double_2 > y + 5 && double_2 < y + 15) if (page > 0) page--;
if (double_1 > x + 77 && double_1 < x + 92 && double_2 > y + 5 && double_2 < y + 15) page++;
if (double_1 > x + w - 44 && double_1 < x + w && double_2 > y + 3 && double_2 < y + 15) {
try { Util.getOperatingSystem().open(new URI("https://www.youtube.com/watch?v=clT_aNvQedk")); } catch (Exception e) {}
}
if (double_1 > x + 10 && double_1 < x + 99 && double_2 > y + h - 13 && double_2 < y + h - 3) {
NotebotUtils.downloadSongs(true);
}
if (entry != null) {
/* Pfft why use buttons when you can use meaningless rectangles with messy code */
if (double_1 > x + w - w / 2 + 10 && double_1 < x + w - w / 4 && double_2 > y + h - 15 && double_2 < y + h - 5) {
BleachFileMang.deleteFile("notebot", entry.fileName);
client.openScreen(this);
}
if (double_1 > x + w - w / 4 + 5 && double_1 < x + w - 5 && double_2 > y + h - 15 && double_2 < y + h - 5) {
Notebot.filePath = entry.fileName;
}
if (double_1 > x + w - w / 4 - w / 8 && double_1 < x + w - w / 4 + w / 8 && double_2 > y + h - 27 && double_2 < y + h - 17) {
entry.playing = !entry.playing;
}
}
int pageEntries = 0;
for (int i = y + 20; i < y + h - 27; i += 10) pageEntries++;
int c = 0;
int c1 = -1;
for (String s: files) {
c1++;
if (c1 < page * pageEntries) continue;
if (double_1 > x + 5 && double_1 < x + 105 && double_2 > y + 15 + c * 10 && double_2 < y + 25 + c * 10) {
entry = new NotebotEntry(s);
selected = s;
}
c++;
}
}
return super.mouseClicked(double_1, double_2, int_1);
}
public boolean mouseClicked(double double_1, double double_2, int int_1) {
if (!windows.get(0).closed) {
int x = windows.get(0).x1,
y = windows.get(0).y1 + 10,
w = width / 2,
h = height / 2;
if (double_1 > x + 20 && double_1 < x + 35 && double_2 > y + 5 && double_2 < y + 15) if (page > 0) page--;
if (double_1 > x + 77 && double_1 < x + 92 && double_2 > y + 5 && double_2 < y + 15) page++;
if (double_1 > x + w - 44 && double_1 < x + w && double_2 > y + 3 && double_2 < y + 15) {
try { Util.getOperatingSystem().open(new URI("https://www.youtube.com/watch?v=clT_aNvQedk")); } catch (Exception e) {}
}
if (double_1 > x + 10 && double_1 < x + 99 && double_2 > y + h - 13 && double_2 < y + h - 3) {
NotebotUtils.downloadSongs(true);
}
if (entry != null) {
/* Pfft why use buttons when you can use meaningless rectangles with messy code */
if (double_1 > x + w - w / 2 + 10 && double_1 < x + w - w / 4 && double_2 > y + h - 15 && double_2 < y + h - 5) {
BleachFileMang.deleteFile("notebot", entry.fileName);
minecraft.openScreen(this);
}
if (double_1 > x + w - w / 4 + 5 && double_1 < x + w - 5 && double_2 > y + h - 15 && double_2 < y + h - 5) {
Notebot.filePath = entry.fileName;
}
if (double_1 > x + w - w / 4 - w / 8 && double_1 < x + w - w / 4 + w / 8 && double_2 > y + h - 27 && double_2 < y + h - 17) {
entry.playing = !entry.playing;
}
}
int pageEntries = 0;
for (int i = y + 20; i < y + h - 27; i += 10) pageEntries++;
int c = 0;
int c1 = -1;
for (String s: files) {
c1++;
if (c1 < page * pageEntries) continue;
if (double_1 > x + 5 && double_1 < x + 105 && double_2 > y + 15 + c * 10 && double_2 < y + 25 + c * 10) {
entry = new NotebotEntry(s);
selected = s;
}
c++;
}
}
return super.mouseClicked(double_1, double_2, int_1);
}
@Inject(method = "run", at = @At(value = "INVOKE", shift = At.Shift.AFTER,
target = "Lnet/minecraft/server/MinecraftServer;setFavicon(Lnet/minecraft/server/ServerMetadata;)V"))
private void modifiedRunLoop(CallbackInfo ci)
{
while (this.running)
{
//long long_1 = Util.getMeasuringTimeMs() - this.timeReference;
//CM deciding on tick speed
if (CarpetProfiler.tick_health_requested != 0L)
{
CarpetProfiler.start_tick_profiling();
}
long msThisTick = 0L;
long long_1 = 0L;
if (TickSpeed.time_warp_start_time != 0 && TickSpeed.continueWarp())
{
//making sure server won't flop after the warp or if the warp is interrupted
this.timeReference = this.field_4557 = Util.getMeasuringTimeMs();
carpetMsptAccum = TickSpeed.mspt;
}
else
{
if (Math.abs(carpetMsptAccum - TickSpeed.mspt) > 1.0f)
{
// Tickrate changed. Ensure that we use the correct value.
carpetMsptAccum = TickSpeed.mspt;
}
msThisTick = (long)carpetMsptAccum; // regular tick
carpetMsptAccum += TickSpeed.mspt - msThisTick;
long_1 = Util.getMeasuringTimeMs() - this.timeReference;
}
//end tick deciding
//smoothed out delay to include mcpt component. With 50L gives defaults.
if (long_1 > /*2000L*/1000L+20*TickSpeed.mspt && this.timeReference - this.field_4557 >= /*15000L*/10000L+100*TickSpeed.mspt)
{
long long_2 = (long)(long_1 / TickSpeed.mspt);//50L;
LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", long_1, long_2);
this.timeReference += (long)(long_2 * TickSpeed.mspt);//50L;
this.field_4557 = this.timeReference;
}
this.timeReference += msThisTick;//50L;
if (this.profilerStartQueued)
{
this.profilerStartQueued = false;
this.profiler.getController().enable();
}
this.profiler.startTick();
this.profiler.push("tick");
this.tick(TickSpeed.time_warp_start_time != 0 ? ()->true : this::shouldKeepTicking);
this.profiler.swap("nextTickWait");
if (TickSpeed.time_warp_start_time != 0) // clearing all hanging tasks no matter what when warping
{
while(this.runEveryTask()) {Thread.yield();}
}
this.field_19249 = true;
this.field_19248 = Math.max(Util.getMeasuringTimeMs() + /*50L*/ msThisTick, this.timeReference);
// run all tasks (this will not do a lot when warping), but that's fine since we already run them
this.method_16208();
this.profiler.pop();
this.profiler.endTick();
this.loading = true;
}
}
public WrapperUtil(Util var1) {
this.real = var1;
}
public Util unwrap() {
return this.real;
}