Skip to content

Commit

Permalink
choose what you need in the pattern #2
Browse files Browse the repository at this point in the history
  • Loading branch information
RealSilverMoon committed Oct 30, 2023
1 parent 23fad42 commit 5a63640
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public class GTMachineBox extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<
public static IStructureDefinition<GTMachineBox> STRUCTURE_DEFINITION;

// The spotless made my structure a mess. Shit.

// spotless off
static {
StructureDefinition.Builder<GTMachineBox> A = IStructureDefinition.<GTMachineBox>builder()
.addShape(
Expand Down Expand Up @@ -942,6 +944,8 @@ public class GTMachineBox extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<
STRUCTURE_DEFINITION = A.build();
}

// spotless on

public GTMachineBox(String name) {
super(name);
}
Expand Down Expand Up @@ -1476,37 +1480,42 @@ public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
*
* @param player Who is making it
*/
private void makeAE2Pattern(EntityPlayer player, String ls) {
if (mProgresstime != 0) return;
for (ItemStack pattern : getStoredInputs()) {
if (Util.isPattern(pattern)) {
ItemStack outputPattern = pattern.copy();
if (recipe.FinalFluidOutput.isEmpty() && recipe.FinalFluidInput.isEmpty()) {
for (final ItemStack encodedPatternStack : AEApi.instance()
.definitions()
.items()
.encodedPattern()
.maybeStack(1)
.asSet()) {
outputPattern = encodedPatternStack;
NBTTagCompound encodedValue = recipe.RecipeToAE2ItemPattern(ls);
outputPattern.setTagCompound(encodedValue);
private void makeAE2Pattern(EntityPlayer player, String item, String fluid) {
if (item.equals("0") && fluid.equals("0")) {
player.addChatMessage(new ChatComponentText(i18n("tile.boxplusplus.chatmessage.6")));
return;
}
if (mProgresstime == 0) {
for (ItemStack pattern : getStoredInputs()) {
if (Util.isPattern(pattern)) {
ItemStack outputPattern = pattern.copy();
if (recipe.FinalFluidOutput.isEmpty() && recipe.FinalFluidInput.isEmpty()) {
for (final ItemStack encodedPatternStack : AEApi.instance()
.definitions()
.items()
.encodedPattern()
.maybeStack(1)
.asSet()) {
outputPattern = encodedPatternStack;
NBTTagCompound encodedValue = recipe.RecipeToAE2ItemPattern(item);
outputPattern.setTagCompound(encodedValue);
}
} else {
outputPattern = new ItemStack(ItemAndBlockHolder.PATTERN);
FluidPatternDetails patternDetail = new FluidPatternDetails(outputPattern);
patternDetail.setInputs(recipe.transInputsToAE2Stuff());
patternDetail.setOutputs(recipe.transOutputsToAE2Stuff(item, fluid));
patternDetail.setCanBeSubstitute(0);
outputPattern = patternDetail.writeToStack();
}
} else {
outputPattern = new ItemStack(ItemAndBlockHolder.PATTERN);
FluidPatternDetails patternDetail = new FluidPatternDetails(outputPattern);
patternDetail.setInputs(recipe.transInputsToAE2Stuff());
patternDetail.setOutputs(recipe.transOutputsToAE2Stuff(ls));
patternDetail.setCanBeSubstitute(0);
outputPattern = patternDetail.writeToStack();
outputPattern.stackTagCompound
.setString("author", player.getDisplayName() + i18n("tile.boxplusplus.boxinfo.16"));
pattern.stackSize -= 1;
mOutputItems = new ItemStack[] { outputPattern };
mMaxProgresstime = 100;
updateSlots();
return;
}
outputPattern.stackTagCompound
.setString("author", player.getDisplayName() + i18n("tile.boxplusplus.boxinfo.16"));
pattern.stackSize -= 1;
mOutputItems = new ItemStack[] { outputPattern };
mMaxProgresstime = 100;
updateSlots();
return;
}
}
player.addChatMessage(new ChatComponentText(i18n("tile.boxplusplus.chatmessage.8")));
Expand Down Expand Up @@ -3009,23 +3018,34 @@ public void onRemoveFocus() {
}

protected ModularWindow createExportPatternWindow(final EntityPlayer player) {
ModularWindow.Builder builder = ModularWindow.builder(168, 100);
ModularWindow.Builder builder = ModularWindow.builder(168, 125);
builder.setBackground(GT_UITextures.BACKGROUND_SINGLEBLOCK_DEFAULT);
builder.setGuiTint(getGUIColorization());
Synchronize(builder);
TextFieldWidget input = new TextFieldWidget().setValidator(var -> Util.validator(recipe, var));
return builder.widget(new TextWidget(i18n("tile.boxplusplus.boxUI.48")).setPos(5, 25))
TextFieldWidget inputItem = new TextFieldWidget().setValidator(var -> Util.validator(recipe, var, false));
TextFieldWidget inputFluid = new TextFieldWidget().setValidator(var -> Util.validator(recipe, var, true));
return builder.widget(new TextWidget(i18n("tile.boxplusplus.boxUI.48")).setPos(5, 45))
.widget(
input.setTextAlignment(Alignment.CenterLeft)
inputItem.setTextAlignment(Alignment.CenterLeft)
.setTextColor(Color.WHITE.dark(1))
.setFocusOnGuiOpen(true)
.setFocusOnGuiOpen(false)
.setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD_LIGHT_GRAY.withOffset(-1, -1, 2, 2))
.setPos(5, 5)
.setSize(140, 12))
.setPos(12, 10)
.addTooltip("Item")
.setSize(60, 12))
.widget(
inputFluid.setTextAlignment(Alignment.CenterLeft)
.setTextColor(Color.WHITE.dark(1))
.setFocusOnGuiOpen(false)
.setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD_LIGHT_GRAY.withOffset(-1, -1, 2, 2))
.setPos(96, 10)
.addTooltip("Fluid")
.setSize(60, 12))
.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
if (!widget.isClient()) {
String ls = input.getText();
makeAE2Pattern(player, ls);
String itemInput = inputItem.getText();
String fluidInput = inputFluid.getText();
makeAE2Pattern(player, itemInput, fluidInput);
player.closeScreen();
}
})
Expand All @@ -3037,7 +3057,7 @@ protected ModularWindow createExportPatternWindow(final EntityPlayer player) {
return UI.toArray(new IDrawable[0]);
})
.addTooltip(i18n("tile.boxplusplus.boxUI.36"))
.setPos(145, 5))
.setPos(76, 25))
.build();
}

