下面列出了net.minecraft.util.Rarity#net.fabricmc.api.EnvType 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static byte[] lwTransformerHook(String name, String transformedName, byte[] bytes) {
boolean isDevelopment = FabricLauncherBase.getLauncher().isDevelopment();
EnvType envType = FabricLauncherBase.getLauncher().getEnvironmentType();
byte[] input = MinecraftGameProvider.TRANSFORMER.transform(name);
if (input != null) {
return FabricTransformer.transform(isDevelopment, envType, name, input);
} else {
if (bytes != null) {
return FabricTransformer.transform(isDevelopment, envType, name, bytes);
} else {
return null;
}
}
}
@Environment(EnvType.CLIENT)
@Override
public void paintFrame(int x, int y, Identifier texture) {
// Y Direction (down)
for (int tileYOffset = 0; tileYOffset < height; tileYOffset += tileHeight) {
// X Direction (right)
for (int tileXOffset = 0; tileXOffset < width; tileXOffset += tileWidth) {
// draw the texture
ScreenDrawing.texturedRect(
// at the correct position using tileXOffset and tileYOffset
x + tileXOffset, y + tileYOffset,
// but using the set tileWidth and tileHeight instead of the full height and
// width
tileWidth, tileHeight,
// render the current texture
texture,
// clips the texture if wanted
u1, v1, u2, v2, tint);
}
}
}
@Override
public void launch(ClassLoader loader) {
String targetClass = entrypoint;
if (envType == EnvType.CLIENT && targetClass.contains("Applet")) {
targetClass = "net.fabricmc.loader.entrypoint.applet.AppletMain";
}
try {
Class<?> c = loader.loadClass(targetClass);
Method m = c.getMethod("main", String[].class);
m.invoke(null, (Object) arguments.toArray());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random rand) {
double x = pos.getX();
double y = pos.getY();
double z = pos.getZ();
if (state.get(DRAG)) {
world.addImportantParticle(ParticleTypes.CURRENT_DOWN, x + 0.5D, y + 0.8D, z, 0.0D, 0.0D, 0.0D);
if (rand.nextInt(200) == 0) {
world.playSound(x, y, z, SoundEvents.BLOCK_BUBBLE_COLUMN_WHIRLPOOL_AMBIENT, SoundCategory.BLOCKS, 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false);
}
} else {
world.addImportantParticle(ParticleTypes.BUBBLE_COLUMN_UP, x + 0.5D, y, z + 0.5D, 0.0D, 0.04D, 0.0D);
world.addImportantParticle(ParticleTypes.BUBBLE_COLUMN_UP, x + (double) rand.nextFloat(), y + (double) rand.nextFloat(), z + (double) rand.nextFloat(), 0.0D, 0.04D, 0.0D);
if (rand.nextInt(200) == 0) {
world.playSound(x, y, z, SoundEvents.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT, SoundCategory.BLOCKS, 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false);
}
}
}
/**
* From an X offset past the left edge of a TextRenderer.draw, finds out what the closest caret
* position (division between letters) is.
* @param s
* @param x
* @return
*/
@Environment(EnvType.CLIENT)
public static int getCaretPos(String s, int x) {
if (x<=0) return 0;
TextRenderer font = MinecraftClient.getInstance().textRenderer;
int lastAdvance = 0;
for(int i=0; i<s.length()-1; i++) {
int advance = font.getWidth(s.substring(0,i+1));
int charAdvance = advance-lastAdvance;
if (x<advance + (charAdvance/2)) return i+1;
lastAdvance = advance;
}
return s.length();
}
@Environment(EnvType.CLIENT)
@Override
public WWidget onMouseUp(int x, int y, int button) {
if (children.isEmpty()) return super.onMouseUp(x, y, button);
for(int i=children.size()-1; i>=0; i--) { //Backwards so topmost widgets get priority
WWidget child = children.get(i);
if ( x>=child.getX() &&
y>=child.getY() &&
x<child.getX()+child.getWidth() &&
y<child.getY()+child.getHeight()) {
return child.onMouseUp(x-child.getX(), y-child.getY(), button);
}
}
return super.onMouseUp(x, y, button);
}
/**
* Sets the background painter of this inventory widget's slots.
*
* @param painter the new painter
* @return this panel
*/
@Environment(EnvType.CLIENT)
@Override
public WPanel setBackgroundPainter(BackgroundPainter painter) {
super.setBackgroundPainter(null);
inv.setBackgroundPainter(painter);
hotbar.setBackgroundPainter(painter);
return this;
}
@Override
public boolean loadsInEnvironment(EnvType type) {
switch (side) {
case UNIVERSAL:
return true;
case CLIENT:
return type == EnvType.CLIENT;
case SERVER:
return type == EnvType.SERVER;
default:
return false;
}
}
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(BlockState blockState, World world, BlockPos blockPos, Random random) {
if (blockState.get(AGE) == 3) {
double x = blockPos.getX() + 0.5D + (random.nextFloat() - random.nextFloat());
double y = blockPos.getY() + random.nextFloat();
double z = blockPos.getZ() + 0.5D + (random.nextFloat() - random.nextFloat());
int times = random.nextInt(4);
for (int i = 0; i < times; i++) {
world.addParticle(new DustParticleEffect(0.5f, 0.5f, 1.0f, 0.6f), x, y, z, 0.0D, 0.0D, 0.0D);
}
}
}
@Environment(EnvType.CLIENT)
@Override
public void tick() {
if (draggingFinishedFromScrollingTimer > 0) {
draggingFinishedFromScrollingTimer--;
}
if (pendingDraggingFinishedFromScrolling && draggingFinishedFromScrollingTimer <= 0) {
if (draggingFinishedListener != null) draggingFinishedListener.accept(value);
pendingDraggingFinishedFromScrolling = false;
draggingFinishedFromScrollingTimer = DRAGGING_FINISHED_RATE_LIMIT_FOR_SCROLLING;
}
}
@Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
super.onClick(x, y, button);
MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
this.isOn = !this.isOn;
onToggle(this.isOn);
}
@Override
@Environment(EnvType.CLIENT)
public final void buildTooltip(ItemStack itemStack_1, BlockView blockView_1, List<Text> list_1, TooltipContext tooltipContext_1) {
if (Screen.hasShiftDown()) {
list_1.add(new TranslatableText("tooltip.galacticraft-rewoven.compressor").setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
} else {
list_1.add(new TranslatableText("tooltip.galacticraft-rewoven.press_shift").setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
}
}
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(World world, BlockPos blockPos, FluidState fluidState, Random random) {
if (random.nextInt(10) == 0) {
world.addParticle(GalacticraftParticles.DRIPPING_CRUDE_OIL_PARTICLE,
(double) blockPos.getX() + 0.5D - random.nextGaussian() + random.nextGaussian(),
(double) blockPos.getY() + 1.1F,
(double) blockPos.getZ() + 0.5D - random.nextGaussian() + random.nextGaussian(),
0.0D, 0.0D, 0.0D);
}
}
/**
* Called when the 'Customize' button is pressed on world creation GUI.
*/
@Environment(EnvType.CLIENT)
default void onCustomizeButton(MinecraftClient client, CreateWorldScreen screen) {
if (this == LevelGeneratorType.FLAT) {
client.openScreen(new CustomizeFlatLevelScreen(screen, screen.generatorOptionsTag));
} else if (this == LevelGeneratorType.BUFFET) {
client.openScreen(new CustomizeBuffetLevelScreen(screen, screen.generatorOptionsTag));
}
}
@Environment(EnvType.CLIENT)
@Override
public void onMouseScroll(int x, int y, double amount) {
if (direction == Direction.LEFT || direction == Direction.DOWN) {
amount = -amount;
}
int previous = value;
value = MathHelper.clamp(value + (int) Math.signum(amount) * MathHelper.ceil(valueToCoordRatio * Math.abs(amount) * 2), min, max);
if (previous != value) {
onValueChanged(value);
pendingDraggingFinishedFromScrolling = true;
}
}
@Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
if (button != 0) return; // only left clicks
Style hoveredTextStyle = getTextStyleAt(x, y);
if (hoveredTextStyle != null) {
MinecraftClient.getInstance().currentScreen.handleTextClick(hoveredTextStyle);
}
}
@Override
@Environment(EnvType.CLIENT)
public void appendTooltip(ItemStack itemStack_1, World world_1, List<Text> list_1, TooltipContext tooltipContext_1) {
if (Screen.hasShiftDown()) {
list_1.add(new TranslatableText("tooltip.galacticraft-rewoven.standard_wrench").setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
} else {
list_1.add(new TranslatableText("tooltip.galacticraft-rewoven.press_shift").setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
}
}
@Environment(EnvType.CLIENT)
@Override
public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) {
if (wrappedLines == null || wrappingScheduled) {
wrapLines();
wrappingScheduled = false;
}
TextRenderer font = MinecraftClient.getInstance().textRenderer;
int yOffset;
switch (verticalAlignment) {
case CENTER:
yOffset = height / 2 - font.fontHeight * wrappedLines.size() / 2;
break;
case BOTTOM:
yOffset = height - font.fontHeight * wrappedLines.size();
break;
case TOP:
default:
yOffset = 0;
break;
}
for (int i = 0; i < wrappedLines.size(); i++) {
StringRenderable line = wrappedLines.get(i);
int c = LibGuiClient.config.darkMode ? darkmodeColor : color;
ScreenDrawing.drawString(matrices, line, horizontalAlignment, x, y + yOffset + i * font.fontHeight, width, c);
}
Style hoveredTextStyle = getTextStyleAt(mouseX, mouseY);
if (hoveredTextStyle != null) {
Screen screen = MinecraftClient.getInstance().currentScreen;
if (screen instanceof TextHoverRendererScreen) {
((TextHoverRendererScreen) screen).renderTextHover(matrices, hoveredTextStyle, x + mouseX, y + mouseY);
}
}
}
@Environment(EnvType.CLIENT)
private void drawButton(int x, int y, int state, int width) {
float px = 1 / 256f;
float buttonLeft = 0 * px;
float buttonTop = (46 + (state * 20)) * px;
int halfWidth = width / 2;
if (halfWidth > 198) halfWidth = 198;
float buttonWidth = halfWidth * px;
float buttonHeight = 20 * px;
float buttonEndLeft = (200 - halfWidth) * px;
ScreenDrawing.texturedRect(x, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF);
ScreenDrawing.texturedRect(x + halfWidth, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF);
}
@Override
public PlayerEntity getPlayer() {
if (getPacketEnvironment() == EnvType.CLIENT) {
throw new UnsupportedOperationException();
}
return getSender();
}
@Environment(EnvType.CLIENT)
@Override
public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) {
RenderSystem.enableDepthTest();
MinecraftClient mc = MinecraftClient.getInstance();
ItemRenderer renderer = mc.getItemRenderer();
renderer.zOffset = 100f;
renderer.renderInGui(items.get(current), x + getWidth() / 2 - 9, y + getHeight() / 2 - 9);
renderer.zOffset = 0f;
}
@Environment(EnvType.CLIENT)
@Override
public WWidget onMouseDown(int x, int y, int button) {
// Check if cursor is inside or <=2px away from track
if (isMouseInsideBounds(x, y)) {
requestFocus();
}
return super.onMouseDown(x, y, button);
}
@Environment(EnvType.CLIENT)
@Override
public void onCharTyped(char ch) {
if (this.text.length()<this.maxLength) {
//snap cursor into bounds if it went astray
if (cursor<0) cursor=0;
if (cursor>this.text.length()) cursor = this.text.length();
String before = this.text.substring(0, cursor);
String after = this.text.substring(cursor, this.text.length());
this.text = before+ch+after;
cursor++;
}
}
public boolean matches(EnvType type) {
switch (this) {
case CLIENT:
return type == EnvType.CLIENT;
case SERVER:
return type == EnvType.SERVER;
case UNIVERSAL:
return true;
default:
return false;
}
}
@Environment(EnvType.CLIENT)
@Override
public WWidget onMouseUp(int x, int y, int button) {
//TODO: Clicking before or after the handle should jump instead of scrolling
anchor = -1;
anchorValue = -1;
sliding = false;
return this;
}
@Override
public Collection<String> getMixinConfigs(EnvType type) {
return Arrays.asList(mixins).stream()
.filter((e) -> e.environment.matches(type))
.map((e) -> e.config)
.collect(Collectors.toList());
}
@Environment(EnvType.CLIENT)
@Override
public void onKeyReleased(int ch, int key, int modifiers) {
if (pendingDraggingFinishedFromKeyboard && (isDecreasingKey(ch, direction) || isIncreasingKey(ch, direction))) {
if (draggingFinishedListener != null) draggingFinishedListener.accept(value);
pendingDraggingFinishedFromKeyboard = false;
}
}
@Override
public boolean canOpenErrorGui() {
// Disabled on macs due to -XstartOnFirstThread being incompatible with awt but required for lwjgl
if (System.getProperty("os.name").equals("Mac OS X")) {
return false;
}
if (arguments == null || envType == EnvType.CLIENT) {
return true;
}
List<String> extras = arguments.getExtraArgs();
return !extras.contains("nogui") && !extras.contains("--nogui");
}
@Environment(EnvType.CLIENT)
@Override
public WWidget onMouseDown(int x, int y, int button) {
if (children.isEmpty()) return super.onMouseDown(x, y, button);
for(int i=children.size()-1; i>=0; i--) { //Backwards so topmost widgets get priority
WWidget child = children.get(i);
if ( x>=child.getX() &&
y>=child.getY() &&
x<child.getX()+child.getWidth() &&
y<child.getY()+child.getHeight()) {
return child.onMouseDown(x-child.getX(), y-child.getY(), button);
}
}
return super.onMouseDown(x, y, button);
}
@Environment(EnvType.CLIENT)
public BiomeSource withSeed(long seed) {
return new MoonBiomeSource(seed, this.biomeSize);
}