Some testing refactoring
This commit is contained in:
parent
f7c54d756a
commit
78800a3c07
|
@ -1,5 +1,8 @@
|
|||
package com.youpe.test;
|
||||
|
||||
import com.youpe.test.event.TestHudRender;
|
||||
import com.youpe.test.item.ModItems;
|
||||
import com.youpe.test.item.custom.CustomItem;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
|
@ -24,40 +27,15 @@ 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.
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("testing");
|
||||
public static final Item CUSTOM_ITEM = new CustomItem(new FabricItemSettings().rarity(Rarity.COMMON));
|
||||
|
||||
public static final String MOD_ID = "testing";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
Registry.register(Registries.ITEM, new Identifier("testing", "custom_item"), CUSTOM_ITEM);
|
||||
FuelRegistry.INSTANCE.add(CUSTOM_ITEM, 30000);
|
||||
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();
|
||||
});
|
||||
ModItems.registerModItems();
|
||||
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.youpe.test;
|
|||
|
||||
import com.youpe.test.event.KeyInputHandler;
|
||||
|
||||
import com.youpe.test.event.TestHudRender;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class TestingClient implements ClientModInitializer{
|
||||
|
@ -10,6 +11,7 @@ public class TestingClient implements ClientModInitializer{
|
|||
public void onInitializeClient() {
|
||||
KeyInputHandler.register();
|
||||
KeyInputHandler.registerKeyInputs();
|
||||
TestHudRender.registerModRenders();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.youpe.test.event;
|
||||
|
||||
import com.youpe.test.Testing;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -14,7 +15,7 @@ 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";
|
||||
|
||||
|
@ -23,7 +24,7 @@ public class KeyInputHandler {
|
|||
public static void registerKeyInputs() {
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (modkey.wasPressed()) {
|
||||
LOGGER.info("NAZHAL PIZDEC BLYA");
|
||||
Testing.LOGGER.info("NAZHAL PIZDEC BLYA");
|
||||
client.player.sendMessage(Text.literal("PIZDEC"));
|
||||
MinecraftClient.getInstance().setScreen(new GUI(Text.empty()));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.youpe.test.event;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.youpe.test.Testing;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
public class TestHudRender {
|
||||
|
||||
private static void addTestRendering(DrawContext drawContext, float 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();
|
||||
}
|
||||
|
||||
|
||||
public static void registerModRenders(){
|
||||
Testing.LOGGER.info("Registering ModRenders for " + Testing.MOD_ID);
|
||||
HudRenderCallback.EVENT.register(TestHudRender::addTestRendering);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.youpe.test.item;
|
||||
|
||||
import com.youpe.test.Testing;
|
||||
import com.youpe.test.item.custom.CustomItem;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroupEntries;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroups;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Rarity;
|
||||
|
||||
public class ModItems {
|
||||
|
||||
// Items list
|
||||
public static final Item CUSTOM_ITEM_EXAMPLE = registerItem("custom_item_example",
|
||||
new CustomItem(new FabricItemSettings().rarity(Rarity.EPIC)));
|
||||
|
||||
// Adding to specific ItemGroup (using ItemGroupsEvents)
|
||||
public static void addItemsToBuildingBlocks(FabricItemGroupEntries entries){
|
||||
entries.add(CUSTOM_ITEM_EXAMPLE);
|
||||
}
|
||||
|
||||
// Register item via Registry
|
||||
private static Item registerItem(String name, Item item){
|
||||
return Registry.register(Registries.ITEM, new Identifier(Testing.MOD_ID, name), item);
|
||||
}
|
||||
|
||||
// Using in class which implementing ModInitializer
|
||||
public static void registerModItems(){
|
||||
Testing.LOGGER.info("Registering Mod Items for " + Testing.MOD_ID);
|
||||
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register(ModItems::addItemsToBuildingBlocks);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.youpe.test;
|
||||
package com.youpe.test.item.custom;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -6,6 +6,8 @@ import net.minecraft.client.item.TooltipContext;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
@ -21,16 +23,18 @@ 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);
|
||||
if (world.isClient) {return super.use(world, playerEntity, hand);}
|
||||
|
||||
world.playSound(null, playerEntity.getBlockPos(), SoundEvents.BLOCK_BELL_USE, SoundCategory.PLAYERS, 1.0F, 1.0F);
|
||||
// playerEntity.playSound(SoundEvents.BLOCK_BELL_USE, 1.0F, 1.0F);
|
||||
return TypedActionResult.success(playerEntity.getStackInHand(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {
|
||||
// default white text
|
||||
tooltip.add(Text.translatable("item.testing.custom_item.tooltip"));
|
||||
tooltip.add(Text.translatable("item.testing.custom_item_example.tooltip"));
|
||||
// formatted red text
|
||||
tooltip.add(Text.translatable("item.testing.custom_item.tooltip").formatted(Formatting.RED));
|
||||
tooltip.add(Text.translatable("item.testing.custom_item_example.tooltip").formatted(Formatting.DARK_RED));
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"item.testing.custom_item": "Pizdec",
|
||||
"item.testing.custom_item.tooltip": "hahaha",
|
||||
"item.testing.custom_item_example": "Pizdec",
|
||||
"item.testing.custom_item_example.tooltip": "hahaha",
|
||||
"key.category.testing.tutorial": "Testing",
|
||||
"key.testing.test": "Test"
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "testing:item/custom_item"
|
||||
"layer0": "testing:item/custom_item_example"
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
@ -3,7 +3,6 @@
|
|||
"package": "com.youpe.test.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"ExampleMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in New Issue