Skip to content

Commit

Permalink
Added Forge version (Untested)
Browse files Browse the repository at this point in the history
All NeoForge issues have all been fixed
  • Loading branch information
GirafiStudios committed Dec 9, 2023
1 parent 01a94ac commit fa82e90
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,6 @@ public static void renderHeaderAndFooter(GuiGraphics guiGraphics, Screen base, i
Tesselator tessellator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuilder();

// HEADER - SHADOW
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);

bufferBuilder.vertex(0, headerHeight + shadowDepth, 0.0D).uv(0.0F, 1.0F).color(0, 0, 0, 0).endVertex();
bufferBuilder.vertex(base.width, headerHeight + shadowDepth, 0.0D).uv(1.0F, 1.0F).color(0, 0, 0, 0).endVertex();

bufferBuilder.vertex(base.width, headerHeight, 0.0D).uv(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(0, headerHeight, 0.0D).uv(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();

tessellator.end();

// FOOTER - SHADOW
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);

bufferBuilder.vertex(0, base.height - footerHeight, 0.0D).uv(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(base.width, base.height - footerHeight, 0.0D).uv(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();

bufferBuilder.vertex(base.width, base.height - footerHeight - shadowDepth, 0.0D).uv(1.0F, 0.0F).color(0, 0, 0, 0).endVertex();
bufferBuilder.vertex(0, base.height - footerHeight - shadowDepth, 0.0D).uv(0.0F, 0.0F).color(0, 0, 0, 0).endVertex();

tessellator.end();

RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.disableBlend();

Expand Down Expand Up @@ -77,6 +55,8 @@ public static void renderHeaderAndFooter(GuiGraphics guiGraphics, Screen base, i

poseStack.popPose();

poseStack.pushPose();
guiGraphics.drawCenteredString(Minecraft.getInstance().font, headerText, base.width / 2, 8, 16777215);
poseStack.popPose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.girafi.minemenu.gui.ScreenStack;
import com.girafi.minemenu.helper.GuiRenderHelper;
import com.girafi.minemenu.menu.button.ItemButton;
import com.girafi.minemenu.platform.Services;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
Expand All @@ -23,7 +22,7 @@
import java.util.Collections;

public class ClickActionScreen extends Screen {
public static final boolean IS_CONTROLLING_LOADED = Services.PLATFORM.isModLoaded("controlling");
//public static final boolean IS_CONTROLLING_LOADED = Services.PLATFORM.isModLoaded("controlling");
public static ItemStack item;
public static KeyMapping keyBinding;
private static boolean toggle = false;
Expand All @@ -48,12 +47,6 @@ public ClickActionScreen() {
ClickActionScreen.item = ItemStack.EMPTY;
}

/*@Override
public void tick() {
this.textCommand.tick();
this.textCategory.tick();
}*/

@Override
@Nullable
public GuiEventListener getFocused() {
Expand Down Expand Up @@ -270,25 +263,16 @@ public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPre

@Override
public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) {
this.renderBackground(guiGraphics, mouseX, mouseY, partial);
super.render(guiGraphics, mouseX, mouseY, partial);
this.textCommand.render(guiGraphics, mouseX, mouseY, partial);
this.textCategory.render(guiGraphics, mouseX, mouseY, partial);
super.render(guiGraphics, mouseX, mouseY, partial);
String header = "";
switch (mode) {
case 0:
header = "Enter a command";
break;
case 1:
header = "Select a key";
break;
case 2:
header = "Pick an item";
break;
case 3:
header = "Enter a category";
break;
}
String header = switch (mode) {
case 0 -> "Enter a command";
case 1 -> "Select a key";
case 2 -> "Pick an item";
case 3 -> "Enter a category";
default -> "";
};
GuiRenderHelper.renderHeaderAndFooter(guiGraphics, this, 25, 20, 5, header);
if (mouseX > modeCommand.getX() && mouseX < modeCommand.getX() + modeCommand.getWidth() && mouseY > modeCommand.getY() && mouseY < modeCommand.getY() + modeCommand.getWidth()) {
guiGraphics.renderTooltip(this.font, Collections.singletonList(Component.translatable("mine_menu.clickAction_command").getVisualOrderText()), mouseX, mouseY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public MenuItemScreen(int slot, MenuItem menuItem) {

@Override
public void tick() {
//this.textTitle.tick();

this.buttonConfirm.visible = EditSessionData.clickAction != null;
this.buttonDelete.visible = RadialMenu.getActiveArray()[slot] != null;
}
Expand Down Expand Up @@ -136,10 +134,9 @@ public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPre

@Override
public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) {
this.renderBackground(guiGraphics, mouseX, mouseY, partial);
super.render(guiGraphics, mouseX, mouseY, partial);
this.textTitle.render(guiGraphics, mouseX, mouseY, partial);
guiGraphics.drawCenteredString(this.font, "Enter a title, then configure using the options below", this.width / 2, 80, 16777215);
super.render(guiGraphics, mouseX, mouseY, partial);
GuiRenderHelper.renderHeaderAndFooter(guiGraphics, this, 25, 20, 5, "Modifying Menu Item #" + slot);
}
}
37 changes: 18 additions & 19 deletions common/src/main/java/com/girafi/minemenu/menu/PickIconScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.NonNullList;
import net.minecraft.core.registries.BuiltInRegistries;
Expand All @@ -20,7 +19,6 @@
import org.lwjgl.glfw.GLFW;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class PickIconScreen extends Screen {
private static final int MAX_COLUMN = 14;
Expand Down Expand Up @@ -54,12 +52,6 @@ private void reconstructList(NonNullList<ItemStack> list) {
}
}

@Override
@Nullable
public GuiEventListener getFocused() {
return this.textSearch;
}

@Override
public void init() {
stacks = NonNullList.create();
Expand All @@ -69,6 +61,7 @@ public void init() {
this.textSearch = new EditBox(this.font, this.width / 2 - 150, 40, 300, 20, Component.translatable("mine_menu.pickIcon.search"));
this.textSearch.setMaxLength(32767);
this.textSearch.setFocused(true);
this.setInitialFocus(textSearch);
}

@Override
Expand Down Expand Up @@ -107,18 +100,22 @@ public boolean charTyped(char key, int keyCode) {
}
}
}
return true;
}
return super.charTyped(key, keyCode);
}
return false;
}

@Override
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
if (p_keyPressed_1_ == GLFW.GLFW_KEY_ESCAPE) {
public boolean keyPressed(int keycode, int i2, int i3) {
if (keycode == GLFW.GLFW_KEY_ESCAPE) {
ScreenStack.pop();
return true;
} else if (this.textSearch.keyPressed(keycode, i2, i3)) {
return true;
} else {
return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_);
return super.keyPressed(keycode, i2, i3);
}
}

Expand All @@ -136,7 +133,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double wheel, double d) {
public boolean mouseScrolled(double mouseX, double mouseY, double d, double wheel) {
wheel = -wheel;

if (wheel < 0) {
Expand All @@ -159,11 +156,8 @@ public boolean mouseScrolled(double mouseX, double mouseY, double wheel, double

@Override
public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) {
this.renderBackground(guiGraphics, mouseX, mouseY, partial);

this.textSearch.render(guiGraphics, mouseX, mouseY, partial);

super.render(guiGraphics, mouseX, mouseY, partial);
this.textSearch.render(guiGraphics, mouseX, mouseY, partial);

GuiRenderHelper.renderHeaderAndFooter(guiGraphics, this, 25, 20, 5, "Select an Icon:");

Expand All @@ -175,12 +169,14 @@ private void drawList(GuiGraphics guiGraphics, int x, int y, int mx, int my) {
int highlightedX = 0;
int highlightedY = 0;

int amountOfRowsThatFits = ((this.minecraft.getWindow().getGuiScaledHeight() - 150) / 16);
amountOfRowsThatFits = amountOfRowsThatFits > 7 ? amountOfRowsThatFits - 6 : amountOfRowsThatFits;

for (int i = MAX_COLUMN * listScrollIndex; i < stacks.size(); i++) {
int drawX = i % MAX_COLUMN;
int drawY = i / MAX_COLUMN;

if (((i - 14 * listScrollIndex) / MAX_COLUMN) <= MAX_ROW) {

if (((i - 14 * listScrollIndex) / MAX_COLUMN) <= amountOfRowsThatFits) {
boolean scaled = false;
int actualDrawX = (x + drawX * 20) - (7 * 20) + 10;
int actualDrawY = (y + drawY * 20);
Expand Down Expand Up @@ -217,7 +213,10 @@ private ItemStack getClickedStack(int x, int y, double mx, double my) {
int drawX = i % MAX_COLUMN;
int drawY = i / MAX_COLUMN;

if (((i - 14 * listScrollIndex) / MAX_COLUMN) <= MAX_ROW) {
int amountOfRowsThatFits = ((this.minecraft.getWindow().getGuiScaledHeight() - 150) / 16);
amountOfRowsThatFits = amountOfRowsThatFits > 7 ? amountOfRowsThatFits - 6 : amountOfRowsThatFits;

if (((i - 14 * listScrollIndex) / MAX_COLUMN) <= amountOfRowsThatFits) {
float actualDrawX = (x + drawX * 20) - (7 * 20) + 10;
float actualDrawY = (y + drawY * 20);
actualDrawY -= 20 * listScrollIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public void init() {

@Override
public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(guiGraphics, mouseX, mouseY, partialTicks);
super.render(guiGraphics, mouseX, mouseY, partialTicks);
Minecraft mc = this.minecraft;
GuiRenderHelper.renderHeaderAndFooter(guiGraphics, this, 25, 20, 5, "Pick an Item:");
Expand Down
11 changes: 6 additions & 5 deletions common/src/main/java/com/girafi/minemenu/menu/PickKeyScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.girafi.minemenu.menu;

import com.girafi.minemenu.gui.ScreenStack;
import com.girafi.minemenu.helper.GuiRenderHelper;
import com.girafi.minemenu.menu.list.GuiControlList;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -59,10 +60,10 @@ public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
}

@Override
public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(guiGraphics, mouseX, mouseY, partialTicks);
this.controlList.render(guiGraphics, mouseX, mouseY, partialTicks);
guiGraphics.drawCenteredString(this.font, "Select a Key:", this.width / 2, 8, 16777215);
super.render(guiGraphics, mouseX, mouseY, partialTicks);
public void render(@Nonnull GuiGraphics guiGraphics, int x, int y, float partialTicks) {
super.render(guiGraphics, x, y, partialTicks);
GuiRenderHelper.renderHeaderAndFooter(guiGraphics, this, 25, 20, 5, "Select a Key:");
this.controlList.render(guiGraphics, x, y, partialTicks);
//guiGraphics.drawCenteredString(this.font, "Select a Key:", this.width / 2, 8, 16777215);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ public ItemButton(int xPos, int yPos, int width, int height, @Nonnull ItemStack
}

@Override
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) {
public void renderWidget(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partial) {
if (this.visible) {
super.renderWidget(guiGraphics, mouseX, mouseY, partial);
this.isHovered = mouseX >= this.getX() && mouseY >= this.getY() && mouseX < this.getX() + this.width && mouseY < this.getY() + this.height;
int k = !this.active ? 0 : (this.isHoveredOrFocused() ? 2 : 1);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
//ScreenUtils.blitWithBorder(guiGraphics, WIDGETS_LOCATION, this.getX(), this.getY(), 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, 0); //Old way
guiGraphics.blitSprite(SPRITES.get(this.active, this.isHoveredOrFocused()), this.getX(), this.getY(), this.getWidth(), this.getHeight()); //TODO Test if button renders correctly


if (this.icon.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void refreshEntry() {
this.buttonSelect.setMessage(this.key.getTranslatedKeyMessage());
MutableComponent mutablecomponent = Component.empty();
if (!this.key.isUnbound()) {
for(KeyMapping keymapping : GuiControlList.this.minecraft.options.keyMappings) {
for (KeyMapping keymapping : GuiControlList.this.minecraft.options.keyMappings) {
if ((keymapping != this.key && this.key.same(keymapping)) /*|| keymapping.hasKeyModifierConflict(this.key)*/) {
mutablecomponent.append(Component.translatable(keymapping.getName()));
}
Expand Down
File renamed without changes
21 changes: 2 additions & 19 deletions fabric/src/main/java/com/girafi/minemenu/MineMenu.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
package com.girafi.minemenu;

import com.girafi.minemenu.client.KeyHelper;
import com.girafi.minemenu.client.PingHandlerHelper;
import com.girafi.minemenu.client.PingKeybinds;
import com.girafi.minemenu.client.gui.PingSelectGui;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.loader.api.FabricLoader;

public class MineMenu implements ModInitializer {

@Override
public void onInitialize() {
MineMenuCommon.loadCommon();
MineMenuCommon.loadCommon(FabricLoader.getInstance().getGameDir().toFile());

//Register keybinds
KeyBindingHelper.registerKeyBinding(PingKeybinds.KEY_BINDING);
KeyBindingHelper.registerKeyBinding(PingKeybinds.PING_ALERT);
KeyBindingHelper.registerKeyBinding(PingKeybinds.PING_MINE);
KeyBindingHelper.registerKeyBinding(PingKeybinds.PING_LOOK);
KeyBindingHelper.registerKeyBinding(PingKeybinds.PING_GOTO);

//TODO Register Shader Instance (Probably not here, but somehow somewhere)

ClientTickEvents.END_CLIENT_TICK.register((mc) -> {
PingHandlerHelper.pingTimer();
KeyHelper.onTick();

if ((mc.level == null || mc.isPaused()) && PingSelectGui.active) {
PingSelectGui.deactivate();
}
});
}
}
6 changes: 3 additions & 3 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"${mod_author}"
],
"contact": {
"homepage": "https://minecraft.curseforge.com/projects/ping",
"sources": "https://github.com/dmillerw/Ping/issues"
"homepage": "https://www.curseforge.com/minecraft/mc-mods/minemenu",
"sources": "https://github.com/GirafiStudios/MineMenu/issues"
},
"license": "${license}",
"icon": "assets/${mod_id}/logo.png",
"icon": "assets/${mod_id}/icon.png",
"environment": "*",
"entrypoints": {
"main": [
Expand Down
36 changes: 36 additions & 0 deletions forge/src/main/java/com/girafi/MineMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.girafi;

import com.girafi.minemenu.Constants;
import com.girafi.minemenu.MineMenuCommon;
import com.girafi.minemenu.util.Config;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;
import net.neoforged.fml.config.ModConfig;

@Mod(Constants.MOD_ID)
public class MineMenu {

public MineMenu() {
final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
modBus.addListener(EventPriority.LOWEST, this::loadMenuLoader);
modBus.addListener(this::registerKeybind);

MineMenuCommon.loadCommon(FMLPaths.GAMEDIR.get().toFile());

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.spec);
}

public void loadMenuLoader(final FMLClientSetupEvent event) {
MineMenuCommon.setupMenuLoader();
}

public void registerKeybind(RegisterKeyMappingsEvent event) {
event.register(MineMenuCommon.WHEEL);
}
}

0 comments on commit fa82e90

Please sign in to comment.