Jump to content

[1.19.2] Gui won't display properly


Recommended Posts

Hello i added a new Block with its own Menu and screen. In the tutorial everything displays propely, but on my end its stretched and only the half of the texture is shown. I havent worked with the rendering system until now, so here's my code. Maybe you guys have an idea what im doing wrong

package net.internalerror.futuristicfactories.gui.screen;

import net.internalerror.futuristicfactories.block.entity.CrushingMachineBlockEntity;
import net.internalerror.futuristicfactories.data.recipe.CrushingRecipe;
import net.internalerror.futuristicfactories.gui.menu.CrushingMachineMenu;
import net.internalerror.futuristicfactories.gui.screen.util.FFMachineScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;

import static net.internalerror.futuristicfactories.FuturisticFactories.MOD_ID;

public class CrushingMachineScreen extends FFMachineScreen<CrushingRecipe, CrushingMachineBlockEntity, CrushingMachineMenu> {
    public CrushingMachineScreen(CrushingMachineMenu menu, Inventory playerInventory, Component title) {
        super(menu, playerInventory, title);
    }

    @Override
    public int getImageWidth() {
        return 176;
    }

    @Override
    public int getImageHeight() {
        return 168;
    }

    @Override
    public ResourceLocation getTexture() {
        return new ResourceLocation(MOD_ID, "textures/gui/crushing_machine.png");
    }
}
package net.internalerror.futuristicfactories.gui.screen.util;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.internalerror.futuristicfactories.block.entity.util.FFSimpleMachineBlockEntity;
import net.internalerror.futuristicfactories.data.recipe.FFSimpleRecipe;
import net.internalerror.futuristicfactories.gui.menu.util.FFMachineMenu;
import net.internalerror.futuristicfactories.gui.screen.area.EnergyInfoArea;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public abstract class FFMachineScreen<R extends FFSimpleRecipe, E extends FFSimpleMachineBlockEntity<R>, M extends FFMachineMenu<R, E>> extends AbstractContainerScreen<M> {

    private EnergyInfoArea energyInfoArea;

    public FFMachineScreen(M menu, Inventory playerInventory, Component title) {
        super(menu, playerInventory, title);
        imageWidth = getImageWidth();
        imageHeight = getImageHeight();
    }

    @Override
    protected void init() {
        super.init();
        assignEnergyInfoArea();
    }

    public abstract int getImageWidth();

    public abstract int getImageHeight();

    private void assignEnergyInfoArea() {

        int x = (width - imageWidth) / 2;
        int y = (height - imageHeight) / 2;

        energyInfoArea = new EnergyInfoArea(x + 152, y + 19, menu.getBlockEntity().getEnergyStorage());
    }

    @Override
    protected void renderLabels(@NotNull PoseStack poseStack, int mouseX, int mouseY) {
        int x = (width - imageWidth) / 2;
        int y = (height - imageHeight) / 2;
        renderEnergyAreaTooltips(poseStack, mouseX, mouseY, x, y);
    }

    private void renderEnergyAreaTooltips(PoseStack poseStack, int mouseX, int mouseY, int x, int y) {
        if (isMouseAboveArea(mouseX, mouseY, x, y, 152, 19, 16, 52)) {
            renderTooltip(poseStack, energyInfoArea.getTooltips(), Optional.empty(), mouseX - x, mouseY - y);
        }
    }

    private boolean isMouseAboveArea(int mouseX, int mouseY, int x, int y, int offsetX, int offsetY, int width, int height) {
        return FFMouseUtil.isMouseOver(mouseX, mouseY, x + offsetX, y + offsetY, width, height);
    }

    public abstract ResourceLocation getTexture();

    @Override
    protected void renderBg(@NotNull PoseStack poseStack, float partialTick, int pmousex, int mouseY) {
        RenderSystem.setShader(GameRenderer::getPositionTexShader);
        RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
        RenderSystem.setShaderTexture(0, getTexture());
        int x = (width - imageWidth) / 2;
        int y = (height - imageHeight) / 2;

        blit(poseStack, x, y, 0, 0, imageWidth, imageHeight);
        renderProgressArrow(poseStack, x, y);

        energyInfoArea.draw(poseStack);

    }

    private void renderProgressArrow(PoseStack poseStack, int x, int y) {
        if (menu.isCrafting()) {
            blit(poseStack, x + 77, y + 37, 176, 0, menu.getScaledProgress(), 16);
        }

    }
}
package net.internalerror.futuristicfactories.gui.menu.util;

