Client GUI test
This commit is contained in:
parent
714570c75f
commit
f7c54d756a
|
@ -21,6 +21,7 @@ public class CustomItem extends Item{
|
|||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
|
||||
playerEntity.openHandledScreen(null);
|
||||
playerEntity.playSound(SoundEvents.BLOCK_BELL_USE, 1.0F, 1.0F);
|
||||
return TypedActionResult.success(playerEntity.getStackInHand(hand));
|
||||
}
|
||||
|
|
|
@ -1,20 +1,28 @@
|
|||
package com.youpe.test;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.fabricmc.fabric.api.registry.FuelRegistry;
|
||||
import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Rarity;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
public class Testing implements ModInitializer {
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
|
@ -34,5 +42,22 @@ public class Testing implements ModInitializer {
|
|||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register(content -> {
|
||||
content.add(CUSTOM_ITEM);
|
||||
});
|
||||
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
|
||||
Matrix4f positionMatrix = drawContext.getMatrices().peek().getPositionMatrix();
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
|
||||
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE);
|
||||
buffer.vertex(positionMatrix, 20, 20, 0).color(1f, 1f, 1f, 1f).texture(0f, 0f).next();
|
||||
buffer.vertex(positionMatrix, 20, 60, 0).color(1f, 0f, 0f, 1f).texture(0f, 1f).next();
|
||||
buffer.vertex(positionMatrix, 60, 60, 0).color(0f, 1f, 0f, 1f).texture(1f, 1f).next();
|
||||
buffer.vertex(positionMatrix, 60, 20, 0).color(0f, 0f, 1f, 1f).texture(1f, 0f).next();
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorTexProgram);
|
||||
RenderSystem.setShaderTexture(0, new Identifier("testing", "icon.png"));
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
|
||||
|
||||
tessellator.draw();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.youpe.test;
|
||||
|
||||
import com.youpe.test.event.KeyInputHandler;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class TestingClient implements ClientModInitializer{
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
KeyInputHandler.register();
|
||||
KeyInputHandler.registerKeyInputs();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.youpe.test;
|
||||
|
||||
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
|
||||
|
||||
public class TestingDataGenerator implements DataGeneratorEntrypoint {
|
||||
@Override
|
||||
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.youpe.test.client;
|
||||
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.tooltip.Tooltip;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class GUI extends Screen {
|
||||
|
||||
public GUI(Text title) {
|
||||
super(title);
|
||||
}
|
||||
public ButtonWidget button1;
|
||||
public ButtonWidget button2;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
button1 = ButtonWidget.builder(Text.literal("Button 1"), button -> {
|
||||
System.out.println("You clicked button1!");
|
||||
})
|
||||
.dimensions(width / 2 - 205, 20, 200, 20)
|
||||
.tooltip(Tooltip.of(Text.literal("Tooltip of button1")))
|
||||
.build();
|
||||
button2 = ButtonWidget.builder(Text.literal("Button 2"), button -> {
|
||||
System.out.println("You clicked button2!");
|
||||
})
|
||||
.dimensions(width / 2 + 5, 20, 200, 20)
|
||||
.tooltip(Tooltip.of(Text.literal("Tooltip of button2")))
|
||||
.build();
|
||||
|
||||
addDrawableChild(button1);
|
||||
addDrawableChild(button2);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.youpe.test.event;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.youpe.test.client.GUI;
|
||||
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class KeyInputHandler {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("testing");
|
||||
public static final String KEY_CATEGORY_TESTING = "key.category.testing.tutorial";
|
||||
public static final String KEY_TEST = "key.testing.test";
|
||||
|
||||
public static KeyBinding modkey;
|
||||
|
||||
public static void registerKeyInputs() {
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (modkey.wasPressed()) {
|
||||
LOGGER.info("NAZHAL PIZDEC BLYA");
|
||||
client.player.sendMessage(Text.literal("PIZDEC"));
|
||||
MinecraftClient.getInstance().setScreen(new GUI(Text.empty()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
modkey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
KEY_TEST,
|
||||
InputUtil.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_B,
|
||||
KEY_CATEGORY_TESTING));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.youpe.test.mixin;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "loadWorld")
|
||||
private void init(CallbackInfo info) {
|
||||
// This code is injected into the start of MinecraftServer.loadWorld()V
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"item.testing.custom_item": "Pizdec",
|
||||
"item.testing.custom_item.tooltip": "hahaha"
|
||||
"item.testing.custom_item.tooltip": "hahaha",
|
||||
"key.category.testing.tutorial": "Testing",
|
||||
"key.testing.test": "Test"
|
||||
}
|
|
@ -18,6 +18,9 @@
|
|||
"main": [
|
||||
"com.youpe.test.Testing"
|
||||
],
|
||||
"client": [
|
||||
"com.youpe.test.TestingClient"
|
||||
],
|
||||
"fabric-datagen": [
|
||||
"com.youpe.test.TestingDataGenerator"
|
||||
]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"required": true,
|
||||
"required": false,
|
||||
"package": "com.youpe.test.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
|
|
Loading…
Reference in New Issue