Skip to content

Commit

Permalink
feat: change how nutrient cost is visualized
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Nov 8, 2024
1 parent 5ae1bcb commit 66d7a34
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.client.gui.components.Renderable;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -202,7 +203,9 @@ private void renderRecipeResult(GuiGraphics guiGraphics) {
ItemStack stack = selectedRecipe.getResultItem(minecraft.level.registryAccess());
int x = leftPos + 194 + 2;
int y = topPos + 33 + 2;
GuiRenderUtil.drawGhostItem(guiGraphics, x, y, stack);
guiGraphics.fill(x, y, x + 16, y + 16, 0x30_ff0000);
guiGraphics.renderFakeItem(stack, x, y);
guiGraphics.fill(RenderType.guiGhostRecipeOverlay(), x, y, x + 16, y + 16, 0x30_ffffff);
guiGraphics.renderItemDecorations(font, stack, x, y);
}
}
Expand Down Expand Up @@ -276,12 +279,13 @@ private void renderFuelBar(GuiGraphics guiGraphics) {

BioForgingRecipe selectedRecipe = recipeBook.getSelectedRecipe();
int cost = selectedRecipe != null ? selectedRecipe.getCraftingCostNutrients() : 0;
if (cost <= 0) return;
if (cost <= menu.getFuelAmount()) return;

int x = leftPos + 144;
int y = topPos + 13 + 36 - ((int) ((cost / (float) menu.getMaxFuelAmount()) * 36) + 1);
guiGraphics.fill(x - 3, y, x + 5 + 3, y + 1, 0xff_ffffff);
guiGraphics.drawString(font, "" + cost, x + 5 + 3 + 2, y - font.lineHeight / 2, cost <= menu.getFuelAmount() ? ColorStyles.TEXT_SUCCESS : ColorStyles.TEXT_ERROR);
guiGraphics.fill(x - 3, y, x + 5 + 3, y + 1, 0x30_ff0000);
guiGraphics.fill(x + 5 + 3, y, x + 5 + 3 + 1, y + 1, 0xff_ff0000);
guiGraphics.fill(x + 5 + 3 + 1, y - 1, x + 5 + 3 + 2, y + 2, 0xff_ff0000);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.github.elenterius.biomancy.client.util.GuiRenderUtil;
import com.github.elenterius.biomancy.client.util.GuiUtil;
import com.github.elenterius.biomancy.menu.BioLabMenu;
import com.github.elenterius.biomancy.styles.ColorStyles;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -71,12 +70,13 @@ private void drawFuelBar(GuiGraphics guiGraphics, float fuelPct) {
guiGraphics.blit(BACKGROUND_TEXTURE, leftPos + 36, topPos + 48 + 36 - vHeight, 178, 58 - vHeight, 5, vHeight);

int cost = menu.getFuelCost();
if (cost <= 0) return;
if (cost <= menu.getFuelAmount()) return;

int x = leftPos + 36;
int y = topPos + 48 + 36 - ((int) ((cost / (float) menu.getMaxFuelAmount()) * 36) + 1);
guiGraphics.fill(x - 3, y, x + 5 + 3, y + 1, 0xff_ffffff);
guiGraphics.drawString(font, "" + cost, x + 5 + 3 + 2, y - font.lineHeight / 2, cost <= menu.getFuelAmount() ? ColorStyles.TEXT_SUCCESS : ColorStyles.TEXT_ERROR);
guiGraphics.fill(x - 3, y, x + 5 + 3, y + 1, 0x30_ff0000);
guiGraphics.fill(x + 5 + 3, y, x + 5 + 3 + 1, y + 1, 0xff_ff0000);
guiGraphics.fill(x + 5 + 3 + 1, y - 1, x + 5 + 3 + 2, y + 2, 0xff_ff0000);
}

private void drawLock(GuiGraphics guiGraphics, boolean isLocked) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.github.elenterius.biomancy.client.util.GuiRenderUtil;
import com.github.elenterius.biomancy.client.util.GuiUtil;
import com.github.elenterius.biomancy.menu.DecomposerMenu;
import com.github.elenterius.biomancy.styles.ColorStyles;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -56,12 +55,13 @@ private void drawFuelBar(GuiGraphics guiGraphics, float fuelPct) {
guiGraphics.blit(BACKGROUND_TEXTURE, leftPos + 44, topPos + 26 + 36 - vHeight, 178, 36 - vHeight, 5, vHeight);

int cost = menu.getFuelCost();
if (cost <= 0) return;
if (cost <= menu.getFuelAmount()) return;

int x = leftPos + 44;
int y = topPos + 26 + 36 - ((int) ((cost / (float) menu.getMaxFuelAmount()) * 36) + 1);
guiGraphics.fill(x - 3, y, x + 5 + 3, y + 1, 0xff_ffffff);
guiGraphics.drawString(font, "" + cost, x + 5 + 3 + 2, y - font.lineHeight / 2, cost <= menu.getFuelAmount() ? ColorStyles.TEXT_SUCCESS : ColorStyles.TEXT_ERROR);
guiGraphics.fill(x - 3, y, x + 5 + 3, y + 1, 0x30_ff0000);
guiGraphics.fill(x + 5 + 3, y, x + 5 + 3 + 1, y + 1, 0xff_ff0000);
guiGraphics.fill(x + 5 + 3 + 1, y - 1, x + 5 + 3 + 2, y + 2, 0xff_ff0000);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.github.elenterius.biomancy.client.util.GuiRenderUtil;
import com.github.elenterius.biomancy.client.util.GuiUtil;
import com.github.elenterius.biomancy.menu.DigesterMenu;
import com.github.elenterius.biomancy.styles.ColorStyles;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -56,12 +55,13 @@ private void drawFuelBar(GuiGraphics guiGraphics, float fuelPct) {
guiGraphics.blit(BACKGROUND_TEXTURE, leftPos + 44, topPos + 28 + 36 - vHeight, 178, 36 - vHeight, 5, vHeight);

int cost = menu.getFuelCost();
if (cost <= 0) return;
if (cost <= menu.getFuelAmount()) return;

int x = leftPos + 44;
int y = topPos + 28 + 36 - ((int) ((cost / (float) menu.getMaxFuelAmount()) * 36) + 1);
guiGraphics.fill(x - 3, y, x + 5 + 3, y + 1, 0xff_ffffff);
guiGraphics.drawString(font, "" + cost, x + 5 + 3 + 2, y - font.lineHeight / 2, cost <= menu.getFuelAmount() ? ColorStyles.TEXT_SUCCESS : ColorStyles.TEXT_ERROR);
guiGraphics.fill(x - 3, y, x + 5 + 3, y + 1, 0x30_ff0000);
guiGraphics.fill(x + 5 + 3, y, x + 5 + 3 + 1, y + 1, 0xff_ff0000);
guiGraphics.fill(x + 5 + 3 + 1, y - 1, x + 5 + 3 + 2, y + 2, 0xff_ff0000);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.joml.Matrix4f;
import org.lwjgl.opengl.GL11;

import java.text.DecimalFormat;
import java.util.ArrayList;
Expand All @@ -37,13 +35,6 @@ public static void drawFuelTooltip(Font font, GuiGraphics guiGraphics, int mouse
guiGraphics.renderComponentTooltip(font, hoveringText, mouseX, mouseY);
}

public static void drawGhostItem(GuiGraphics guiGraphics, int pX, int pY, ItemStack stack) {
guiGraphics.renderFakeItem(stack, pX, pY);
RenderSystem.depthFunc(GL11.GL_GREATER); //passes if the fragment's depth value is greater than the stored depth value
guiGraphics.fill(pX, pY, pX + 16, pY + 16, 0x30_ff_ff_ff);
RenderSystem.depthFunc(GL11.GL_LEQUAL); //passes if the fragment's depth value is equal to the stored depth value
}

public static void drawAttackIndicator(GuiGraphics guiGraphics, int x, int y, float pct) {
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE_MINUS_DST_COLOR, GlStateManager.DestFactor.ONE_MINUS_SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
guiGraphics.blit(GUI_ICONS_TEXTURE, x, y, 36, 94, 16, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerListener;
import net.minecraft.world.inventory.ResultContainer;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -46,6 +48,24 @@ protected BioForgeMenu(int id, Inventory playerInventory, @Nullable BioForgeBloc
addSlot(new CustomResultSlot(playerInventory.player, resultContainer, 0, 194 + 2, 33 + 2));

addDataSlots(bioforge.getStateData());

addSlotListener(new ContainerListener() {
@Override
public void slotChanged(AbstractContainerMenu container, int slot, ItemStack stack) {}

int fuel = 0;

@Override
public void dataChanged(AbstractContainerMenu container, int index, int value) {
if (index == BioForgeStateData.FUEL_INDEX && playerInventory.player instanceof ServerPlayer serverPlayer) {
BioForgingRecipe recipe = getSelectedRecipe();
if (recipe != null && recipe.getCraftingCostNutrients() > fuel && recipe.getCraftingCostNutrients() <= value) {
updateResultSlot(serverPlayer);
}
fuel = value;
}
}
});
}
}

Expand All @@ -70,14 +90,14 @@ protected void onPlayerMainInventoryChanged(Inventory inventory) {
private void trackPlayerInvChanges(ServerPlayer serverPlayer, Inventory inventory) {
if (playerInvChanges != inventory.getTimesChanged()) {
countPlayerInvItems(serverPlayer, inventory);
updateResultSlot(serverPlayer);
playerInvChanges = inventory.getTimesChanged();
}
}

private void countPlayerInvItems(ServerPlayer serverPlayer, Inventory inventory) {
itemCounter.clear();
itemCounter.accountStacks(inventory.items);
updateResultSlot(serverPlayer);
}

private void updateResultSlot(ServerPlayer serverPlayer) {
Expand All @@ -102,6 +122,7 @@ public BioForgingRecipe getSelectedRecipe() {
public void setSelectedRecipe(@Nullable BioForgingRecipe recipe, ServerPlayer serverPlayer) {
selectedRecipe = recipe;
countPlayerInvItems(serverPlayer, serverPlayer.getInventory());
updateResultSlot(serverPlayer);
}

@Override
Expand Down

0 comments on commit 66d7a34

Please sign in to comment.