Skip to content

Commit

Permalink
Some work on screens
Browse files Browse the repository at this point in the history
  • Loading branch information
Fureniku committed Feb 3, 2024
1 parent feb8fa7 commit a2c8522
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 21 deletions.
17 changes: 9 additions & 8 deletions src/main/java/com/fureniku/metropolis/RegistrationBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ public RegistrationBase(String modid, IEventBus modEventBus) {
modEventBus.addListener(this::common);
modEventBus.addListener(this::client);
modEventBus.addListener(this::buildCreativeTabs);
modEventBus.addListener(this::modelInit);
modEventBus.addListener(this::modelBakeComplete);
modEventBus.addListener(this::modifyBake);
//These need to be client only. Unused for now so disabled //todo
//modEventBus.addListener(this::modelInit);
//modEventBus.addListener(this::modelBakeComplete);
//modEventBus.addListener(this::modifyBake);
modEventBus.addListener(this::generate);
blockRegistry.register(modEventBus);
itemRegistry.register(modEventBus);
Expand Down Expand Up @@ -217,9 +218,9 @@ public void buildCreativeTabs(BuildCreativeModeTabContentsEvent event) {
* Model setup event. Register model overrides etc here. (Client only)
* @param event ModelEvent.RegisterGeometryLoaders
*/
protected abstract void modelSetup(ModelEvent.RegisterGeometryLoaders event);
protected abstract void modifyBakingResult(ModelEvent.ModifyBakingResult event);
protected abstract void bakingComplete(ModelEvent.BakingCompleted event);
//protected abstract void modelSetup(ModelEvent.RegisterGeometryLoaders event);
//protected abstract void modifyBakingResult(ModelEvent.ModifyBakingResult event);
//protected abstract void bakingComplete(ModelEvent.BakingCompleted event);

/**
* Data generation event. Register data generations here.
Expand Down Expand Up @@ -284,7 +285,7 @@ protected void client(final FMLClientSetupEvent event) {
}

//Call anything we want on the model setup then offer it to end mods
@SubscribeEvent
/*@SubscribeEvent
protected void modelInit(ModelEvent.RegisterGeometryLoaders event) {
Debug.Log("EVENT CALL: Register Geometry Loaders");
modelSetup(event);
Expand All @@ -300,7 +301,7 @@ protected void modifyBake(ModelEvent.ModifyBakingResult event) {
protected void modelBakeComplete(ModelEvent.BakingCompleted event) {
Debug.Log("EVENT CALL: Baking completed");
bakingComplete(event);
}
}*/

//Add a block to the registry
private void addBlock(String key, RegistryObject<Block> value) {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/fureniku/metropolis/blocks/BlockSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraftforge.client.event.RegisterColorHandlersEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.registries.RegistryObject;

import java.util.function.BiFunction;
Expand Down Expand Up @@ -77,10 +78,12 @@ private void init(RegistrationBase register) {
* @return An instance of BlockSet for method chaining.
*/
public BlockSet addColorTints(IEventBus modEventBus, BiFunction<BlockAndTintGetter, BlockPos, Integer> blockColor, Supplier<Integer> itemColor) {
modEventBus.addListener(this::registerBlockColors);
modEventBus.addListener(this::registerItemColors);
tintColorBlock = blockColor;
tintColorItem = itemColor;
if (FMLEnvironment.dist.isClient()) {
modEventBus.addListener(this::registerBlockColors);
modEventBus.addListener(this::registerItemColors);
tintColorBlock = blockColor;
tintColorItem = itemColor;
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.fureniku.metropolis.client.screens;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;

public abstract class MetroScreenContainerBase<T extends AbstractContainerMenu> extends AbstractContainerScreen<T> {

private final ScreenImage _background;

public MetroScreenContainerBase(T menu, Inventory inventory, Component component, ScreenImage background) {
super(menu, inventory, component);
_background = background;
this.imageWidth = background.getWidth();
this.imageHeight = background.getHeight();
}

protected abstract ResourceLocation getBackground();

@Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
this.renderBackground(graphics);
super.render(graphics, mouseX, mouseY, partialTick);
this.renderTooltip(graphics, mouseX, mouseY);
}

@Override
protected void renderBg(GuiGraphics graphics, float partialTick, int mouseX, int mouseY) {
RenderSystem.setShaderTexture(0, getBackground());
graphics.blit(_background.getResourceLocation(), this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight);
}

@Override
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
super.renderLabels(graphics, mouseX, mouseY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.fureniku.metropolis.client.screens;

import net.minecraft.resources.ResourceLocation;

public class ScreenImage {

private ResourceLocation _resourceLocation;
private int _startLeft;
private int _startTop;
private int _width;
private int _height;

public ScreenImage(ResourceLocation loc, int startLeft, int startTop, int width, int height) {
_resourceLocation = loc;
_startLeft = startLeft;
_startTop = startTop;
_width = width;
_height = height;
}

public ResourceLocation getResourceLocation() {
return _resourceLocation;
}

public int getStartLeft() {
return _startLeft;
}

public int getStartTop() {
return _startTop;
}

public int getWidth() {
return _width;
}

public int getHeight() {
return _height;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,6 @@ protected void commonSetup(FMLCommonSetupEvent event) {}
@Override
protected void clientSetup(FMLClientSetupEvent event) {}

@Override
protected void modelSetup(ModelEvent.RegisterGeometryLoaders event) {}

@Override
protected void modifyBakingResult(ModelEvent.ModifyBakingResult event) {}

@Override
protected void bakingComplete(ModelEvent.BakingCompleted event) {}

@Override
protected void dataGen(GatherDataEvent event, DataGenerator gen, PackOutput packOutput, ExistingFileHelper efh) {
gen.addProvider(event.includeClient(), new MetroBlockStateProvider(packOutput, Metropolis.MODID, efh, Metropolis.INSTANCE.registrationTest));
Expand Down

0 comments on commit a2c8522

Please sign in to comment.