net.minecraft.util.Rarity#net.fabricmc.api.Environment源码实例Demo

下面列出了net.minecraft.util.Rarity#net.fabricmc.api.Environment 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: the-hallow   文件: WitchWaterFluid.java
@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
		);
	}
}
 
源代码2 项目: the-hallow   文件: SkirtCostumeItem.java
@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();
}
 
源代码3 项目: LibGui   文件: WPanel.java
@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);
}
 
源代码4 项目: LibGui   文件: WTextField.java
/**
 * 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();
}
 
源代码5 项目: LibGui   文件: WTiledSprite.java
@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);
		}
	}
}
 
源代码6 项目: LibGui   文件: WItem.java
@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;
}
 
源代码7 项目: LibGui   文件: WPlayerInvPanel.java
/**
 * 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;
}
 
源代码8 项目: LibGui   文件: WLabel.java
@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);
		}
	}
}
 
源代码9 项目: patchwork-api   文件: IForgeWorldType.java
/**
 * 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));
	}
}
 
@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)));
    }
}
 
源代码11 项目: Galacticraft-Rewoven   文件: MoonBerryBushBlock.java
@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);
        }
    }
}
 
源代码12 项目: LibGui   文件: WButton.java
@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();
	}
}
 
源代码13 项目: LibGui   文件: WItem.java
@Environment(EnvType.CLIENT)
@Override
public void tick() {
	if (ticks++ >= duration) {
		ticks = 0;
		current = (current + 1) % items.size();
	}
}
 
源代码14 项目: Galacticraft-Rewoven   文件: CompressorBlock.java
@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)));
    }
}
 
源代码15 项目: Galacticraft-Rewoven   文件: CrudeOilFluid.java
@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);
    }
}
 
源代码16 项目: LibGui   文件: WPanel.java
@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());
	}
}
 
源代码17 项目: LibGui   文件: WAbstractSlider.java
@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;
	}
}
 
源代码18 项目: LibGui   文件: WLabel.java
/**
 * 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;
}
 
源代码19 项目: Galacticraft-Rewoven   文件: StandardWrenchItem.java
@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)));
    }
}
 
源代码20 项目: Galacticraft-Rewoven   文件: BatteryItem.java
@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);
}
 
源代码21 项目: the-hallow   文件: HallowedFogColorCalculator.java
@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));
}
 
源代码22 项目: LibGui   文件: WAbstractSlider.java
@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;
	}
}
 
源代码23 项目: LibGui   文件: WTextField.java
@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++;
	}
}
 
源代码24 项目: LibGui   文件: WTextField.java
/**
 * 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;
}
 
源代码25 项目: LibGui   文件: WScrollBar.java
@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;
}
 
源代码26 项目: LibGui   文件: WItemSlot.java
@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);
	}
}
 
源代码27 项目: LibGui   文件: WAbstractSlider.java
@Environment(EnvType.CLIENT)
@Override
public void onMouseDrag(int x, int y, int button) {
	if (isFocused()) {
		dragging = true;
		moveSlider(x, y);
	}
}
 
源代码28 项目: LibGui   文件: WPanel.java
@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);
}
 
源代码29 项目: LibGui   文件: WToggleButton.java
@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);
}
 
源代码30 项目: LibGui   文件: WText.java
/**
 * 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;
}