From c03f4d214635d557270503ff7dafa758ee716200 Mon Sep 17 00:00:00 2001 From: Fureniku Date: Sun, 11 Feb 2024 13:16:52 +0000 Subject: [PATCH] Some UI testing and basic item implementation --- .../fureniku/metropolis/RegistrationBase.java | 34 ++++++++++++++++-- .../client/screens/UIRenderHandler.java | 32 +++++++++++++++++ .../metropolis/items/MetroItemBase.java | 10 ++++++ .../metropolis/items/MetroItemSimple.java | 12 +++++++ .../metropolis/items/MetroItemToolBase.java | 8 +++++ .../metropolis/test/RegistrationTest.java | 5 +++ .../models/item/test_basic_item.json | 6 ++++ .../textures/item/test_basic_item.png | Bin 0 -> 391 bytes 8 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/fureniku/metropolis/client/screens/UIRenderHandler.java create mode 100644 src/main/java/com/fureniku/metropolis/items/MetroItemBase.java create mode 100644 src/main/java/com/fureniku/metropolis/items/MetroItemSimple.java create mode 100644 src/main/java/com/fureniku/metropolis/items/MetroItemToolBase.java create mode 100644 src/main/resources/assets/metropolis/models/item/test_basic_item.json create mode 100644 src/main/resources/assets/metropolis/textures/item/test_basic_item.png diff --git a/src/main/java/com/fureniku/metropolis/RegistrationBase.java b/src/main/java/com/fureniku/metropolis/RegistrationBase.java index 54b85c0..e66de46 100644 --- a/src/main/java/com/fureniku/metropolis/RegistrationBase.java +++ b/src/main/java/com/fureniku/metropolis/RegistrationBase.java @@ -1,9 +1,13 @@ package com.fureniku.metropolis; import com.fureniku.metropolis.blockentity.MetroBlockEntity; +import com.fureniku.metropolis.client.screens.UIRenderHandler; import com.fureniku.metropolis.menus.MetroMenu; import com.fureniku.metropolis.utils.CreativeTabSet; import com.fureniku.metropolis.utils.Debug; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GameRenderer; import net.minecraft.core.registries.Registries; import net.minecraft.data.DataGenerator; import net.minecraft.data.PackOutput; @@ -12,6 +16,9 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.client.event.ModelEvent; +import net.minecraftforge.client.event.RegisterGuiOverlaysEvent; +import net.minecraftforge.client.gui.overlay.IGuiOverlay; +import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.data.event.GatherDataEvent; import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; @@ -19,6 +26,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.loading.FMLEnvironment; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; @@ -64,9 +72,13 @@ public RegistrationBase(String modid, IEventBus modEventBus) { modEventBus.addListener(this::client); modEventBus.addListener(this::buildCreativeTabs); //These need to be client only. Unused for now so disabled //todo - //modEventBus.addListener(this::modelInit); - //modEventBus.addListener(this::modelBakeComplete); - //modEventBus.addListener(this::modifyBake); + if (FMLEnvironment.dist.isClient()) { + //modEventBus.addListener(this::modelInit); + //modEventBus.addListener(this::modelBakeComplete); + //modEventBus.addListener(this::modifyBake); + modEventBus.addListener(this::guiOverlay); + } + modEventBus.addListener(this::generate); blockRegistry.register(modEventBus); itemRegistry.register(modEventBus); @@ -153,6 +165,16 @@ public RegistryObject retrieveRegisterBlockSet(String name, Supplier itemClass) { + retrieveRegisterItem(name, itemClass); + return name; + } + + public RegistryObject retrieveRegisterItem(String name, Supplier itemClass) { + RegistryObject item = itemRegistry.register(name, itemClass); + return item; + } + public RegistryObject> registerBlockEntity(String name, BlockEntityType.BlockEntitySupplier blockEntity, Block... validBlocks) { return blockEntityRegistry.register(name, () -> BlockEntityType.Builder.of(blockEntity, validBlocks).build(null)); } @@ -303,6 +325,12 @@ protected void modelBakeComplete(ModelEvent.BakingCompleted event) { bakingComplete(event); }*/ + @SubscribeEvent + protected void guiOverlay(RegisterGuiOverlaysEvent event) { + event.registerAboveAll("test_ui_class", UIRenderHandler::new); + } + + //Add a block to the registry private void addBlock(String key, RegistryObject value) { block_map.put(key, value); diff --git a/src/main/java/com/fureniku/metropolis/client/screens/UIRenderHandler.java b/src/main/java/com/fureniku/metropolis/client/screens/UIRenderHandler.java new file mode 100644 index 0000000..1570e46 --- /dev/null +++ b/src/main/java/com/fureniku/metropolis/client/screens/UIRenderHandler.java @@ -0,0 +1,32 @@ +package com.fureniku.metropolis.client.screens; + +import com.fureniku.metropolis.utils.Debug; +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraftforge.client.gui.overlay.ForgeGui; +import net.minecraftforge.client.gui.overlay.IGuiOverlay; + +public class UIRenderHandler implements IGuiOverlay { + + public UIRenderHandler(ForgeGui forgeGui, GuiGraphics guiGraphics, float v, int i, int i1) { + render(forgeGui, guiGraphics, v, i, i1); + } + + @Override + public void render(ForgeGui gui, GuiGraphics guiGraphics, float partialTick, int screenWidth, int screenHeight) { + RenderSystem.setShader(GameRenderer::getPositionColorShader); + + // Maybe this draw a rectangle on the screen. + // First, second, third and fourth arguments may set a position. + // Fifth argument may set color. + guiGraphics.fill(100, 120, 140, 160, 0xFFFFFF); + + // This draw text on the screen. The method have no problem. + // Third and fourth arguments set a position. + // Fifth argument sets text color. + // Sixth argument sets shadow. + guiGraphics.drawString(Minecraft.getInstance().font, "test", 100, 140, 0xFFFFFF, true); + } +} diff --git a/src/main/java/com/fureniku/metropolis/items/MetroItemBase.java b/src/main/java/com/fureniku/metropolis/items/MetroItemBase.java new file mode 100644 index 0000000..b4b9af0 --- /dev/null +++ b/src/main/java/com/fureniku/metropolis/items/MetroItemBase.java @@ -0,0 +1,10 @@ +package com.fureniku.metropolis.items; + +import net.minecraft.world.item.Item; + +public class MetroItemBase extends Item { + + public MetroItemBase(Properties props) { + super(props); + } +} diff --git a/src/main/java/com/fureniku/metropolis/items/MetroItemSimple.java b/src/main/java/com/fureniku/metropolis/items/MetroItemSimple.java new file mode 100644 index 0000000..027d5cc --- /dev/null +++ b/src/main/java/com/fureniku/metropolis/items/MetroItemSimple.java @@ -0,0 +1,12 @@ +package com.fureniku.metropolis.items; + +public class MetroItemSimple extends MetroItemBase { + + public MetroItemSimple() { + this(64); + } + + public MetroItemSimple(int stackSize) { + super(new Properties().stacksTo(stackSize)); + } +} diff --git a/src/main/java/com/fureniku/metropolis/items/MetroItemToolBase.java b/src/main/java/com/fureniku/metropolis/items/MetroItemToolBase.java new file mode 100644 index 0000000..4dd157e --- /dev/null +++ b/src/main/java/com/fureniku/metropolis/items/MetroItemToolBase.java @@ -0,0 +1,8 @@ +package com.fureniku.metropolis.items; + +public class MetroItemToolBase extends MetroItemBase { + + public MetroItemToolBase(int durability) { + super(new Properties().stacksTo(1).fireResistant().defaultDurability(durability)); + } +} diff --git a/src/main/java/com/fureniku/metropolis/test/RegistrationTest.java b/src/main/java/com/fureniku/metropolis/test/RegistrationTest.java index 0da890d..37311e0 100644 --- a/src/main/java/com/fureniku/metropolis/test/RegistrationTest.java +++ b/src/main/java/com/fureniku/metropolis/test/RegistrationTest.java @@ -8,6 +8,7 @@ import com.fureniku.metropolis.blocks.decorative.helpers.ConnectHorizontalHelper; import com.fureniku.metropolis.datagen.MetroBlockStateProvider; import com.fureniku.metropolis.enums.BlockConnectionType; +import com.fureniku.metropolis.items.MetroItemSimple; import com.fureniku.metropolis.utils.CreativeTabSet; import com.fureniku.metropolis.utils.ShapeUtils; import net.minecraft.data.DataGenerator; @@ -162,6 +163,8 @@ public void init(IEventBus modEventBus) { .setConnectHorizontalHelper(BlockConnectionType.ALL, shapes) .build())); + registerItem("test_basic_item", MetroItemSimple::new); + /* TODO update to new registration for block entities with buildAs() blockNames.add("test_block_entity_decorative"); TEST_BLOCK_ENTITY_DECORATIVE_ENTITY = registerBlockEntityWithBlock("test_block_entity_decorative", () -> @@ -180,6 +183,8 @@ public void generateCreativeTabs() { for (int i = 0; i < blockNames.size(); i++) { _testTab.addItem(getItem(blockNames.get(i)).get().getDefaultInstance()); } + + //_testTab.addItem(getItem("test_basic_item").get().getDefaultInstance()); } @Override diff --git a/src/main/resources/assets/metropolis/models/item/test_basic_item.json b/src/main/resources/assets/metropolis/models/item/test_basic_item.json new file mode 100644 index 0000000..45586cd --- /dev/null +++ b/src/main/resources/assets/metropolis/models/item/test_basic_item.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "metropolis:item/test_basic_item" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/metropolis/textures/item/test_basic_item.png b/src/main/resources/assets/metropolis/textures/item/test_basic_item.png new file mode 100644 index 0000000000000000000000000000000000000000..bd366229abdcf5ddaf6529c9f5151f7cad20cfc4 GIT binary patch literal 391 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%Lhh0G|-oU)8MtyIKCWviz=L{Zh{Qubt&b73-gR*1ydx->X>vwy^x`VENa{ z^0k8X{{*%_4Xl5gSY8#f{qJGx%-m_ob|#%URzPvEIvK`%udIwwU#Q zKdXEimp#xH&H|6fVg?4j10c+pb*+;VD7ekj#W6%9nD;Da(qRJ*){FUyn@=p8;IYMT z^1c7FzA`@J-C+94nmZ)tfrTO8=k?b@Tdg}eA26PGpM2q8h-AX^M#cxjtrD+<80h)3@HILR;3{v}2pM zr1Vbv?Uo69OK0*-@BDe3QO>loDE*CscZTcK+G~m;6)Sy=yBDRuovwGs=g`C}=5}2i jS*MMjzsX;(7WhAO7T1lk-h>*U4;VaM{an^LB{Ts5D@mbP literal 0 HcmV?d00001