Skip to content

Commit

Permalink
Basic hud elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Nov 14, 2023
1 parent 944bbde commit 5c2b8fd
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 11 deletions.
1 change: 1 addition & 0 deletions common/src/main/java/de/griefed/addemall/CommonClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static void init() {

ModItems.loadClass();
KeyInputHandler.loadClass();

}

public static void onItemTooltip(ItemStack stack, TooltipFlag context, List<Component> tooltip) {
Expand Down
59 changes: 59 additions & 0 deletions common/src/main/java/de/griefed/addemall/client/BlockToolHud.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package de.griefed.addemall.client;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import de.griefed.addemall.Constants;
import de.griefed.addemall.event.KeyInputHandler;
import de.griefed.addemall.item.ModItems;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;

public class BlockToolHud {

protected static final ResourceLocation TOOL_MULTI_ACTIVATED = new ResourceLocation(Constants.MOD_ID, "textures/item/multi.png");
protected static final ResourceLocation TOOL_MULTI_DEACTIVATED = new ResourceLocation(Constants.MOD_ID, "textures/item/multi_deactivated.png");
protected static final ResourceLocation TOOL_SHOVEL = new ResourceLocation(Constants.MOD_ID, "textures/item/shovel.png");
protected static final ResourceLocation TOOL_HOE = new ResourceLocation(Constants.MOD_ID, "textures/item/hoe.png");
protected static final ResourceLocation TOOL_BAR = new ResourceLocation(Constants.MOD_ID, "textures/item/bar.png");

protected static void renderToolSettings(PoseStack stack, int x, int height) {
Player player = Minecraft.getInstance().player;
if (player == null) {
return;
}
if (player.getMainHandItem().is(ModItems.BLOCK_TOOL.get())) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

RenderSystem.setShaderTexture(0, TOOL_BAR);
// X coord Y coord u v wid hei twi the
GuiComponent.blit(stack, x + 96, height - 23, 0, 0, 65, 23, 65, 23);

if (KeyInputHandler.BLOCKTOOL_MULTI_ACTIVE) {
RenderSystem.setShaderTexture(0, TOOL_MULTI_ACTIVATED);
GuiComponent.blit(stack, x + 100, height - 19, 0, 0, 16, 16, 16, 16);
} else {
RenderSystem.setShaderTexture(0, TOOL_MULTI_DEACTIVATED);
GuiComponent.blit(stack, x + 100, height - 19, 0, 0, 16, 16, 16, 16);
}

if (KeyInputHandler.BLOCKTOOL_SHOVELMODE) {
RenderSystem.setShaderTexture(0, TOOL_SHOVEL);
GuiComponent.blit(stack, x + 120, height - 19, 0, 0, 16, 16, 16, 16);
} else {
RenderSystem.setShaderTexture(0, TOOL_HOE);
GuiComponent.blit(stack, x + 120, height - 19, 0, 0, 16, 16, 16, 16);
}

// TODO draw selected block
// TODO draw amount available
/*if (block selected) {
RenderSystem.setShaderTexture(0, stack of selected block with amount of material available);
GuiComponent.blit(stack, x + 140, height - 19, 0, 0, 16, 16, 16, 16);
}*/
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package de.griefed.addemall.event;

import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.KeyMapping;
import org.lwjgl.glfw.GLFW;

public class KeyInputHandler {

Expand All @@ -13,8 +11,8 @@ public class KeyInputHandler {
public static KeyMapping toolBehaviourKey;
public static KeyMapping toolShovelHoeKey;

public static boolean TOOL_BEHAVIOUR = false;
public static boolean TOOL_SHOVEL_HOE = false;
public static boolean BLOCKTOOL_MULTI_ACTIVE = false;
public static boolean BLOCKTOOL_SHOVELMODE = false;

public static void loadClass() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public InteractionResult useOn(UseOnContext context) {
BlockState blockState = level.getBlockState(blockPos);
Block block = blockState.getBlock();
ItemStack itemInHand = context.getItemInHand();
if (player != null && player.isSecondaryUseActive() && KeyInputHandler.TOOL_BEHAVIOUR) {
if (player != null && player.isSecondaryUseActive() && KeyInputHandler.BLOCKTOOL_MULTI_ACTIVE) {
// Axe
Optional<BlockState> strippedState = getStripped(blockState);
Optional<BlockState> previousState = WeatheringCopper.getPrevious(blockState);
Expand Down Expand Up @@ -98,7 +98,7 @@ public InteractionResult useOn(UseOnContext context) {
level.setBlockAndUpdate(blockPos, headBlock.getMaxAgeState(blockState));

return InteractionResult.sidedSuccess(level.isClientSide);
} else if (KeyInputHandler.TOOL_SHOVEL_HOE) {
} else if (KeyInputHandler.BLOCKTOOL_SHOVELMODE) {
// shovel
if (context.getClickedFace() == Direction.DOWN) {
return InteractionResult.PASS;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added definitions/bb projects/Block Tool/bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added definitions/bb projects/Block Tool/bar.xcf
Binary file not shown.
Binary file added definitions/bb projects/Block Tool/hoe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added definitions/bb projects/Block Tool/hoe.xcf
Binary file not shown.
Binary file added definitions/bb projects/Block Tool/multi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added definitions/bb projects/Block Tool/multi.xcf
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added definitions/bb projects/Block Tool/shovel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added definitions/bb projects/Block Tool/shovel.xcf
Binary file not shown.
5 changes: 4 additions & 1 deletion fabric/src/main/java/de/griefed/addemall/AddEmAllFabric.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package de.griefed.addemall;

import de.griefed.addemall.block.GeneratedModBlocks;
import de.griefed.addemall.client.BlockToolHud;
import de.griefed.addemall.client.BlockToolHudOverlay;
import de.griefed.addemall.event.FabricKeyInputHandler;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
Expand All @@ -30,5 +32,6 @@ public void onInitialize() {
FabricKeyInputHandler.register();

ItemTooltipCallback.EVENT.register(CommonClass::onItemTooltip);
HudRenderCallback.EVENT.register(new BlockToolHudOverlay());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.griefed.addemall.client;

import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.Minecraft;

public class BlockToolHudOverlay extends BlockToolHud implements HudRenderCallback {
@Override
public void onHudRender(PoseStack matrixStack, float tickDelta) {
int x, y;
Minecraft instance = Minecraft.getInstance();
int width = instance.getWindow().getGuiScaledWidth();
int height = instance.getWindow().getGuiScaledHeight();

x = width / 2;
y = height;

renderToolSettings(matrixStack, x, y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class FabricKeyInputHandler {
public static void registerKeyInputs() {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (toolBehaviourKey.consumeClick()) {
KeyInputHandler.TOOL_BEHAVIOUR = !KeyInputHandler.TOOL_BEHAVIOUR;
KeyInputHandler.BLOCKTOOL_MULTI_ACTIVE = !KeyInputHandler.BLOCKTOOL_MULTI_ACTIVE;
}
if (toolShovelHoeKey.consumeClick()) {
KeyInputHandler.TOOL_SHOVEL_HOE = !KeyInputHandler.TOOL_SHOVEL_HOE;
KeyInputHandler.BLOCKTOOL_SHOVELMODE = !KeyInputHandler.BLOCKTOOL_SHOVELMODE;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.griefed.addemall.client;

import net.minecraftforge.client.event.RegisterGuiOverlaysEvent;
import net.minecraftforge.client.gui.overlay.IGuiOverlay;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class BlockToolHudOverlay extends BlockToolHud {
public static final IGuiOverlay TOOL_SETTINGS = ((gui, poseStack, partialTick, width, height) -> {
int x = width / 2;
renderToolSettings(poseStack, x, height);
});

@SubscribeEvent
public static void registerGuiOverlays(RegisterGuiOverlaysEvent event) {
event.registerAboveAll("tool.settings", BlockToolHudOverlay.TOOL_SETTINGS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public static class ClientForgeEvents {
@SubscribeEvent
public static void onKeyInput(InputEvent.Key event) {
if (KeyInputHandler.toolBehaviourKey.consumeClick()) {
KeyInputHandler.TOOL_BEHAVIOUR = !KeyInputHandler.TOOL_BEHAVIOUR;
KeyInputHandler.BLOCKTOOL_MULTI_ACTIVE = !KeyInputHandler.BLOCKTOOL_MULTI_ACTIVE;
}
if (KeyInputHandler.toolShovelHoeKey.consumeClick()) {
KeyInputHandler.TOOL_SHOVEL_HOE = !KeyInputHandler.TOOL_SHOVEL_HOE;
KeyInputHandler.BLOCKTOOL_SHOVELMODE = !KeyInputHandler.BLOCKTOOL_SHOVELMODE;
}
}
}
Expand Down

0 comments on commit 5c2b8fd

Please sign in to comment.