import net.internalerror.futuristicfactories.FuturisticFactories;
import net.internalerror.futuristicfactories.block.entity.util.FFSimpleMachineBlockEntity;
import net.internalerror.futuristicfactories.data.recipe.FFSimpleRecipe;
import net.internalerror.futuristicfactories.registries.FFBlocks;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;


public abstract class FFMachineMenu<R extends FFSimpleRecipe, E extends FFSimpleMachineBlockEntity<R>> extends AbstractContainerMenu {

    protected final E blockEntity;
    protected final Level level;
    protected final ContainerData data;

    public FFMachineMenu(MenuType<?> menuType, int id, Inventory inventory, FriendlyByteBuf friendlyByteBuf) {
        this(menuType, id, inventory, inventory.player.level.getBlockEntity(friendlyByteBuf.readBlockPos()), new SimpleContainerData(2));
    }

    public FFMachineMenu(MenuType<?> menuType, int id, Inventory inventory, BlockEntity blockEntity, ContainerData simpleContainerData) {
        super(menuType, id);
        checkContainerSize(inventory, castBlockEntity(blockEntity).getSlotCount());
        this.blockEntity = castBlockEntity(blockEntity);
        this.level = inventory.player.level;
        this.data = simpleContainerData;
        addPlayerInventory(inventory);
        addPlayerHotbar(inventory);
        addSlots(blockEntity.getCapability(ForgeCapabilities.ITEM_HANDLER));
    }

    public E getBlockEntity() {
        return blockEntity;
    }

    protected abstract <T extends IItemHandler> void addSlots(LazyOptional<T> capability);

    protected void addPlayerInventory(Inventory playerInventory) {
        for (int i = 0; i < 3; i++) {
            for (int l = 0; l < 9; l++) {
                addSlot(new Slot(playerInventory, l + i * 9 + 9, 8 + l * 18, 108 + i * 18));
            }
        }
    }

    protected void addPlayerHotbar(Inventory playerInventory) {
        for (int i = 0; i < 9; i++) {
            addSlot(new Slot(playerInventory, i, 8 + i * 18, 166));
        }
    }

    protected abstract E castBlockEntity(BlockEntity blockEntity);

    private static final int hotbar_slot_count = 9;
    private static final int player_inventor_row_count = 3;
    private static final int player_inventory_column_count = 9;
    private static final int player_inventory_slot_count = player_inventory_column_count * player_inventor_row_count;
    private static final int vanilla_slot_count = hotbar_slot_count + player_inventory_slot_count;
    private static final int vanilla_first_slot_index = 0;
    private static final int te_inventory_first_slot_index = vanilla_first_slot_index + vanilla_slot_count;
    private static final int te_inventory_slot_count = 3;

    @Override
    public @NotNull ItemStack quickMoveStack(@NotNull Player player, int index) {
        Slot sourceSlot = slots.get(index);
        if (!sourceSlot.hasItem()) {
            return ItemStack.EMPTY;
        }
        ItemStack sourceStack = sourceSlot.getItem();
        ItemStack copyOfSourceStack = sourceStack.copy();
        if (index < vanilla_first_slot_index + vanilla_slot_count) {
            if (!moveItemStackTo(sourceStack, te_inventory_first_slot_index, te_inventory_first_slot_index + te_inventory_slot_count, false)) {
                return ItemStack.EMPTY;
            }
        } else if (index < te_inventory_first_slot_index + te_inventory_slot_count) {
            if (!moveItemStackTo(sourceStack, vanilla_first_slot_index, vanilla_first_slot_index + vanilla_slot_count, false)) {
                return ItemStack.EMPTY;
            }
        } else {
            FuturisticFactories.LOGGER.error("Invalid slot index: {}", index);
            return ItemStack.EMPTY;
        }
        if (sourceStack.getCount() == 0) {
            sourceSlot.set(ItemStack.EMPTY);
        } else {
            sourceSlot.setChanged();
        }
        sourceSlot.onTake(player, sourceStack);
        return copyOfSourceStack;
    }

    @Override
    public boolean stillValid(@NotNull Player player) {
        return stillValid(ContainerLevelAccess.create(level, blockEntity.getBlockPos()), player, FFBlocks.crushing_machine.get());
    }

