net.fabricmc.api.Environment Java Examples
The following examples show how to use
net.fabricmc.api.Environment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WTiledSprite.java From LibGui with MIT License | 6 votes |
@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); } } }
Example #2
Source File: WitchWaterFluid.java From the-hallow with MIT License | 6 votes |
@Override @Environment(EnvType.CLIENT) public void randomDisplayTick(World world, BlockPos blockPos, FluidState fluidState, Random random) { if (random.nextInt(10) == 0) { world.addParticle(ParticleTypes.BUBBLE_POP, (double) blockPos.getX() + 0.5D + (random.nextFloat() - 0.5F), (double) blockPos.getY() + (fluidState.getHeight(world, blockPos) * (1F / 7F)) + 1F, (double) blockPos.getZ() + 0.5D + (random.nextFloat() - 0.5F), 0.0D, 0.0D, 0.0D ); } if (random.nextInt(15) == 0) { world.addParticle(ParticleTypes.BUBBLE, (double) blockPos.getX() + 0.5D + (random.nextFloat() - 0.5F), (double) blockPos.getY() + (fluidState.getHeight(world, blockPos) * (1F / 7F)) + 1F, (double) blockPos.getZ() + 0.5D + (random.nextFloat() - 0.5F), 0.0D, 0.0D, 0.0D ); } }
Example #3
Source File: SkirtCostumeItem.java From the-hallow with MIT License | 6 votes |
@Override @Environment(EnvType.CLIENT) public void render(String slot, MatrixStack matrix, VertexConsumerProvider vertexConsumer, int light, PlayerEntityModel<AbstractClientPlayerEntity> model, AbstractClientPlayerEntity player, float headYaw, float headPitch) { ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer(); matrix.push(); translateToChest(model, player, headYaw, headPitch, matrix); //TODO switch back to trinkets version once it's fixed matrix.push(); matrix.translate(0.25, 0.65, 0); matrix.scale(0.5F, 0.5F, 0.5F); matrix.multiply(ROTATION_CONSTANT); renderer.renderItem(new ItemStack(Items.BLAZE_ROD), ModelTransformation.Mode.FIXED, light, OverlayTexture.DEFAULT_UV, matrix, vertexConsumer); matrix.pop(); matrix.push(); matrix.translate(-0.25, 0.65, 0); matrix.scale(0.5F, 0.5F, 0.5F); matrix.multiply(ROTATION_CONSTANT); renderer.renderItem(new ItemStack(Items.BLAZE_ROD), ModelTransformation.Mode.FIXED, light, OverlayTexture.DEFAULT_UV, matrix, vertexConsumer); matrix.pop(); matrix.push(); matrix.translate(0, 0.65, 0.325); matrix.scale(0.5F, 0.5F, 0.5F); matrix.multiply(ROTATION_CONSTANT); renderer.renderItem(new ItemStack(Items.BLAZE_ROD), ModelTransformation.Mode.FIXED, light, OverlayTexture.DEFAULT_UV, matrix, vertexConsumer); matrix.pop(); matrix.pop(); }
Example #4
Source File: WPanel.java From LibGui with MIT License | 6 votes |
@Environment(EnvType.CLIENT) @Override public void onMouseDrag(int x, int y, int button) { if (children.isEmpty()) return; 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()) { child.onMouseDrag(x-child.getX(), y-child.getY(), button); return; //Only send the message to the first valid recipient } } super.onMouseDrag(x, y, button); }
Example #5
Source File: WTextField.java From LibGui with MIT License | 6 votes |
/** * 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(); }
Example #6
Source File: GlowstoneWallTorchBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override @Environment(EnvType.CLIENT) public void buildTooltip(ItemStack itemStack, BlockView blockView, List<Text> list, TooltipContext tooltipContext) { if (Screen.hasShiftDown()) { list.add(new TranslatableText("tooltip.galacticraft-rewoven.glowstone_torch").setStyle(Style.EMPTY.withColor(Formatting.GRAY))); } else { list.add(new TranslatableText("tooltip.galacticraft-rewoven.press_shift").setStyle(Style.EMPTY.withColor(Formatting.GRAY))); } }
Example #7
Source File: WPlayerInvPanel.java From LibGui with MIT License | 5 votes |
/** * 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; }
Example #8
Source File: WButton.java From LibGui with MIT License | 5 votes |
@Environment(EnvType.CLIENT) @Override public void onClick(int x, int y, int button) { super.onClick(x, y, button); if (enabled && isWithinBounds(x, y)) { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); if (onClick!=null) onClick.run(); } }
Example #9
Source File: IForgeWorldType.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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)); } }
Example #10
Source File: MoonBerryBushBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@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); } } }
Example #11
Source File: WItem.java From LibGui with MIT License | 5 votes |
@Environment(EnvType.CLIENT) @Override public void tick() { if (ticks++ >= duration) { ticks = 0; current = (current + 1) % items.size(); } }
Example #12
Source File: WItem.java From LibGui with MIT License | 5 votes |
@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; }
Example #13
Source File: CompressorBlock.java From Galacticraft-Rewoven with MIT License | 5 votes |
@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))); } }
Example #14
Source File: BatteryItem.java From Galacticraft-Rewoven with MIT License | 5 votes |
@Override @Environment(EnvType.CLIENT) public void appendTooltip(ItemStack stack, World world, List<Text> lines, TooltipContext context) { int charge = stack.getOrCreateTag().getInt("Energy"); if (stack.getMaxDamage() - stack.getDamage() < 3334) { lines.add(new TranslatableText("tooltip.galacticraft-rewoven.energy-remaining", charge).setStyle(Style.EMPTY.withColor(Formatting.DARK_RED))); } else if (stack.getMaxDamage() - stack.getDamage() < 6667) { lines.add(new TranslatableText("tooltip.galacticraft-rewoven.energy-remaining", charge).setStyle(Style.EMPTY.withColor(Formatting.GOLD))); } else { lines.add(new TranslatableText("tooltip.galacticraft-rewoven.energy-remaining", charge).setStyle(Style.EMPTY.withColor(Formatting.GREEN))); } super.appendTooltip(stack, world, lines, context); }
Example #15
Source File: WLabel.java From LibGui with MIT License | 5 votes |
@Environment(EnvType.CLIENT) @Override public void onClick(int x, int y, int button) { Style hoveredTextStyle = getTextStyleAt(x, y); if (hoveredTextStyle != null) { Screen screen = MinecraftClient.getInstance().currentScreen; if (screen != null) { screen.handleTextClick(hoveredTextStyle); } } }
Example #16
Source File: CrudeOilFluid.java From Galacticraft-Rewoven with MIT License | 5 votes |
@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); } }
Example #17
Source File: WPanel.java From LibGui with MIT License | 5 votes |
@Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (backgroundPainter!=null) backgroundPainter.paintBackground(x, y, this); for(WWidget child : children) { child.paint(matrices, x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); } }
Example #18
Source File: WAbstractSlider.java From LibGui with MIT License | 5 votes |
@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; } }
Example #19
Source File: WLabel.java From LibGui with MIT License | 5 votes |
/** * Gets the text style at the specific widget-space coordinates. * * @param x the X coordinate in widget space * @param y the Y coordinate in widget space * @return the text style at the position, or null if not found */ @Environment(EnvType.CLIENT) @Nullable public Style getTextStyleAt(int x, int y) { if (isWithinBounds(x, y)) { return MinecraftClient.getInstance().textRenderer.getTextHandler().trimToWidth(text, x); } return null; }
Example #20
Source File: StandardWrenchItem.java From Galacticraft-Rewoven with MIT License | 5 votes |
@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))); } }
Example #21
Source File: HallowedFogColorCalculator.java From the-hallow with MIT License | 5 votes |
@Override @Environment(EnvType.CLIENT) public Vec3d calculate(float v, float v1) { World world = MinecraftClient.getInstance().world; PlayerEntity player = MinecraftClient.getInstance().player; double totalR = 0; double totalG = 0; double totalB = 0; int count = 0; int radius = HallowedConfig.HallowedFog.fogSmoothingRadius; for (int x = 0; x < radius; x++) { for (int z = 0; z < radius; z++) { BlockPos pos = player.getBlockPos().add(x - (radius / 2), 0, z - (radius / 2)); if (world.getBiomeAccess().getBiome(pos) instanceof HallowedBiomeInfo) { HallowedBiomeInfo biomeInfo = (HallowedBiomeInfo) world.getBiomeAccess().getBiome(pos); totalR += Math.pow(biomeInfo.getFogColor().x, 2); totalG += Math.pow(biomeInfo.getFogColor().y, 2); totalB += Math.pow(biomeInfo.getFogColor().z, 2); } count++; } } return new Vec3d(Math.sqrt(totalR / count), Math.sqrt(totalG / count), Math.sqrt(totalB / count)); }
Example #22
Source File: WAbstractSlider.java From LibGui with MIT License | 5 votes |
@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; } }
Example #23
Source File: WTextField.java From LibGui with MIT License | 5 votes |
@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++; } }
Example #24
Source File: WTextField.java From LibGui with MIT License | 5 votes |
/** * From a caret position, finds out what the x-offset to draw the caret is. * @param s * @param pos * @return */ @Environment(EnvType.CLIENT) public static int getCaretOffset(String s, int pos) { if (pos==0) return 0;//-1; TextRenderer font = MinecraftClient.getInstance().textRenderer; int ofs = font.getWidth(s.substring(0, pos))+1; return ofs; //(font.isRightToLeft()) ? -ofs : ofs; }
Example #25
Source File: WScrollBar.java From LibGui with MIT License | 5 votes |
@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; }
Example #26
Source File: WItemSlot.java From LibGui with MIT License | 5 votes |
@Environment(EnvType.CLIENT) @Override public void onKeyPressed(int ch, int key, int modifiers) { if (isActivationKey(ch) && host instanceof ScreenHandler && focusedSlot >= 0) { ScreenHandler handler = (ScreenHandler) host; MinecraftClient client = MinecraftClient.getInstance(); ValidatedSlot peer = peers.get(focusedSlot); client.interactionManager.clickSlot(handler.syncId, peer.id, 0, SlotActionType.PICKUP, client.player); } }
Example #27
Source File: WAbstractSlider.java From LibGui with MIT License | 5 votes |
@Environment(EnvType.CLIENT) @Override public void onMouseDrag(int x, int y, int button) { if (isFocused()) { dragging = true; moveSlider(x, y); } }
Example #28
Source File: WPanel.java From LibGui with MIT License | 5 votes |
@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); }
Example #29
Source File: WToggleButton.java From LibGui with MIT License | 5 votes |
@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); }
Example #30
Source File: WText.java From LibGui with MIT License | 5 votes |
/** * Gets the text style at the specific widget-space coordinates. * * @param x the X coordinate in widget space * @param y the Y coordinate in widget space * @return the text style at the position, or null if not found */ @Environment(EnvType.CLIENT) @Nullable public Style getTextStyleAt(int x, int y) { TextRenderer font = MinecraftClient.getInstance().textRenderer; int lineIndex = y / font.fontHeight; if (lineIndex >= 0 && lineIndex < wrappedLines.size()) { StringRenderable line = wrappedLines.get(lineIndex); return font.getTextHandler().trimToWidth(line, x); } return null; }