Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes and IC Workbench UI cleanup #1846

Merged
merged 5 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions core/src/main/java/mrtjp/projectred/core/Configurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import codechicken.lib.config.ConfigFile;

import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

import static mrtjp.projectred.core.ProjectRedCore.MOD_ID;

Expand All @@ -27,19 +29,21 @@ public class Configurator {
public static boolean fabulousLights = true;

/* World Gen */
public static String rubyOreKey = "ruby_ore";
public static String sapphireOreKey = "sapphire_ore";
public static String peridotOreKey = "peridot_ore";
public static String tinOreKey = "tin_ore";
public static String silverOreKey = "silver_ore";
public static String electrotineOreKey = "electrotine_ore";
public static String marbleCaveKey = "marble_cave";
public static boolean gen_MarbleCave = true;
public static boolean gen_Ruby = true;
public static int gen_RubyVeinSize = 8;
public static boolean gen_Sapphire = true;
public static int gen_SapphireVeinSize = 8;
public static boolean gen_Peridot = true;
public static int gen_PeridotVeinSize = 10;
public static boolean gen_Tin = true;
public static int gen_TinVeinSize = 8;
public static boolean gen_Silver = true;
public static int gen_SilverVeinSize = 9;
public static boolean gen_Electrotine = true;
public static int gen_ElectrotineVeinSize = 8;
public static Map<String, Boolean> worldFeatures = new HashMap<>();

/* Compatibility */
public static boolean compat_CCBundledCable = true;
Expand All @@ -54,6 +58,12 @@ public static void load() {
config.save();
}

private static boolean loadAndStoreFeature(ConfigCategory gen, String key, boolean def) {
boolean value = gen.getValue(key).setDefaultBoolean(def).getBoolean();
worldFeatures.put(key, value);
return value;
}

private static void loadValues(ConfigCategory config) {

//TODO remove later
Expand All @@ -77,19 +87,13 @@ private static void loadValues(ConfigCategory config) {
fabulousLights = rendering.getValue("fabulous_lights").setDefaultBoolean(fabulousLights).setComment("Use fabulous shader pipeline for lights when on Fabulous Graphics mode").getBoolean();

ConfigCategory gen = config.getCategory("world_gen").setComment("World gen settings");
gen_Ruby = gen.getValue("ruby_ore").setDefaultBoolean(gen_Ruby).setComment("Enable Ruby Ore generation").getBoolean();
gen_RubyVeinSize = gen.getValue("ruby_ore_vein_size").setDefaultInt(gen_RubyVeinSize).setComment("Ruby Ore vein size").getInt();
gen_Sapphire = gen.getValue("sapphire_ore").setDefaultBoolean(gen_Sapphire).setComment("Enable Sapphire Ore generation").getBoolean();
gen_SapphireVeinSize = gen.getValue("sapphire_ore_vein_size").setDefaultInt(gen_SapphireVeinSize).setComment("Sapphire Ore vein size").getInt();
gen_Peridot = gen.getValue("peridot_ore").setDefaultBoolean(gen_Peridot).setComment("Enable Peridot Ore generation").getBoolean();
gen_PeridotVeinSize = gen.getValue("peridot_ore_vein_size").setDefaultInt(gen_PeridotVeinSize).setComment("Peridot Ore vein size").getInt();
gen_Tin = gen.getValue("tin_ore").setDefaultBoolean(gen_Tin).setComment("Enable Tin Ore generation").getBoolean();
gen_TinVeinSize = gen.getValue("tin_ore_vein_size").setDefaultInt(gen_TinVeinSize).setComment("Tin Ore vein size").getInt();
gen_Silver = gen.getValue("silver_ore").setDefaultBoolean(gen_Silver).setComment("Enable Silver Ore generation").getBoolean();
gen_SilverVeinSize = gen.getValue("silver_ore_vein_size").setDefaultInt(gen_SilverVeinSize).setComment("Silver Ore vein size").getInt();
gen_Electrotine = gen.getValue("electrotine_ore").setDefaultBoolean(gen_Electrotine).setComment("Enable Electrotine Ore generation").getBoolean();
gen_ElectrotineVeinSize = gen.getValue("electrotine_ore_vein_size").setDefaultInt(gen_ElectrotineVeinSize).setComment("Electrotine Ore vein size").getInt();
gen_MarbleCave = gen.getValue("marble_cave").setDefaultBoolean(gen_MarbleCave).setComment("Enable Marble Cave generation").getBoolean();
gen_Ruby = loadAndStoreFeature(gen, rubyOreKey, true);
gen_Sapphire = loadAndStoreFeature(gen, sapphireOreKey, true);
gen_Peridot = loadAndStoreFeature(gen, peridotOreKey, true);
gen_Tin = loadAndStoreFeature(gen, tinOreKey, true);
gen_Silver = loadAndStoreFeature(gen, silverOreKey, true);
gen_Electrotine = loadAndStoreFeature(gen, electrotineOreKey, true);
gen_MarbleCave = loadAndStoreFeature(gen, marbleCaveKey, true);

ConfigCategory compat = config.getCategory("compatibility").setComment("Control the loading of various compatibility hooks. These settings are ignored unless the Compatibility module is installed.");
compat_CCBundledCable = compat.getValue("computercraft").setDefaultBoolean(compat_CCBundledCable).setComment("This allows computers to connect to bundled cables with the RS API.").getBoolean();
Expand Down Expand Up @@ -123,17 +127,11 @@ private static void loadAndDeleteLegacyValues(ConfigCategory config) {

ConfigCategory gen = config.getCategory("World Gen");
gen_Ruby = gen.getValue("Ruby Ore").setDefaultBoolean(gen_Ruby).getBoolean();
gen_RubyVeinSize = gen.getValue("Ruby Ore vein size").setDefaultInt(gen_RubyVeinSize).getInt();
gen_Sapphire = gen.getValue("Sapphire Ore").setDefaultBoolean(gen_Sapphire).getBoolean();
gen_SapphireVeinSize = gen.getValue("Sapphire Ore vein size").setDefaultInt(gen_SapphireVeinSize).getInt();
gen_Peridot = gen.getValue("Peridot Ore").setDefaultBoolean(gen_Peridot).getBoolean();
gen_PeridotVeinSize = gen.getValue("Peridot Ore vein size").setDefaultInt(gen_PeridotVeinSize).getInt();
gen_Tin = gen.getValue("Tin Ore").setDefaultBoolean(gen_Tin).getBoolean();
gen_TinVeinSize = gen.getValue("Tin Ore vein size").setDefaultInt(gen_TinVeinSize).getInt();
gen_Silver = gen.getValue("Silver Ore").setDefaultBoolean(gen_Silver).getBoolean();
gen_SilverVeinSize = gen.getValue("Silver Ore vein size").setDefaultInt(gen_SilverVeinSize).getInt();
gen_Electrotine = gen.getValue("Electrotine Ore").setDefaultBoolean(gen_Electrotine).getBoolean();
gen_ElectrotineVeinSize = gen.getValue("Electrotine Ore vein size").setDefaultInt(gen_ElectrotineVeinSize).getInt();
gen_MarbleCave = gen.getValue("Marble Caves").setDefaultBoolean(gen_MarbleCave).getBoolean();

ConfigCategory compat = config.getCategory("Compatibility");
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/mrtjp/projectred/redui/ScrollBarNode.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package mrtjp.projectred.redui;

import codechicken.lib.colour.EnumColour;
import com.mojang.blaze3d.vertex.PoseStack;
import mrtjp.projectred.lib.Point;
import mrtjp.projectred.lib.Rect;
import mrtjp.projectred.lib.Size;
import net.minecraft.client.gui.GuiComponent;

public abstract class ScrollBarNode extends AbstractGuiNode {

Expand All @@ -28,7 +30,12 @@ public void setSliderSize(int w, int h) {
@Override
public void drawBack(PoseStack stack, Point mouse, float partialFrame) {

// Draw scroll bar background
// Draw semi-transparent grey background
int x = getFrame().x();
int y = getFrame().y();
GuiComponent.fillGradient(stack, x, y, x + getFrame().width(), y + getFrame().height(), EnumColour.BLACK.argb(127), EnumColour.BLACK.argb(127), 0);

// Draw slider rectangle
drawSlider(stack, sliderFrame);
}

Expand Down
39 changes: 39 additions & 0 deletions core/src/main/java/mrtjp/projectred/redui/SpriteButtonNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package mrtjp.projectred.redui;

import com.mojang.blaze3d.vertex.PoseStack;

import java.util.function.Supplier;

public class SpriteButtonNode extends AbstractButtonNode {

private RedUISprite sprite;
private Runnable clickReceiver = () -> { };
private Supplier<Boolean> isDisabledProvider = () -> false;

public SpriteButtonNode(RedUISprite sprite) {
this.sprite = sprite;
}

public void setClickReceiver(Runnable clickReceiver) {
this.clickReceiver = clickReceiver;
}

public void setIsDisabledProvider(Supplier<Boolean> isDisabledProvider) {
this.isDisabledProvider = isDisabledProvider;
}

@Override
protected boolean isButtonDisabled() {
return isDisabledProvider.get();
}

@Override
protected void onButtonClicked() {
clickReceiver.run();
}

@Override
protected void drawButtonBody(PoseStack stack, boolean mouseover) {
blitSpriteCentered(stack, sprite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void loadRecipe() {

public void loadOutput() {

result = craftFromStorage(true);
result = craftFromStorageOrMatrix(true);
}

public boolean hasRecipe() {
Expand All @@ -109,15 +109,14 @@ public int getMissingIngredientMask() {
public boolean onCraftedByPlayer(Player player, boolean leaveRemainingInGrid) {
if (recipe == null) return false;

CraftingResult result = craftFromStorage(false);
CraftingResult result = craftFromStorageOrMatrix(false);

if (!result.isCraftable()) {
return false;
}

// Re-obtain remaining items in case "setCraftingPlayer" changes remaining items
ForgeHooks.setCraftingPlayer(player);
// NonNullList<ItemStack> remainingStacks = player.level.getRecipeManager().getRemainingItemsFor(IRecipeType.CRAFTING, craftingInventory, player.level);
NonNullList<ItemStack> remainingStacks = recipe.getRemainingItems(craftingInventory); // Skip re-searching for recipe, should be ok
ForgeHooks.setCraftingPlayer(null);

Expand Down Expand Up @@ -155,7 +154,21 @@ public boolean onCraftedIntoStorage() {
return true;
}

private CraftingResult craftFromStorageOrMatrix(boolean simulate) {
CraftingResult result = craftFromStorage(simulate);
if (!result.isCraftable() && inputSource.canConsumeFromCraftingMatrix()) {
// TODO maybe merge the missingIngredientMasks of these two results?
result = craftFromSource(inputSource.getCraftingMatrix(), simulate);
}
// TODO Hybrid craft that consumes from both sources instead of one or the other?
return result;
}

private CraftingResult craftFromStorage(boolean simulate) {
return craftFromSource(inputSource.getStorage(), simulate);
}

private CraftingResult craftFromSource(Container source, boolean simulate) {

if (recipe == null) return CraftingResult.EMPTY;

Expand All @@ -164,9 +177,8 @@ private CraftingResult craftFromStorage(boolean simulate) {
ItemStack result = recipe.assemble(craftingInventory);
if (result.isEmpty()) return CraftingResult.EMPTY;

Container storage = inputSource.getStorage();
if (simulate) {
storage = copyInventory(storage);
source = copyInventory(source);
}

// Try to consume all ingredients
Expand All @@ -176,7 +188,7 @@ private CraftingResult craftFromStorage(boolean simulate) {
ItemStack previousInput = craftingInventory.getItem(slot);
if (previousInput.isEmpty()) continue;

boolean isPresent = consumeIngredient(storage, 0, input -> {
boolean isPresent = consumeIngredient(source, 0, input -> {
// Candidate ingredient must be same item
if (!input.sameItemStackIgnoreDurability(previousInput)) return false;

Expand All @@ -199,31 +211,9 @@ private CraftingResult craftFromStorage(boolean simulate) {
return CraftingResult.missingIngredients(missingIngredientMask);
}

return new CraftingResult(result, recipe.getRemainingItems(craftingInventory), 0, simulate ? storage : copyInventory(storage));
return new CraftingResult(result, recipe.getRemainingItems(craftingInventory), 0, simulate ? source : copyInventory(source));
}

// private boolean insertResultsIntoInventory(NonNullList inventory, boolean simulate) {
// if (result.outputStack.isEmpty() || result.missingIngredientMask != 0) {
// return false;
// }
//
// IInventory storage = copyInventory(result.remainingStorage);
//
// // Try to insert into remaining storage
// ItemStack output = outputStack.copy();
// InventoryLib.injectItemStack(storage, output, true);
// if (!output.isEmpty()) return false;
//
// // Try to insert remaining items
// for (ItemStack stack : remainingItems) {
// ItemStack remaining = stack.copy();
// InventoryLib.injectItemStack(storage, remaining, true);
// if (!remaining.isEmpty()) return false;
// }
//
// return true;
// }

private boolean consumeIngredient(Container storage, int startIndex, Predicate<ItemStack> matchFunc) {

int i = startIndex;
Expand All @@ -250,7 +240,7 @@ private static Container copyInventory(Container inventory) {
return copy;
}

private static class CraftingResult {
private static final class CraftingResult {

private static final CraftingResult EMPTY = new CraftingResult(ItemStack.EMPTY, NonNullList.create(), 0, null);

Expand Down Expand Up @@ -294,10 +284,6 @@ private boolean canFitResultsIntoStorage() {
return InventoryLib.injectAllItemStacks(storage, getCopyOfAllResults(), true);
}

public static CraftingResult empty() {
return EMPTY;
}

public static CraftingResult missingIngredients(int missingIngredientMask) {
return new CraftingResult(ItemStack.EMPTY, NonNullList.create(), missingIngredientMask, null);
}
Expand All @@ -309,6 +295,10 @@ public interface InventorySource {

Container getStorage();

default boolean canConsumeFromCraftingMatrix() {
return false;
}

Level getWorld(); // Required for recipe lookup
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -77,10 +78,9 @@ public void drawBack(PoseStack stack, Point mouse, float partialFrame) {
blit(stack, x, y, 0, 0, getFrame().width(), getFrame().height());

ProjectBenchTile tile = getMenu().getProjectBenchTile();
ItemStack plan = tile.getPlanInventory().getItem(0);
if (!plan.isEmpty() && tile.isPlanRecipe()) {
ItemStack[] inputs = RecipePlanItem.loadPlanInputs(plan);
int missingMask = getMenu().getProjectBenchTile().getCraftingHelper().getMissingIngredientMask();
if (tile.isPlanRecipe()) {
int missingMask = tile.getCraftingHelper().getMissingIngredientMask();
Container inputs = tile.getCraftingHelper().getCraftingInventory();
drawPlanIngredientsOverlay(stack, inputs, missingMask, x + 48, y + 18);
}
}
Expand All @@ -93,16 +93,16 @@ public void drawFront(PoseStack stack, Point mouse, float partialFrame) {
}
}

private void drawPlanIngredientsOverlay(PoseStack mStack, ItemStack[] ingredients, int missingMask, int xPos, int yPos) {
private void drawPlanIngredientsOverlay(PoseStack mStack, Container ingredients, int missingMask, int xPos, int yPos) {

for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
int drawPosX = xPos + (x * 18);
int drawPosY = yPos + (y * 18);

int index = (y * 3) + x;
ItemStack ingredient = ingredients[index];
int colour = (missingMask & 1 << index) != 0 ? EnumColour.RED.argb() : EnumColour.GRAY.argb();
ItemStack ingredient = ingredients.getItem(index);
int colour = (missingMask & 1 << index) != 0 ? EnumColour.RED.argb(0x77) : EnumColour.GRAY.argb(0x77);

if (!ingredient.isEmpty()) {
fillGradient(mStack, drawPosX, drawPosY, drawPosX + 16, drawPosY + 16, colour, colour);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public ItemStack quickMoveStack(Player player, int slotIndex) {
if (!moveToStorage(stack, true) && !moveToEntireInventory(stack, false)) return ItemStack.EMPTY;

} else if (isResultSlot(slotIndex)) {
// Usualy, mayPickup is only queried once, and then this method is called repeatedly until EMPTY is returned.
// Since this slot is allowed to remain non-empty even after pickup is not possible, we must check this every time.
// See AbstractContainerMenu#doClick
if (!slot.mayPickup(player)) return ItemStack.EMPTY;
if (!moveToEntireInventory(stack, true) && !moveToStorage(stack, true)) return ItemStack.EMPTY;

} else if (isPlayerInventory(slotIndex) || isHotbar(slotIndex)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ public Container getStorage() {
return storageInventory;
}

@Override
public boolean canConsumeFromCraftingMatrix() {
return !isPlanRecipe;
}

@Override
public Level getWorld() {
return getLevel();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// 1.19.2 2024-03-04T11:32:53.74826 forge/biome_modifier generator for projectred_exploration
d945627f6efcd004553c4907dafa754afd32182e data/projectred_exploration/forge/biome_modifier/add_overworld_carvers.json
867d7ebae686f787cde12b48c638e594733e28ae data/projectred_exploration/forge/biome_modifier/add_overworld_ores.json
// 1.19.2 2024-04-12T12:50:48.118367 forge/biome_modifier generator for projectred_exploration
a9ee4e4ea7ce9d6a5e98587da776a55196704fa2 data/projectred_exploration/forge/biome_modifier/add_electrotine_ore_to_overworld.json
b040a155acc4c4c41dadb18f3a2a8d514cf7cd22 data/projectred_exploration/forge/biome_modifier/add_marble_cave_to_overworld.json
d44596fde99ef0bd30d0ead290049c629e8b74b1 data/projectred_exploration/forge/biome_modifier/add_peridot_ore_to_overworld.json
bdc09c896ef2863532a7ef17a2e3567274819eef data/projectred_exploration/forge/biome_modifier/add_ruby_ore_to_overworld.json
691f03827983499ee1547931cc06a5cfbecb3349 data/projectred_exploration/forge/biome_modifier/add_sapphire_ore_to_overworld.json
05ade71ce944b91d3b8309ba9b396cef7377b64a data/projectred_exploration/forge/biome_modifier/add_silver_ore_to_overworld.json
c4f8a9b2d88c1b62f59e68aca1d58249ffe5c0cf data/projectred_exploration/forge/biome_modifier/add_tin_ore_to_overworld.json
Loading
Loading