Jump to content

Recommended Posts

Posted

I want to make a gui with a few pages and buttons which are displayed on the different pages. But this undisplayed buttons overlap others buttons, so I can't interact with them. How to solve this?

Posted
@Override
public void init(Minecraft minecraft, int width, int height) {
	super.init(minecraft, width, height);
	minecraft.keyboardListener.enableRepeatEvents(true);
	this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 30, 32, 32, 192, 0, 128, BUTTONS2, e -> {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("blue")){
					HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(0, x, y, z));
					ShopGui.handleButtonAction(entity, 0, x, y, z);
					}
			}) {
				@Override
				public void render(MatrixStack ms, int gx, int gy, float ticks) {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("blue"))
					super.render(ms, gx, gy, ticks);
			}
			});
	this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 30, 32, 32, 192, 0, 128, BUTTONS2, e -> {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("red")){
					HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(1, x, y, z));
					ShopGui.handleButtonAction(entity, 1, x, y, z);
					}
			}) {
				@Override
				public void render(MatrixStack ms, int gx, int gy, float ticks) {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("red"))
					super.render(ms, gx, gy, ticks);
			}
			});
}}

 

Posted

I tried setting the value to false, but it had no effect so I think I'm doing something wrong.

P.S. There's no AbstractWidget in 1.16.5, I only find Widget

Posted

I look more closely at Widget and Button classes, but don't understand how to use the "visible" field so I just tried adding it as ResourseLocation and set it to false, but it did nothing.

Posted (edited)
public class ShopGuiWindow extends ContainerScreen<ShopGui.GuiContainerMod> {
	private World world;
	private int x, y, z;
	private PlayerEntity entity;
	private final static HashMap guistate = ShopGui.guistate;

	public ShopGuiWindow(ShopGui.GuiContainerMod container, PlayerInventory inventory, ITextComponent text) {
		super(container, inventory, text);
		this.world = container.world;
		this.x = container.x;
		this.y = container.y;
		this.z = container.z;
		this.entity = container.entity;
		this.xSize = 190;
		this.ySize = 166;
	}

	private static final ResourceLocation texture = new ResourceLocation("hyrabw:textures/shop.png");
	private static final ResourceLocation BUTTONS = new ResourceLocation("hyrabw:textures/shop_buttons1.png");
	private static final ResourceLocation BUTTONS2 = new ResourceLocation("hyrabw:textures/shop_buttons2.png");
	public boolean visible = false;


	@Override
	public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
		this.renderBackground(ms);
		super.render(ms, mouseX, mouseY, partialTicks);
		this.renderHoveredTooltip(ms, mouseX, mouseY);
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(MatrixStack ms, float partialTicks, int gx, int gy) {
		RenderSystem.color4f(1, 1, 1, 1);
		RenderSystem.enableBlend();
		RenderSystem.defaultBlendFunc();
		Minecraft.getInstance().getTextureManager().bindTexture(texture);
		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		this.blit(ms, k, l, 0, 0, this.xSize, this.ySize, this.xSize, this.ySize);
		RenderSystem.disableBlend();
	}

	@Override
	public boolean keyPressed(int key, int b, int c) {
		if (key == 256) {
			this.minecraft.player.closeScreen();
			return true;
		}
		return super.keyPressed(key, b, c);
	}

	@Override
	public void tick() {
		super.tick();
	}

	@Override
	protected void drawGuiContainerForegroundLayer(MatrixStack ms, int mouseX, int mouseY) {
	}

	@Override
	public void onClose() {
		super.onClose();
		Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
	}

	@Override
	public void init(Minecraft minecraft, int width, int height) {
		super.init(minecraft, width, height);
		minecraft.keyboardListener.enableRepeatEvents(true);
		this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 4, 32, 32, 0, 0, 128, BUTTONS2, e -> {
			if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("red")) {
				HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(0, x, y, z));
				ShopGui.handleButtonAction(entity, 0, x, y, z);
			}
		}) {
			@Override
			public void render(MatrixStack ms, int gx, int gy, float ticks) {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("red"))
					super.render(ms, gx, gy, ticks);
			}
		});
		this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 4, 32, 32, 0, 32, 128, BUTTONS2, e -> {
			if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("blue")) {
				HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(1, x, y, z));
				ShopGui.handleButtonAction(entity, 1, x, y, z);
			}
		}) {
			@Override
			public void renderButton(MatrixStack ms, int gx, int gy, float ticks) {
				if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
				.equals("blue"))
					super.renderButton(ms, gx, gy, ticks);
			}
		});
	}
}

 