    public abstract boolean isCrafting();

    public abstract int getScaledProgress();
}
package net.internalerror.futuristicfactories.gui.menu;

import net.internalerror.futuristicfactories.block.entity.CrushingMachineBlockEntity;
import net.internalerror.futuristicfactories.data.recipe.CrushingRecipe;
import net.internalerror.futuristicfactories.gui.menu.util.FFMachineMenu;
import net.internalerror.futuristicfactories.registries.FFMenuTypes;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class CrushingMachineMenu extends FFMachineMenu<CrushingRecipe, CrushingMachineBlockEntity> {

    public CrushingMachineMenu(int id, Inventory inventory, CrushingMachineBlockEntity blockEntity, ContainerData data) {
        super(FFMenuTypes.crushing_machine.get(), id, inventory, blockEntity, data);
    }

    public CrushingMachineMenu(int id, Inventory inventory, FriendlyByteBuf extraData) {
        super(FFMenuTypes.crushing_machine.get(), id, inventory, extraData);
    }

    @Override
    protected <T extends IItemHandler> void addSlots(LazyOptional<T> capability) {

        capability.ifPresent(handler -> {
            addSlot(new SlotItemHandler(handler, CrushingMachineBlockEntity.Slot_Index_Wip_Upgrade, 8, 19));
            addSlot(new SlotItemHandler(handler, CrushingMachineBlockEntity.Slot_Index_Speed_Upgrade, 8, 37));
            addSlot(new SlotItemHandler(handler, CrushingMachineBlockEntity.Slot_Index_Energy_Upgrade, 8, 55));

            addSlot(new SlotItemHandler(handler, CrushingMachineBlockEntity.Slot_Index_Ingredient, 44, 37));
            addSlot(new SlotItemHandler(handler, CrushingMachineBlockEntity.Slot_Index_Result, 107, 37));
            addSlot(new SlotItemHandler(handler, CrushingMachineBlockEntity.Slot_Index_Secondary_Result, 125, 37));
        });

    }

    @Override
    protected CrushingMachineBlockEntity castBlockEntity(BlockEntity blockEntity) {
        return (CrushingMachineBlockEntity) blockEntity;
    }

    @Override
    public boolean isCrafting() {
        return data.get(CrushingMachineBlockEntity.Data_Index_Progress) > 0;
    }

    @Override
    public int getScaledProgress() {
        int progress = data.get(CrushingMachineBlockEntity.Data_Index_Progress);
        int maxProgress = data.get(CrushingMachineBlockEntity.Data_Index_Max_Progress);
        int progressArrowSize = 22;

        return maxProgress != 0 && progress != 0 ? progress * progressArrowSize / maxProgress : 0;
    }
}
Link to comment
Share on other sites

1 hour ago, InternalError_ said:

In the tutorial everything displays propely, but on my end its stretched and only the half of the texture is shown.

How big is your texture and the image inside the texture file? Also, a lot of what's here seems inherently bad, but it shouldn't cause a major issue at a quick glance.

Link to comment
Share on other sites

21 minutes ago, ChampionAsh5357 said:

How big is your texture and the image inside the texture file? Also, a lot of what's here seems inherently bad, but it shouldn't cause a major issue at a quick glance.

