-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the ability to toggle being a ninja
- Loading branch information
Showing
14 changed files
with
245 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/com/sekwah/narutomod/client/gui/JutsuScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.sekwah.narutomod.client.gui; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.sekwah.narutomod.capabilities.NinjaCapabilityHandler; | ||
import com.sekwah.narutomod.network.PacketHandler; | ||
import com.sekwah.narutomod.network.c2s.ServerToggleNinjaPacket; | ||
import net.minecraft.client.gui.components.Button; | ||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraft.network.chat.Component; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class JutsuScreen extends Screen { | ||
public JutsuScreen() { | ||
super(Component.translatable("naruto.gui.jutsu.title")); | ||
} | ||
|
||
private Button becomeANinja; | ||
private Button changeBack; | ||
|
||
private Component[] renderLines = { | ||
Component.translatable("naruto.gui.jutsu.notice"), | ||
Component.translatable("naruto.gui.jutsu.notice2"), | ||
Component.empty(), | ||
Component.translatable("naruto.gui.jutsu.placeholder"), | ||
}; | ||
|
||
protected void init() { | ||
this.addButtons(); | ||
} | ||
|
||
public void addButtons() { | ||
|
||
becomeANinja = this.addRenderableWidget(new Button(this.width / 2 - 102, this.height / 4 + 72 + -16, 98, 20, Component.translatable("naruto.gui.jutsu.enable"), (buttonRef) -> { | ||
PacketHandler.sendToServer(new ServerToggleNinjaPacket(true)); | ||
})); | ||
renderables.add(becomeANinja); | ||
becomeANinja.active = false; | ||
|
||
changeBack = this.addRenderableWidget(new Button(this.width / 2 + 4, this.height / 4 + 72 + -16, 98, 20, Component.translatable("naruto.gui.jutsu.disable"), (buttonRef) -> { | ||
PacketHandler.sendToServer(new ServerToggleNinjaPacket(false)); | ||
})); | ||
renderables.add(changeBack); | ||
changeBack.active = false; | ||
|
||
Button back = this.addRenderableWidget(new Button(this.width / 2 - 98 / 2, this.height / 4 + 72 + 7, 98, 20, Component.translatable("naruto.gui.jutsu.done"), (buttonRef) -> { | ||
this.minecraft.popGuiLayer(); | ||
})); | ||
renderables.add(back); | ||
} | ||
|
||
public void tick() { | ||
super.tick(); | ||
AtomicBoolean isNinja = new AtomicBoolean(false); | ||
var player = this.minecraft.player; | ||
if(player != null) { | ||
player.getCapability(NinjaCapabilityHandler.NINJA_DATA).ifPresent(ninjaData -> { | ||
isNinja.set(ninjaData.isNinjaModeEnabled()); | ||
}); | ||
} | ||
becomeANinja.active = !isNinja.get(); | ||
changeBack.active = isNinja.get(); | ||
} | ||
|
||
public boolean isPauseScreen() { | ||
return false; | ||
} | ||
|
||
public void render(PoseStack poseStack, int p_96311_, int p_96312_, float p_96313_) { | ||
this.renderBackground(poseStack); | ||
drawCenteredString(poseStack, this.font, this.title, this.width / 2, 40, 16777215); | ||
for (int i = 0; i < renderLines.length; i++) { | ||
drawCenteredString(poseStack, this.font, renderLines[i], this.width / 2, 60 + 10 * i, 16777215); | ||
} | ||
super.render(poseStack, p_96311_, p_96312_, p_96313_); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.