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

Add various GUI changes relating to Parallel Recipes #2719

Merged
merged 3 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,7 @@
"gtceu.multiblock.page_switcher.io.export": "sʇndʇnOㄣ§",
"gtceu.multiblock.page_switcher.io.import": "sʇnduIᄅ§",
"gtceu.multiblock.parallel": "ןǝןןɐɹɐԀ uı sǝdıɔǝᴚ %d oʇ dn buıɯɹoɟɹǝԀ",
"gtceu.multiblock.parallel.exact": "ןǝןןɐɹɐԀ uı sǝdıɔǝᴚ %d buıɯɹoɟɹǝԀ",
"gtceu.multiblock.parallelizable.tooltip": "˙sǝɥɔʇɐH ןoɹʇuoƆ ןǝןןɐɹɐԀ ɥʇıʍ ǝzıןǝןןɐɹɐd uɐƆ",
"gtceu.multiblock.pattern.clear_amount_1": "ɹ§ʇuoɹɟ uı ǝɔɐds ƖxƖxƖ ɹɐǝןɔ ɐ ǝʌɐɥ ʇsnW9§",
"gtceu.multiblock.pattern.clear_amount_3": "ɹ§ʇuoɹɟ uı ǝɔɐds ƖxƐxƐ ɹɐǝןɔ ɐ ǝʌɐɥ ʇsnW9§",
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,7 @@
"gtceu.multiblock.page_switcher.io.export": "§4Outputs",
"gtceu.multiblock.page_switcher.io.import": "§2Inputs",
"gtceu.multiblock.parallel": "Performing up to %d Recipes in Parallel",
"gtceu.multiblock.parallel.exact": "Performing %d Recipes in Parallel",
"gtceu.multiblock.parallelizable.tooltip": "Can parallelize with Parallel Control Hatches.",
"gtceu.multiblock.pattern.clear_amount_1": "§6Must have a clear 1x1x1 space in front§r",
"gtceu.multiblock.pattern.clear_amount_3": "§6Must have a clear 3x3x1 space in front§r",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,15 @@ public Builder addMachineModeLine(GTRecipeType recipeType, boolean hasMultipleMo
* <br>
* Added if structure is formed and the number of parallels is greater than one.
*/
public Builder addParallelsLine(int numParallels) {
public Builder addParallelsLine(int numParallels, boolean exact) {
if (!isStructureFormed)
return this;
if (numParallels > 1) {
Component parallels = Component.literal(FormattingUtil.formatNumbers(numParallels))
.withStyle(ChatFormatting.DARK_PURPLE);

textList.add(Component.translatable(
"gtceu.multiblock.parallel",
parallels)
String key = "gtceu.multiblock.parallel";
if (exact) key += ".exact";
textList.add(Component.translatable(key, parallels)
.withStyle(ChatFormatting.GRAY));
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,23 @@ public void onPartUnload() {

@Override
public void addDisplayText(List<Component> textList) {
int numParallels = this.getParallelHatch()
.map(IParallelHatch::getCurrentParallel)
.orElse(0);
int numParallels;
boolean exact = false;
if (recipeLogic.isActive() && recipeLogic.getLastRecipe() != null) {
numParallels = recipeLogic.getLastRecipe().parallels;
exact = true;
} else {
numParallels = getParallelHatch()
.map(IParallelHatch::getCurrentParallel)
.orElse(0);
}

MultiblockDisplayText.builder(textList, isFormed())
.setWorkingStatus(recipeLogic.isWorkingEnabled(), recipeLogic.isActive())
.addEnergyUsageLine(energyContainer)
.addEnergyTierLine(tier)
.addMachineModeLine(getRecipeType(), getRecipeTypes().length > 1)
.addParallelsLine(numParallels)
.addParallelsLine(numParallels, exact)
.addWorkingStatusLine()
.addProgressLine(recipeLogic.getProgress(), recipeLogic.getMaxProgress(),
recipeLogic.getProgressPercent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,7 @@ public static void init(RegistrateLangProvider provider) {
provider.add("gtceu.multiblock.universal.distinct.info",
"If enabled, each Item Input Bus will be treated as fully distinct from each other for recipe lookup. Useful for things like Programmed Circuits, Extruder Shapes, etc.");
provider.add("gtceu.multiblock.parallel", "Performing up to %d Recipes in Parallel");
provider.add("gtceu.multiblock.parallel.exact", "Performing %d Recipes in Parallel");
provider.add("gtceu.multiblock.multiple_recipemaps.header", "Machine Mode:");
provider.add("gtceu.multiblock.multiple_recipemaps.tooltip",
"Screwdriver the controller to change which machine mode to use.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.blockentity.MetaMachineBlockEntity;
import com.gregtechceu.gtceu.api.capability.IParallelHatch;
import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiController;
import com.gregtechceu.gtceu.utils.FormattingUtil;

import net.minecraft.ChatFormatting;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -23,9 +25,11 @@ public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPlugi
if (blockAccessor.getServerData().contains("parallel")) {
int parallel = blockAccessor.getServerData().getInt("parallel");
if (parallel > 0) {
iTooltip.add(Component.translatable(
"gtceu.multiblock.parallel",
Component.literal(parallel + "").withStyle(ChatFormatting.DARK_PURPLE)));
Component parallels = Component.literal(FormattingUtil.formatNumbers(parallel))
.withStyle(ChatFormatting.DARK_PURPLE);
String key = "gtceu.multiblock.parallel";
if (blockAccessor.getServerData().getBoolean("exact")) key += ".exact";
iTooltip.add(Component.translatable(key, parallels));
}
}
}
Expand All @@ -36,8 +40,16 @@ public void appendServerData(CompoundTag compoundTag, BlockAccessor blockAccesso
if (blockEntity.getMetaMachine() instanceof IParallelHatch parallelHatch) {
compoundTag.putInt("parallel", parallelHatch.getCurrentParallel());
} else if (blockEntity.getMetaMachine() instanceof IMultiController controller) {
controller.getParallelHatch()
.ifPresent(parallelHatch -> compoundTag.putInt("parallel", parallelHatch.getCurrentParallel()));
if (controller instanceof IRecipeLogicMachine rlm &&
rlm.getRecipeLogic().isActive() &&
rlm.getRecipeLogic().getLastRecipe() != null) {
compoundTag.putInt("parallel", rlm.getRecipeLogic().getLastRecipe().parallels);
compoundTag.putBoolean("exact", true);
} else {
controller.getParallelHatch()
.ifPresent(parallelHatch -> compoundTag.putInt("parallel",
parallelHatch.getCurrentParallel()));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;
import com.gregtechceu.gtceu.api.capability.recipe.FluidRecipeCapability;
import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability;
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
import com.gregtechceu.gtceu.api.recipe.RecipeHelper;
import com.gregtechceu.gtceu.integration.jade.GTElementHelper;
Expand Down Expand Up @@ -49,26 +51,54 @@ protected void write(CompoundTag data, RecipeLogic recipeLogic) {
data.putBoolean("Working", recipeLogic.isWorking());
var recipe = recipeLogic.getLastRecipe();
if (recipe != null) {
ListTag itemTags = new ListTag();
for (var stack : RecipeHelper.getOutputItems(recipe)) {
if (stack != null && !stack.isEmpty()) {
var itemTag = new CompoundTag();
int recipeTier = RecipeHelper.getPreOCRecipeEuTier(recipe);
int chanceTier = recipeTier + recipe.ocLevel;
var function = recipe.getType().getChanceFunction();
var itemContents = recipe.getOutputContents(ItemRecipeCapability.CAP);
var fluidContents = recipe.getOutputContents(FluidRecipeCapability.CAP);

GTUtil.saveItemStack(stack, itemTag);
itemTags.add(itemTag);
ListTag itemTags = new ListTag();
for (var item : itemContents) {
var stacks = ItemRecipeCapability.CAP.of(item.content).getItems();
if (stacks.length == 0) continue;
if (stacks[0].isEmpty()) continue;
var stack = stacks[0];

var itemTag = new CompoundTag();
GTUtil.saveItemStack(stack, itemTag);
if (item.chance < item.maxChance) {
int count = stack.getCount();
double countD = (double) count * recipe.parallels *
function.getBoostedChance(item, recipeTier, chanceTier) / item.maxChance;
count = countD < 1 ? 1 : (int) Math.round(countD);
itemTag.putInt("Count", count);
}
itemTags.add(itemTag);
}

if (!itemTags.isEmpty()) {
data.put("OutputItems", itemTags);
}

ListTag fluidTags = new ListTag();
for (var stack : RecipeHelper.getOutputFluids(recipe)) {
if (stack != null && !stack.isEmpty()) {
var fluidTag = new CompoundTag();
stack.writeToNBT(fluidTag);
fluidTags.add(fluidTag);
for (var fluid : fluidContents) {
var stacks = FluidRecipeCapability.CAP.of(fluid.content).getStacks();
if (stacks.length == 0) continue;
if (stacks[0].isEmpty()) continue;
var stack = stacks[0];

var fluidTag = new CompoundTag();
stack.writeToNBT(fluidTag);
if (fluid.chance < fluid.maxChance) {
int amount = stack.getAmount();
double amountD = (double) amount * recipe.parallels *
function.getBoostedChance(fluid, recipeTier, chanceTier) / fluid.maxChance;
amount = amountD < 1 ? 1 : (int) Math.round(amountD);
fluidTag.putInt("Amount", amount);
}
fluidTags.add(fluidTag);
}

if (!fluidTags.isEmpty()) {
data.put("OutputFluids", fluidTags);
}
Expand Down Expand Up @@ -141,7 +171,6 @@ private void addFluidTooltips(ITooltip iTooltip, List<FluidStack> outputFluids)
.append(getFluidName(fluidOutput))
.withStyle(ChatFormatting.WHITE);
iTooltip.append(text);

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.blockentity.MetaMachineBlockEntity;
import com.gregtechceu.gtceu.api.capability.IParallelHatch;
import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiController;
import com.gregtechceu.gtceu.utils.FormattingUtil;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -31,17 +33,27 @@ public void addProbeInfo(ProbeMode probeMode, IProbeInfo iProbeInfo, Player play
BlockEntity blockEntity = level.getBlockEntity(iProbeHitData.getPos());
if (blockEntity instanceof MetaMachineBlockEntity machineBlockEntity) {
int parallel = 0;
boolean exact = false;
if (machineBlockEntity.getMetaMachine() instanceof IParallelHatch parallelHatch) {
parallel = parallelHatch.getCurrentParallel();
} else if (machineBlockEntity.getMetaMachine() instanceof IMultiController controller) {
parallel = controller.getParallelHatch()
.map(IParallelHatch::getCurrentParallel)
.orElse(0);
if (controller instanceof IRecipeLogicMachine rlm &&
rlm.getRecipeLogic().isActive() &&
rlm.getRecipeLogic().getLastRecipe() != null) {
parallel = rlm.getRecipeLogic().getLastRecipe().parallels;
exact = true;
} else {
parallel = controller.getParallelHatch()
.map(IParallelHatch::getCurrentParallel)
.orElse(0);
}
}
if (parallel > 0) {
iProbeInfo.text(Component.translatable(
"gtceu.multiblock.parallel",
Component.literal(parallel + "").withStyle(ChatFormatting.DARK_PURPLE)));
Component parallels = Component.literal(FormattingUtil.formatNumbers(parallel))
.withStyle(ChatFormatting.DARK_PURPLE);
String key = "gtceu.multiblock.parallel";
if (exact) key += ".exact";
iProbeInfo.text(Component.translatable(key, parallels));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;
import com.gregtechceu.gtceu.api.capability.recipe.FluidRecipeCapability;
import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability;
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
import com.gregtechceu.gtceu.api.recipe.RecipeHelper;
import com.gregtechceu.gtceu.integration.top.element.FluidStackElement;
Expand All @@ -24,6 +26,7 @@
import mcjty.theoneprobe.apiimpl.styles.ItemStyle;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class RecipeOutputProvider extends CapabilityInfoProvider<RecipeLogic> {
Expand All @@ -45,17 +48,52 @@ protected void addProbeInfo(RecipeLogic recipeLogic, IProbeInfo iProbeInfo, Play
if (recipeLogic.isWorking()) {
var recipe = recipeLogic.getLastRecipe();
if (recipe != null) {
IProbeInfo verticalPane = iProbeInfo.vertical(iProbeInfo.defaultLayoutStyle().spacing(0));
verticalPane.text(
CompoundText.create().info(Component.translatable("gtceu.top.recipe_output").append(" ")));
List<ItemStack> outputItems = RecipeHelper.getOutputItems(recipe);
if (!outputItems.isEmpty()) {
addItemInfo(verticalPane, outputItems);
int recipeTier = RecipeHelper.getPreOCRecipeEuTier(recipe);
int chanceTier = recipeTier + recipe.ocLevel;
var function = recipe.getType().getChanceFunction();
var itemContents = recipe.getOutputContents(ItemRecipeCapability.CAP);
var fluidContents = recipe.getOutputContents(FluidRecipeCapability.CAP);

List<ItemStack> itemOutputs = new ArrayList<>();
for (var item : itemContents) {
var stacks = ItemRecipeCapability.CAP.of(item.content).getItems();
if (stacks.length == 0) continue;
if (stacks[0].isEmpty()) continue;
var stack = stacks[0].copy();

if (item.chance < item.maxChance) {
int count = stack.getCount();
double countD = (double) count * recipe.parallels *
function.getBoostedChance(item, recipeTier, chanceTier) / item.maxChance;
count = countD < 1 ? 1 : (int) Math.round(countD);
stack.setCount(count);
}
itemOutputs.add(stack);
}

List<FluidStack> fluidOutputs = new ArrayList<>();
for (var fluid : fluidContents) {
var stacks = FluidRecipeCapability.CAP.of(fluid.content).getStacks();
if (stacks.length == 0) continue;
if (stacks[0].isEmpty()) continue;
var stack = stacks[0].copy();

if (fluid.chance < fluid.maxChance) {
int amount = stack.getAmount();
double amountD = (double) amount * recipe.parallels *
function.getBoostedChance(fluid, recipeTier, chanceTier) / fluid.maxChance;
amount = amountD < 1 ? 1 : (int) Math.round(amountD);
stack.setAmount(amount);
}
fluidOutputs.add(stack);
}

List<FluidStack> outputFluids = RecipeHelper.getOutputFluids(recipe);
if (!outputFluids.isEmpty()) {
addFluidInfo(verticalPane, outputFluids);
if (!itemOutputs.isEmpty() || !fluidOutputs.isEmpty()) {
IProbeInfo verticalPane = iProbeInfo.vertical(iProbeInfo.defaultLayoutStyle().spacing(0));
verticalPane.text(
CompoundText.create().info(Component.translatable("gtceu.top.recipe_output").append(" ")));
addItemInfo(verticalPane, itemOutputs);
addFluidInfo(verticalPane, fluidOutputs);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public Tag serializeNBT() {
tag.putString("id", payload.id.toString());
tag.put("recipe",
GTRecipeSerializer.CODEC.encodeStart(NbtOps.INSTANCE, payload).result().orElse(new CompoundTag()));
tag.putInt("parallels", payload.parallels);
tag.putInt("ocLevel", payload.ocLevel);
return tag;
}

Expand All @@ -52,6 +54,8 @@ public void deserializeNBT(Tag tag) {
payload = GTRecipeSerializer.CODEC.parse(NbtOps.INSTANCE, compoundTag.get("recipe")).result().orElse(null);
if (payload != null) {
payload.id = new ResourceLocation(compoundTag.getString("id"));
payload.parallels = compoundTag.contains("parallels") ? compoundTag.getInt("parallels") : 1;
payload.ocLevel = compoundTag.getInt("ocLevel");
}
} else if (tag instanceof StringTag stringTag) { // Backwards Compatibility
var recipe = recipeManager.byKey(new ResourceLocation(stringTag.getAsString())).orElse(null);
Expand All @@ -75,13 +79,19 @@ public void deserializeNBT(Tag tag) {
public void writePayload(FriendlyByteBuf buf) {
buf.writeResourceLocation(this.payload.id);
GTRecipeSerializer.SERIALIZER.toNetwork(buf, this.payload);
buf.writeInt(this.payload.parallels);
buf.writeInt(this.payload.ocLevel);
}

@Override
public void readPayload(FriendlyByteBuf buf) {
var id = buf.readResourceLocation();
if (buf.isReadable()) {
this.payload = GTRecipeSerializer.SERIALIZER.fromNetwork(id, buf);
if (buf.isReadable()) {
this.payload.parallels = buf.readInt();
this.payload.ocLevel = buf.readInt();
}
} else { // Backwards Compatibility
RecipeManager recipeManager = getRecipeManager();
this.payload = (GTRecipe) recipeManager.byKey(id).orElse(null);
Expand Down
Loading
Loading