Posted February 1, 20232 yr 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; } }
February 1, 20232 yr 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.
February 1, 20232 yr Author 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
February 1, 20232 yr You need to make the texture file size, not the gui inside the texture, 256x256 as that is what the blit method assumes the file size is. You can accomplish this by adding nothing in the associated space.
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.