Merge remote-tracking branch 'origin/zoomerio_dev'

This commit is contained in:
Eugene Rybalkin 2024-04-13 18:20:10 +03:00
commit 6b2af0560a
10 changed files with 101 additions and 47 deletions

View File

@ -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.event.player.PlayerBlockBreakEvents;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
@ -25,47 +28,17 @@ import com.youpe.test.server.PlayerData;
import com.youpe.test.server.StateSaverAndLoader;
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);
public static final Identifier DIRT_BROKEN = new Identifier("testing", "dirt_broken");
@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);
});
PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, entity) -> {
if (state.getBlock() == Blocks.GRASS_BLOCK || state.getBlock() == Blocks.DIRT) {
StateSaverAndLoader serverState = StateSaverAndLoader.getServerState(world.getServer());
// Increment the amount of dirt blocks that have been broken
serverState.totalDirtBlocksBroken += 1;
ModItems.registerModItems();
PlayerData playerState = StateSaverAndLoader.getPlayerState(player);
playerState.dirtBlocksBroken += 1;
// Send a packet to the client
MinecraftServer server = world.getServer();
PacketByteBuf data = PacketByteBufs.create();
data.writeInt(serverState.totalDirtBlocksBroken);
data.writeInt(playerState.dirtBlocksBroken);
ServerPlayerEntity playerEntity = server.getPlayerManager().getPlayer(player.getUuid());
server.execute(() -> {
ServerPlayNetworking.send(playerEntity, DIRT_BROKEN, data);
});
}
});
}
}

View File

@ -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;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.text.Text;
@ -22,6 +23,7 @@ public class TestingClient implements ClientModInitializer{
client.player.sendMessage(Text.literal("Player specific dirt blocks broken: " + playerSpecificDirtBlocksBroken));
});
});
TestHudRender.registerModRenders();
}
}

View File

@ -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()));
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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"
}

View File

@ -1,6 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "testing:item/custom_item"
"layer0": "testing:item/custom_item_example"
}
}

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -3,7 +3,6 @@
"package": "com.youpe.test.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ExampleMixin"
],
"injectors": {
"defaultRequire": 1