diff --git a/common/src/main/java/de/griefed/addemall/CommonClass.java b/common/src/main/java/de/griefed/addemall/CommonClass.java index d05a92e..cb26f5d 100644 --- a/common/src/main/java/de/griefed/addemall/CommonClass.java +++ b/common/src/main/java/de/griefed/addemall/CommonClass.java @@ -48,6 +48,7 @@ public static void init() { ModItems.loadClass(); KeyInputHandler.loadClass(); + } public static void onItemTooltip(ItemStack stack, TooltipFlag context, List tooltip) { diff --git a/common/src/main/java/de/griefed/addemall/client/BlockToolHud.java b/common/src/main/java/de/griefed/addemall/client/BlockToolHud.java new file mode 100644 index 0000000..eba1eaa --- /dev/null +++ b/common/src/main/java/de/griefed/addemall/client/BlockToolHud.java @@ -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); + }*/ + } + } +} diff --git a/common/src/main/java/de/griefed/addemall/event/KeyInputHandler.java b/common/src/main/java/de/griefed/addemall/event/KeyInputHandler.java index e85b230..7b559cd 100644 --- a/common/src/main/java/de/griefed/addemall/event/KeyInputHandler.java +++ b/common/src/main/java/de/griefed/addemall/event/KeyInputHandler.java @@ -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 { @@ -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() {} } diff --git a/common/src/main/java/de/griefed/addemall/item/BlockToolItem.java b/common/src/main/java/de/griefed/addemall/item/BlockToolItem.java index b46779b..b6a7d37 100644 --- a/common/src/main/java/de/griefed/addemall/item/BlockToolItem.java +++ b/common/src/main/java/de/griefed/addemall/item/BlockToolItem.java @@ -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 strippedState = getStripped(blockState); Optional previousState = WeatheringCopper.getPrevious(blockState); @@ -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; diff --git a/common/src/main/resources/assets/addemall/textures/item/bar.png b/common/src/main/resources/assets/addemall/textures/item/bar.png new file mode 100644 index 0000000..bfdd3df Binary files /dev/null and b/common/src/main/resources/assets/addemall/textures/item/bar.png differ diff --git a/common/src/main/resources/assets/addemall/textures/item/hoe.png b/common/src/main/resources/assets/addemall/textures/item/hoe.png new file mode 100644 index 0000000..072fb5e Binary files /dev/null and b/common/src/main/resources/assets/addemall/textures/item/hoe.png differ diff --git a/common/src/main/resources/assets/addemall/textures/item/multi.png b/common/src/main/resources/assets/addemall/textures/item/multi.png new file mode 100644 index 0000000..af8b25f Binary files /dev/null and b/common/src/main/resources/assets/addemall/textures/item/multi.png differ diff --git a/common/src/main/resources/assets/addemall/textures/item/multi_deactivated.png b/common/src/main/resources/assets/addemall/textures/item/multi_deactivated.png new file mode 100644 index 0000000..68608f2 Binary files /dev/null and b/common/src/main/resources/assets/addemall/textures/item/multi_deactivated.png differ diff --git a/common/src/main/resources/assets/addemall/textures/item/shovel.png b/common/src/main/resources/assets/addemall/textures/item/shovel.png new file mode 100644 index 0000000..4e665c9 Binary files /dev/null and b/common/src/main/resources/assets/addemall/textures/item/shovel.png differ diff --git a/definitions/bb projects/Block Tool/bar.png b/definitions/bb projects/Block Tool/bar.png new file mode 100644 index 0000000..bfdd3df Binary files /dev/null and b/definitions/bb projects/Block Tool/bar.png differ diff --git a/definitions/bb projects/Block Tool/bar.xcf b/definitions/bb projects/Block Tool/bar.xcf new file mode 100644 index 0000000..f0e4e6d Binary files /dev/null and b/definitions/bb projects/Block Tool/bar.xcf differ diff --git a/definitions/bb projects/Block Tool/hoe.png b/definitions/bb projects/Block Tool/hoe.png new file mode 100644 index 0000000..072fb5e Binary files /dev/null and b/definitions/bb projects/Block Tool/hoe.png differ diff --git a/definitions/bb projects/Block Tool/hoe.xcf b/definitions/bb projects/Block Tool/hoe.xcf new file mode 100644 index 0000000..57bc439 Binary files /dev/null and b/definitions/bb projects/Block Tool/hoe.xcf differ diff --git a/definitions/bb projects/Block Tool/multi.png b/definitions/bb projects/Block Tool/multi.png new file mode 100644 index 0000000..af8b25f Binary files /dev/null and b/definitions/bb projects/Block Tool/multi.png differ diff --git a/definitions/bb projects/Block Tool/multi.xcf b/definitions/bb projects/Block Tool/multi.xcf new file mode 100644 index 0000000..2eca2e0 Binary files /dev/null and b/definitions/bb projects/Block Tool/multi.xcf differ diff --git a/definitions/bb projects/Block Tool/multi_deactivated.png b/definitions/bb projects/Block Tool/multi_deactivated.png new file mode 100644 index 0000000..68608f2 Binary files /dev/null and b/definitions/bb projects/Block Tool/multi_deactivated.png differ diff --git a/definitions/bb projects/Block Tool/shovel.png b/definitions/bb projects/Block Tool/shovel.png new file mode 100644 index 0000000..4e665c9 Binary files /dev/null and b/definitions/bb projects/Block Tool/shovel.png differ diff --git a/definitions/bb projects/Block Tool/shovel.xcf b/definitions/bb projects/Block Tool/shovel.xcf new file mode 100644 index 0000000..4032326 Binary files /dev/null and b/definitions/bb projects/Block Tool/shovel.xcf differ diff --git a/fabric/src/main/java/de/griefed/addemall/AddEmAllFabric.java b/fabric/src/main/java/de/griefed/addemall/AddEmAllFabric.java index 40a8948..df3b63b 100644 --- a/fabric/src/main/java/de/griefed/addemall/AddEmAllFabric.java +++ b/fabric/src/main/java/de/griefed/addemall/AddEmAllFabric.java @@ -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; @@ -30,5 +32,6 @@ public void onInitialize() { FabricKeyInputHandler.register(); ItemTooltipCallback.EVENT.register(CommonClass::onItemTooltip); + HudRenderCallback.EVENT.register(new BlockToolHudOverlay()); } } diff --git a/fabric/src/main/java/de/griefed/addemall/client/BlockToolHudOverlay.java b/fabric/src/main/java/de/griefed/addemall/client/BlockToolHudOverlay.java new file mode 100644 index 0000000..b1256fb --- /dev/null +++ b/fabric/src/main/java/de/griefed/addemall/client/BlockToolHudOverlay.java @@ -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); + } +} diff --git a/fabric/src/main/java/de/griefed/addemall/event/FabricKeyInputHandler.java b/fabric/src/main/java/de/griefed/addemall/event/FabricKeyInputHandler.java index dbf4a49..415b903 100644 --- a/fabric/src/main/java/de/griefed/addemall/event/FabricKeyInputHandler.java +++ b/fabric/src/main/java/de/griefed/addemall/event/FabricKeyInputHandler.java @@ -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; } }); } diff --git a/forge/src/main/java/de/griefed/addemall/client/BlockToolHudOverlay.java b/forge/src/main/java/de/griefed/addemall/client/BlockToolHudOverlay.java new file mode 100644 index 0000000..a33c94a --- /dev/null +++ b/forge/src/main/java/de/griefed/addemall/client/BlockToolHudOverlay.java @@ -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); + } +} diff --git a/forge/src/main/java/de/griefed/addemall/event/ForgeKeyInputHandler.java b/forge/src/main/java/de/griefed/addemall/event/ForgeKeyInputHandler.java index ffe3dff..b05707e 100644 --- a/forge/src/main/java/de/griefed/addemall/event/ForgeKeyInputHandler.java +++ b/forge/src/main/java/de/griefed/addemall/event/ForgeKeyInputHandler.java @@ -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; } } }