net.fabricmc.api.EnvType Java Examples

The following examples show how to use net.fabricmc.api.EnvType. 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: MinecraftGameProvider.java    From fabric-loader with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #2
Source File: WTextField.java    From LibGui with MIT License 6 votes vote down vote up
/**
 * 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 #3
Source File: WitchWaterBubbleColumnBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@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);
		}
	}
}
 
Example #4
Source File: FabricTransformer.java    From fabric-loader with Apache License 2.0 6 votes vote down vote up
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;
		}
	}

}
 
Example #5
Source File: WTiledSprite.java    From LibGui with MIT License 6 votes vote down vote up
@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 #6
Source File: WTextField.java    From LibGui with MIT License 5 votes vote down vote up
@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 #7
Source File: ModMetadataV1.java    From fabric-loader with Apache License 2.0 5 votes vote down vote up
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;
	}
}
 
Example #8
Source File: WPanel.java    From LibGui with MIT License 5 votes vote down vote up
@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 #9
Source File: WText.java    From LibGui with MIT License 5 votes vote down vote up
@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);
		}
	}
}
 
Example #10
Source File: MinecraftGameProvider.java    From fabric-loader with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #11
Source File: ModMetadataV0.java    From fabric-loader with Apache License 2.0 5 votes vote down vote up
@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;
	}
}
 
Example #12
Source File: ModMetadataV1.java    From fabric-loader with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #13
Source File: WAbstractSlider.java    From LibGui with MIT License 5 votes vote down vote up
@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 #14
Source File: WPlayerInvPanel.java    From LibGui with MIT License 5 votes vote down vote up
/**
 * 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 #15
Source File: WScrollBar.java    From LibGui with MIT License 5 votes vote down vote up
@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 #16
Source File: MoonBerryBushBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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 #17
Source File: WAbstractSlider.java    From LibGui with MIT License 5 votes vote down vote up
@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);
}
 
Example #18
Source File: WAbstractSlider.java    From LibGui with MIT License 5 votes vote down vote up
@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;
	}
}
 
Example #19
Source File: WToggleButton.java    From LibGui with MIT License 5 votes vote down vote up
@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 #20
Source File: CompressorBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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 #21
Source File: WItem.java    From LibGui with MIT License 5 votes vote down vote up
@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 #22
Source File: NetworkEvent.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public PlayerEntity getPlayer() {
	if (getPacketEnvironment() == EnvType.CLIENT) {
		throw new UnsupportedOperationException();
	}

	return getSender();
}
 
Example #23
Source File: CrudeOilFluid.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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 #24
Source File: IForgeWorldType.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 #25
Source File: WAbstractSlider.java    From LibGui with MIT License 5 votes vote down vote up
@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 #26
Source File: WLabeledSlider.java    From LibGui with MIT License 5 votes vote down vote up
@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);
}
 
Example #27
Source File: WText.java    From LibGui with MIT License 5 votes vote down vote up
@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);
	}
}
 
Example #28
Source File: StandardWrenchItem.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@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 #29
Source File: WPanel.java    From LibGui with MIT License 5 votes vote down vote up
@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);
}
 
Example #30
Source File: KnotCompatibilityClassLoader.java    From fabric-loader with Apache License 2.0 4 votes vote down vote up
KnotCompatibilityClassLoader(boolean isDevelopment, EnvType envType, GameProvider provider) {
	super(new URL[0], KnotCompatibilityClassLoader.class.getClassLoader());
	this.delegate = new KnotClassDelegate(isDevelopment, envType, this, provider);
}