Skip to content

Commit

Permalink
Some UI testing and basic item implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fureniku committed Feb 11, 2024
1 parent a2c8522 commit c03f4d2
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/main/java/com/fureniku/metropolis/RegistrationBase.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,13 +16,17 @@
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;
import net.minecraftforge.eventbus.api.IEventBus;
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -153,6 +165,16 @@ public RegistryObject<Block> retrieveRegisterBlockSet(String name, Supplier<Bloc
return block;
}

public String registerItem(String name, Supplier<Item> itemClass) {
retrieveRegisterItem(name, itemClass);
return name;
}

public RegistryObject<Item> retrieveRegisterItem(String name, Supplier<Item> itemClass) {
RegistryObject<Item> item = itemRegistry.register(name, itemClass);
return item;
}

public <T extends MetroBlockEntity> RegistryObject<BlockEntityType<T>> registerBlockEntity(String name, BlockEntityType.BlockEntitySupplier<T> blockEntity, Block... validBlocks) {
return blockEntityRegistry.register(name, () -> BlockEntityType.Builder.of(blockEntity, validBlocks).build(null));
}
Expand Down Expand Up @@ -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<Block> value) {
block_map.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/fureniku/metropolis/items/MetroItemBase.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/fureniku/metropolis/items/MetroItemSimple.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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", () ->
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "metropolis:item/test_basic_item"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c03f4d2

Please sign in to comment.