Texture is a little more wide than the default inventory texture.
I cant post images here, but this would be the image https://github.com/InternalErrorGit/FuturisticFactories/blob/master/src/main/resources/assets/futuristicfactories/textures/gui/crushing_machine.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Me and my friend started a server using Better Minecraft and added about 10 mods on top of it. Everything works fine until we hover over any armor item in the game. Doesnt matter what mod its from it just crashes. We can hover over armor in JEI but it just gives us a tooltip error. Here is my crash message after hovering over armor The game crashed whilst rendering screen Error: java.lang.NullPointerException: Registry Object not present: feathers:lightweight Here is my Crash Report https://pastebin.com/FWQ7n3HS
    • I am unable to resolve my current issue, I have successfully downloaded the forge extension. I downloaded the correct Java link with Javafix included. I log into the game and it shows the "forge" launcher active menu. I double checked to make sure it was the right release number of minecraft and it matched the forge download as well, this also including the most recent forge client. The issue is when I go into a new minecraft server it doesn't allow me to do //wand. No matter what I try the same issue is following me, it almost seems as if the client is fully active but something isn't allowing it to run on my computer. I would appreciate some assistance regarding my problem.   Thank you
    • Came here for the same reason. But for me it's the client. After following your instructions with the jar, I ended up with the following error. I assume to have chosen the right jar   -jar "${lminecraft_library_path}/net/minecraftforge/forge/1.20.4-49.0.3/forge-1.20.4-49.0.3-shim.jar"   Minecraft 1.20.4 Forge: 1.20.4 - 49.0.3   ;--- cut here --- [7.633s][info][class,load] cpw.mods.jarhandling.SecureJar$ModuleDataProvider source: file:/home/habibiboy/.minecraft/libraries/net/minecraftforge/securemodules/2.2.7/securemodules-2.2.7.jar [7.636s][info][class,load] java.security.CodeSigner source: jrt:/java.base [7.636s][info][class,load] java.nio.file.spi.FileSystemProvider$1 source: jrt:/java.base [7.637s][info][class,load] java.util.ServiceLoader source: shared objects file [7.639s][info][class,load] java.util.ServiceLoader$ModuleServicesLookupIterator source: shared objects file [7.639s][info][class,load] java.util.Spliterators$ArraySpliterator source: shared objects file [7.640s][info][class,load] java.util.Spliterators$1Adapter source: shared objects file [7.643s][info][class,load] java.util.Arrays$ArrayList source: shared objects file [7.648s][info][class,load] java.util.concurrent.CopyOnWriteArrayList$COWIterator source: shared objects file [7.649s][info][class,load] java.util.ServiceLoader$LazyClassPathLookupIterator source: shared objects file [7.649s][info][class,load] java.util.ServiceLoader$2 source: shared objects file [7.649s][info][class,load] java.util.ServiceLoader$3 source: shared objects file [7.652s][info][class,load] jdk.internal.module.ModulePatcher$PatchedModuleReader source: jrt:/java.base [7.654s][info][class,load] sun.net.www.protocol.jrt.Handler source: jrt:/java.base [7.663s][info][class,load] jdk.nio.zipfs.ZipFileSystemProvider source: jrt:/jdk.zipfs [7.667s][info][class,load] java.nio.file.FileSystemNotFoundException source: jrt:/java.base [7.672s][info][class,load] jdk.nio.zipfs.ZipFileSystem source: jrt:/jdk.zipfs [7.675s][info][class,load] java.lang.UnsupportedOperationException source: jrt:/java.base [7.676s][info][class,load] java.util.zip.ZipException source: jrt:/java.base [7.677s][info][class,load] java.nio.file.ProviderMismatchException source: jrt:/java.base [7.680s][info][class,load] java.nio.file.AccessMode source: jrt:/java.base [7.681s][info][class,load] java.nio.file.DirectoryStream$Filter source: jrt:/java.base [7.683s][info][class,load] java.nio.file.DirectoryStream source: jrt:/java.base [7.684s][info][class,load] java.nio.file.FileStore source: jrt:/java.base [7.688s][info][class,load] java.util.concurrent.Executor source: shared objects file [7.688s][info][class,load] java.util.concurrent.ExecutorService source: shared objects file [7.690s][info][class,load] java.nio.channels.AsynchronousChannel source: jrt:/java.base [7.690s][info][class,load] java.nio.channels.AsynchronousFileChannel source: jrt:/java.base [7.691s][info][class,load] java.util.ServiceLoader$1 source: shared objects file [7.692s][info][class,load] java.util.ServiceLoader$Provider source: shared objects file [7.692s][info][class,load] java.util.ServiceLoader$ProviderImpl source: shared objects file [7.693s][info][class,load] jdk.internal.reflect.DirectConstructorHandleAccessor source: shared objects file [7.695s][info][class,load] jdk.internal.jrtfs.JrtFileSystemProvider source: jrt:/java.base [7.699s][info][class,load] java.util.Collections$EmptyEnumeration source: shared objects file [7.699s][info][class,load] jdk.internal.loader.BuiltinClassLoader$1 source: shared objects file [7.700s][info][class,load] java.lang.CompoundEnumeration source: shared objects file [7.701s][info][class,load] jdk.internal.loader.URLClassPath$1 source: shared objects file [7.702s][info][class,load] sun.net.www.protocol.jrt.JavaRuntimeURLConnection source: jrt:/java.base [7.710s][info][class,load] sun.net.www.protocol.jrt.JavaRuntimeURLConnection$$Lambda/0x00007f5d70055728 source: sun.net.www.protocol.jrt.JavaRuntimeURLConnection [7.719s][info][class,load] sun.net.www.protocol.jrt.JavaRuntimeURLConnection$1 source: jrt:/java.base [7.720s][info][class,load] jdk.internal.jimage.ImageBufferCache source: jrt:/java.base [7.722s][info][class,load] jdk.internal.jimage.ImageBufferCache$1 source: jrt:/java.base [7.723s][info][class,load] jdk.internal.jimage.ImageBufferCache$2 source: jrt:/java.base [7.724s][info][class,load] java.util.AbstractMap$SimpleEntry source: jrt:/java.base [7.727s][info][class,load] java.util.LinkedHashMap$LinkedKeySet source: jrt:/java.base [7.731s][info][class,load] java.util.LinkedHashMap$LinkedHashIterator source: shared objects file [7.731s][info][class,load] java.util.LinkedHashMap$LinkedKeyIterator source: jrt:/java.base [7.732s][info][class,load] java.util.Collections$UnmodifiableList source: shared objects file [7.732s][info][class,load] java.util.Collections$UnmodifiableRandomAccessList source: shared objects file [7.736s][info][class,load] java.lang.invoke.LambdaForm$DMH/0x00007f5d7000c400 source: __JVM_LookupDefineClass__ [7.741s][info][class,load] cpw.mods.jarhandling.impl.Jar$$Lambda/0x00007f5d7000adb0 source: cpw.mods.jarhandling.impl.Jar [7.746s][info][class,load] cpw.mods.jarhandling.impl.Jar$$Lambda/0x00007f5d7000aff8 source: cpw.mods.jarhandling.impl.Jar [7.748s][info][class,load] java.lang.ExceptionInInitializerError source: jrt:/java.base [7.749s][info][class,load] java.lang.StackTraceElement$HashedModules source: jrt:/java.base [7.751s][info][class,load] java.lang.invoke.WrongMethodTypeException source: jrt:/java.base [7.751s][info][class,load] java.lang.reflect.InvocationTargetException source: jrt:/java.base Exception in thread "main" [7.758s][info][class,load] java.lang.Throwable$PrintStreamOrWriter source: jrt:/java.base [7.759s][info][class,load] java.lang.Throwable$WrappedPrintStream source: jrt:/java.base java.lang.reflect.InvocationTargetException     at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)     at java.base/java.lang.reflect.Method.invoke(Method.java:580)     at net.minecraftforge.bootstrap.shim.Main.main(Main.java:94) Caused by: java.lang.ExceptionInInitializerError     at cpw.mods.jarhandling.SecureJar.from(SecureJar.java:64)     at cpw.mods.jarhandling.SecureJar.from(SecureJar.java:60)     at net.minecraftforge.bootstrap.ClassPathHelper.getCleanedClassPathImpl(ClassPathHelper.java:178)     at net.minecraftforge.bootstrap.ClassPathHelper.getCleanedClassPath(ClassPathHelper.java:46)     at net.minecraftforge.bootstrap.Bootstrap.start(Bootstrap.java:28)     at net.minecraftforge.bootstrap.ForgeBootstrap.main(ForgeBootstrap.java:18)     at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)     ... 2 more Caused by: java.lang.IllegalStateException: Couldn't find UnionFileSystemProvider     at cpw.mods.jarhandling.impl.Jar.lambda$static$1(Jar.java:48)     at java.base/java.util.Optional.orElseThrow(Optional.java:403)     at cpw.mods.jarhandling.impl.Jar.<clinit>(Jar.java:48)     ... 9 more [7.783s][info][class,load] java.util.IdentityHashMap$IdentityHashMapIterator source: shared objects file [7.784s][info][class,load] java.util.IdentityHashMap$KeyIterator source: shared objects file [7.787s][info][class,load] java.lang.Shutdown source: shared objects file [7.789s][info][class,load] java.lang.Shutdown$Lock source: shared objects file ;--- cut here ---   I tried various things here. Java 17, then Java 21, Searched for missing objects, used strace -ff java ... and so on. The securejar class is there, accessible, permissions all fine. Still running into this issue.
    • sorry for the late answer, I tried it but i hadthe same result crash reportlog
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.