Skip to content

Commit abd667a

Browse files
committed
TX Loader support; Fix the problem that the recipe does not update the components correctly during operation.
1 parent 3c35035 commit abd667a

File tree

10 files changed

+64
-18
lines changed

10 files changed

+64
-18
lines changed

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ dependencies {
108108
implementation fg.deobf("curse.maven:flux-networks-248020:3178199")
109109
implementation fg.deobf("curse.maven:tinkers-construct-74072:2902483")
110110
implementation fg.deobf("curse.maven:mantle-74924:2713386")
111-
112-
compileOnly fg.deobf("curse.maven:lazy-ae2-322347:3254160")
111+
implementation fg.deobf("curse.maven:tx-loader-706505:4515357")
113112
}
114113

115114
jar {

src/main/java/hellfirepvp/modularmachinery/common/base/Mods.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public enum Mods {
2828
TOP("theoneprobe"),
2929
NUCLEARCRAFT_OVERHAULED("nuclearcraft"),
3030
RESOURCELOADER("resourceloader"),
31+
// TXLoader uses fully private variables and I can't get the correct resource folder.
32+
// Bad design.
33+
TX_LOADER("txloader"),
3134
FLUX_NETWORKS("fluxnetworks"),
3235
ZEN_UTILS("zenutils"),
3336
TCONSTRUCT("tconstruct"),

src/main/java/hellfirepvp/modularmachinery/common/crafting/helper/RecipeCraftingContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController;
2525
import hellfirepvp.modularmachinery.common.util.Asyncable;
2626
import hellfirepvp.modularmachinery.common.util.ResultChance;
27+
import net.minecraft.util.Tuple;
2728

2829
import javax.annotation.Nonnull;
2930
import javax.annotation.Nullable;
@@ -341,6 +342,14 @@ private boolean canStartCrafting(final CraftingCheckResult result, final Compone
341342
return false;
342343
}
343344

345+
public void updateComponents(Collection<Tuple<MachineComponent<?>, ComponentSelectorTag>> components) {
346+
this.typeComponents.clear();
347+
for (final Tuple<MachineComponent<?>, ComponentSelectorTag> tuple : components) {
348+
addComponent(tuple.getFirst(), tuple.getSecond());
349+
}
350+
updateRequirementComponents();
351+
}
352+
344353
public <T> void addComponent(MachineComponent<T> component, @Nullable ComponentSelectorTag tag) {
345354
this.typeComponents.add(new ProcessingComponent<>(component, component.getContainerProvider(), tag));
346355
}

src/main/java/hellfirepvp/modularmachinery/common/integration/preview/StructurePreviewWrapper.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,22 @@ public static ItemStack renderItemStackToGUI(final GuiScreen g, final Minecraft
328328
ri.renderItemOverlays(mc.fontRenderer, stack, x, y);
329329

330330
if ((mouseX >= x && mouseX <= x + 16) && (mouseY >= y && mouseY <= y + 16)) {
331-
GuiScreen.drawRect(x, y, x + 16, y + 16, new Color(255, 255, 255, 150).getRGB());
331+
renderHoveredForeground(x, y);
332332
return stack;
333333
}
334334
return null;
335335
}
336336

337+
private static void renderHoveredForeground(final int x, final int y) {
338+
GlStateManager.disableLighting();
339+
GlStateManager.disableDepth();
340+
GlStateManager.colorMask(true, true, true, false);
341+
GuiScreen.drawRect(x, y, x + 16, y + 16, new Color(255, 255, 255, 150).getRGB());
342+
GlStateManager.colorMask(true, true, true, true);
343+
GlStateManager.enableLighting();
344+
GlStateManager.enableDepth();
345+
}
346+
337347
private void renderUpgrades(final Minecraft minecraft, final int mouseX, final int mouseY) {
338348
minecraft.getTextureManager().bindTexture(TEXTURE_BACKGROUND);
339349
this.drawableUpgradesHover.draw(minecraft, 5, 124);

src/main/java/hellfirepvp/modularmachinery/common/machine/DynamicMachine.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,10 @@ public RecipeCraftingContext createContext(ActiveMachineRecipe activeRecipe,
153153
if (!activeRecipe.getRecipe().getOwningMachineIdentifier().equals(registryName)) {
154154
throw new IllegalArgumentException("Tried to create context for a recipe that doesn't belong to the referenced machine!");
155155
}
156-
RecipeCraftingContext context = new RecipeCraftingContext(activeRecipe, controller);
157-
for (Tuple<MachineComponent<?>, ComponentSelectorTag> tpl : taggedComponents) {
158-
context.addComponent(tpl.getFirst(), tpl.getSecond());
159-
}
160-
modifiers.forEach(context::addModifier);
161-
context.updateRequirementComponents();
162-
return context;
156+
RecipeCraftingContext ctx = new RecipeCraftingContext(activeRecipe, controller);
157+
ctx.updateComponents(taggedComponents);
158+
modifiers.forEach(ctx::addModifier);
159+
return ctx;
163160
}
164161

165162
public void mergeFrom(DynamicMachine another) {

src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class RegistryBlocks {
6161

6262
public static void initialize() {
6363
registerBlocks();
64-
if (Mods.RESOURCELOADER.isPresent()) {
64+
if (Mods.RESOURCELOADER.isPresent() || Mods.TX_LOADER.isPresent()) {
6565
try {
6666
RegistryBlocks.writeAllCustomControllerModels();
6767
} catch (IOException e) {

src/main/java/hellfirepvp/modularmachinery/common/tiles/TileFactoryController.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ public void offerRecipe(RecipeCraftingContext context) {
347347

348348
FactoryRecipeThread thread = new FactoryRecipeThread(this);
349349
thread.setContext(context)
350-
.setActiveRecipe(context.getActiveRecipe())
351-
.setStatus(CraftingStatus.SUCCESS);
350+
.setActiveRecipe(context.getActiveRecipe())
351+
.setStatus(CraftingStatus.SUCCESS);
352352
recipeThreadList.add(thread);
353353
onThreadRecipeStart(thread);
354354
}
@@ -437,6 +437,26 @@ public boolean hasIdleThread() {
437437
return false;
438438
}
439439

440+
@Override
441+
protected void updateComponents() {
442+
super.updateComponents();
443+
for (final FactoryRecipeThread thread : this.recipeThreadList) {
444+
RecipeCraftingContext ctx = thread.getContext();
445+
if (ctx == null) {
446+
continue;
447+
}
448+
ctx.updateComponents(this.foundComponents);
449+
}
450+
451+
for (final FactoryRecipeThread thread : this.coreRecipeThreads.values()) {
452+
RecipeCraftingContext ctx = thread.getContext();
453+
if (ctx == null) {
454+
continue;
455+
}
456+
ctx.updateComponents(this.foundComponents);
457+
}
458+
}
459+
440460
@Override
441461
protected void checkRotation() {
442462
IBlockState state = getWorld().getBlockState(getPos());

src/main/java/hellfirepvp/modularmachinery/common/tiles/TileMachineController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import hellfirepvp.modularmachinery.common.crafting.ActiveMachineRecipe;
1919
import hellfirepvp.modularmachinery.common.crafting.MachineRecipe;
2020
import hellfirepvp.modularmachinery.common.crafting.helper.CraftingStatus;
21+
import hellfirepvp.modularmachinery.common.crafting.helper.RecipeCraftingContext;
2122
import hellfirepvp.modularmachinery.common.lib.BlocksMM;
2223
import hellfirepvp.modularmachinery.common.machine.DynamicMachine;
2324
import hellfirepvp.modularmachinery.common.machine.MachineRecipeThread;
@@ -134,6 +135,16 @@ protected boolean doRecipeTick() {
134135
return true;
135136
}
136137

138+
@Override
139+
protected void updateComponents() {
140+
super.updateComponents();
141+
RecipeCraftingContext ctx = this.recipeThread.getContext();
142+
if (ctx == null) {
143+
return;
144+
}
145+
ctx.updateComponents(this.foundComponents);
146+
}
147+
137148
@Override
138149
protected void checkRotation() {
139150
IBlockState state = getWorld().getBlockState(getPos());

src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ protected void updateStatedMachineComponent(final boolean working) {
377377
}
378378

379379
public RecipeCraftingContext createContext(ActiveMachineRecipe activeRecipe) {
380-
RecipeCraftingContext context = this.foundMachine.createContext(activeRecipe, this, Collections.unmodifiableList(this.foundComponents), MiscUtils.flatten(this.foundModifiers.values()));
380+
RecipeCraftingContext context = this.foundMachine.createContext(activeRecipe, this, this.foundComponents, MiscUtils.flatten(this.foundModifiers.values()));
381381
context.addModifier(customModifiers.values());
382382
return context;
383383
}

src/main/java/hellfirepvp/modularmachinery/common/util/BlockArray.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ public BlockArray(BlockArray other, Vec3i offset) {
8383
public StructureBoundingBox getPatternBoundingBox(final BlockPos ctrlPos) {
8484
BlockPos min = ctrlPos.add(this.min);
8585
BlockPos max = ctrlPos.add(this.max);
86-
return new StructureBoundingBox(new int[]{
87-
min.getX(), min.getY(), min.getZ(),
88-
max.getX(), max.getY(), max.getZ()
89-
});
86+
return new StructureBoundingBox(min, max);
9087
}
9188

9289
public void flushTileBlocksCache() {

0 commit comments

Comments
 (0)