Expand Down
44 changes: 21 additions & 23 deletions src/main/java/com/silvermoon/boxplusplus/util/BoxRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,41 +188,39 @@ public IAEItemStack[] transInputsToAE2Stuff() {
return stacks;
}

public IAEItemStack[] transOutputsToAE2Stuff(String ls) {
public IAEItemStack[] transOutputsToAE2Stuff(String itemKey, String fluidKey) {
List<IAEItemStack> stacks = new ArrayList<>();
if (ls.equals("")) {
for (FluidStack fluid : FinalFluidOutput) {
stacks.add(ItemFluidDrop.newAeStack(fluid));
if (itemKey.equals("")) for (FluidStack fluid : FinalFluidOutput) {
stacks.add(ItemFluidDrop.newAeStack(fluid));
}
else if (!itemKey.equals("0")) {
String[] var1 = itemKey.split(",");
for (String s : var1) {
if (s.contains("-")) {
String[] var2 = s.split("-");
int start = Integer.parseInt(var2[0]);
int end = Integer.parseInt(var2[1]);
for (int i = start - 1; i < end; i++) {
stacks.add(AEItemStack.create(FinalItemOutput.get(i)));
}
} else stacks.add(AEItemStack.create(FinalItemOutput.get(Integer.parseInt(s) - 1)));
}
}
if (fluidKey.equals("")) {
for (ItemStack item : FinalItemOutput) {
stacks.add(AEItemStack.create(item));
}
} else {
if (ls.contains("/")) {
String[] var1 = ls.substring(ls.indexOf("/") + 1)
.split(",");
for (String s : var1) {
if (s.contains("-")) {
String[] var2 = s.split("-");
int start = Integer.parseInt(var2[0]);
int end = Integer.parseInt(var2[1]);
for (int i = start - 1; i < end; i++) {
stacks.add(ItemFluidDrop.newAeStack(FinalFluidOutput.get(i)));
}
} else stacks.add(ItemFluidDrop.newAeStack(FinalFluidOutput.get(Integer.parseInt(s) - 1)));
}
}
ls = ls.contains("/") ? ls.substring(0, ls.indexOf("/")) : ls;
String[] var1 = ls.split(",");
} else if (!fluidKey.equals("0")) {
String[] var1 = fluidKey.split(",");
for (String s : var1) {
if (s.contains("-")) {
String[] var2 = s.split("-");
int start = Integer.parseInt(var2[0]);
int end = Integer.parseInt(var2[1]);
for (int i = start - 1; i < end; i++) {
stacks.add(AEItemStack.create(FinalItemOutput.get(i)));
stacks.add(ItemFluidDrop.newAeStack(FinalFluidOutput.get(i)));
}
} else stacks.add(AEItemStack.create(FinalItemOutput.get(Integer.parseInt(s) - 1)));
} else stacks.add(ItemFluidDrop.newAeStack(FinalFluidOutput.get(Integer.parseInt(s) - 1)));
}
}
return stacks.toArray(new IAEItemStack[0]);
Expand Down
26 changes: 7 additions & 19 deletions src/main/java/com/silvermoon/boxplusplus/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ public static List<FluidStack> deepCopyFluidList(List<FluidStack> org) {
return newList;
}

public static String validator(BoxRecipe recipe, String var) {
public static String validator(BoxRecipe recipe, String var, boolean isFluid) {
if (var.equals("0")) return var;
// wrong format?
Matcher m = Pattern.compile("^[0-9,/-]+$")
Matcher m = Pattern.compile("^[0-9-,]+$")
.matcher(var);
if (!m.matches()) return "";
// The second number cannot bigger then the first one!
Expand All @@ -239,26 +240,13 @@ public static String validator(BoxRecipe recipe, String var) {
.orElse(false);
if (!isSmaller) return "";
}
// fluid out of boundary
if (var.contains("/")) {
boolean isFluidOutArray = Stream.of(
var.substring(var.indexOf("/") + 1)
.split(","))
.flatMap(s -> Arrays.stream(s.split("-")))
.map(Integer::parseInt)
.max(Integer::compareTo)
.map(max -> max > recipe.FinalFluidOutput.size())
.orElse(true);
if (isFluidOutArray) return "";
}
String var2 = var.contains("/") ? var.substring(0, var.indexOf("/")) : var;
// item out of boundary
boolean isItemOutArray = Stream.of(var2.split(","))
// out of boundary
boolean isOutArray = Stream.of(var.split(","))
.flatMap(s -> Arrays.stream(s.split("-")))
.map(Integer::parseInt)
.max(Integer::compareTo)
.map(max -> max > recipe.FinalItemOutput.size())
.map(max -> max > (isFluid ? recipe.FinalFluidOutput : recipe.FinalItemOutput).size())
.orElse(true);
return isItemOutArray ? "" : var;
return isOutArray ? "" : var;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/assets/boxplusplus/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ tile.boxplusplus.boxUI.44=如果确认,请按
tile.boxplusplus.boxUI.45=清除完成。
tile.boxplusplus.boxUI.46=粘贴完整工序代码:
tile.boxplusplus.boxUI.47=错误,紧急中止清理进程!
tile.boxplusplus.boxUI.48=指定你希望输出在样板中的玩意。格式:物品编号/流体编号。例如:1,3-7,13/8,9输出1、3-7、13号物品和8号、9号流体; 留空默认输出全部
tile.boxplusplus.boxUI.48=指定你希望输出在样板中的玩意。例如:1,3-7,13表示输出1、3-7、13号物品或流体; 留空默认输出全部; 0表示全部不输出

tile.boxplusplus.boxError.1=原因:未通过1环结构检测。
tile.boxplusplus.boxError.2=原因:未通过2环结构检测。
Expand Down Expand Up @@ -287,7 +287,7 @@ tile.boxplusplus.chatmessage.2=已输出工序代码至剪切板!
tile.boxplusplus.chatmessage.3=输入有误,请检查工序代码。(注意必须在一行内)
tile.boxplusplus.chatmessage.4=你导入的工序数量大于本盒支持的工序上限了!
tile.boxplusplus.chatmessage.5=导入%count条工序成功!
tile.boxplusplus.chatmessage.6=输入有误,请检查工序代码
tile.boxplusplus.chatmessage.6=输入时遇到了错误,请检查
tile.boxplusplus.chatmessage.7=已将配方写入一份空白样板
tile.boxplusplus.chatmessage.8=在输入总线中没有找到空白样板

Expand Down

0 comments on commit 5a63640

Please sign in to comment.