Edited by Hyrancood
Posted
Quote

This makes zero sense. Also, why is it static? Why is it using raw types?

Because I use Mcreator to base my code. It works, so I haven't paid much attention to it.

Quote

Why did you add this? It is entirely unused. You must set the visible field on the button instance. And you are still overriding render.

I searched visible field in ImageButton constructors, but I still don't know where I'm supposed to put it.

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • But what could be the issue with that? Maybe the confiq file?  
    • There is an issue with legendarysurvivaloverhaul
    • I am playing on a nitrado server with friends and everytime i try to join i am getting the same crash.log Does somebody understand what the problem here could be?  Crash Log
    • I see. I'm sure I tried again with a lower case word, a few times. I ended up doing the same thing as pixxy in the end. Is this beyond the scope of the admins to fix? Are they already aware of it, or should I use 'contact us' to post a ticket?
    • I’m working on a Manta Ray entity in MCreator using GeckoLib animations, and my goal is to have a looping (flip) animation that ends at −360°, then transitions seamlessly into a swim animation starting at 0°. However, every method I’ve tried—like quickly interpolating the angle, inserting a brief keyframe at 0°, or using a micro “bridge” animation—still causes a visible “flash” https://imgur.com/a/5ucjUb9 or "jump" when the rotation resets. I want a perfectly smooth motion from the flip’s final rotation to the swim’s initial rotation. If anyone has solved this in MCreator/GeckoLib, or found a better trick for handling the −360° →0° gap without a snap, I’d appreciate some advice ! P.S.- I cannot set swim to start at -360 because I would have the same issue but in reverse. Here's the custom LoopingAnimationGoal :   class LoopingAnimationGoal extends Goal { private final MantaRayEntity entity; private final int cooldownTime; private int animationTimer; private int cooldownTimer; // New boolean to prevent double calls private boolean isLoopingActive = false; public LoopingAnimationGoal(MantaRayEntity entity, int cooldownTime) { this.entity = entity; this.cooldownTime = cooldownTime; this.animationTimer = 0; this.cooldownTimer = 0; this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK)); } @Override public boolean canUse() { System.out.println("[DEBUG] LoopingGoal canUse => cooldownTimer=" + cooldownTimer); if (cooldownTimer > 0) { cooldownTimer--; return false; } BlockPos entityPos = entity.blockPosition(); boolean canUse = entity.isWaterAbove(entityPos, 4); System.out.println("[DEBUG] LoopingGoal canUse => WATER " + (canUse ? "DETECTED" : "NOT DETECTED") + " at " + entityPos + ", returning " + canUse); return canUse; } @Override public void start() { entity.setAnimation("looping"); animationTimer = 63; isLoopingActive = true; System.out.println("[DEBUG] Looping animation STARTED. Timer=" + animationTimer + ", gameTime=" + entity.level().getGameTime()); } @Override public boolean canContinueToUse() { System.out.println("[DEBUG] LoopingGoal canContinueToUse => animationTimer=" + animationTimer); return animationTimer > 0; } @Override public void tick() { animationTimer--; System.out.println("[DEBUG] LoopingGoal TICK => animationTimer=" + animationTimer); // We stop ONLY if we are still looping if (animationTimer <= 0 && isLoopingActive) { System.out.println("[DEBUG] condition => animationTimer <= 0 && isLoopingActive"); stop(); } } @Override public void stop() { // Check if already stopped if (!isLoopingActive) { System.out.println("[DEBUG] stop() called again, but isLoopingActive = false. Doing nothing."); return; } System.out.println("[DEBUG] Looping STOP at tick=" + entity.level().getGameTime() + ", last known rotation=" + entity.getXRot() + "/" + entity.getYRot() + ", animationTimer=" + animationTimer); // Immediately switch to "swim" entity.setAnimation("swim"); // Reset cooldown cooldownTimer = cooldownTime; // Disable looping to prevent a second stop isLoopingActive = false; System.out.println("[DEBUG] Looping STOP => setAnimation('swim'), cooldownTimer=" + cooldownTimer); } }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.