Skip to content

Commit a03e508

Browse files
authored
Follow changes in MI's API (#22)
1 parent 6333a06 commit a03e508

14 files changed

+80
-170
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mod_github=https://github.com/Swedz/tesseract-neoforge
3636
# Dependencies
3737
mixinextras_version=0.3.5
3838
emi_version=1.1.10+1.21
39-
modern_industrialization_version=2.2.23
40-
modern_industrialization_version_range=[2.2.21-beta, 2.3-)
39+
modern_industrialization_version=2.2.27
40+
modern_industrialization_version_range=[2.2.27, 2.3-)
4141
grandpower_version=3.0.0
4242
cloth_config_version=15.0.127

src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/craft/ModularCrafterAccessBehavior.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import aztech.modern_industrialization.stats.PlayerStatistics;
77
import aztech.modern_industrialization.stats.PlayerStatisticsData;
88
import aztech.modern_industrialization.util.Simulation;
9-
import net.minecraft.world.level.Level;
9+
import net.minecraft.server.level.ServerLevel;
1010
import net.swedz.tesseract.neoforge.compat.mi.hook.MIHookEfficiency;
1111
import net.swedz.tesseract.neoforge.compat.mi.hook.MIHooks;
1212
import net.swedz.tesseract.neoforge.compat.mi.hook.context.machine.EfficiencyMIHookContext;
@@ -43,7 +43,7 @@ default long getMaxRecipeEu()
4343
{
4444
long maxRecipeEu = this.getBaseMaxRecipeEu();
4545
if(this instanceof MachineBlockEntity machineBlockEntity &&
46-
machineBlockEntity instanceof CrafterComponentHolder crafterComponentHolder)
46+
machineBlockEntity instanceof CrafterComponentHolder crafterComponentHolder)
4747
{
4848
CrafterAccess crafter = crafterComponentHolder.getCrafterComponent();
4949
EfficiencyMIHookContext context = new EfficiencyMIHookContext(
@@ -62,7 +62,7 @@ default boolean isOverdriving()
6262
}
6363

6464
// can't use getWorld() or the remapping will fail
65-
Level getCrafterWorld();
65+
ServerLevel getCrafterWorld();
6666

6767
default int getMaxFluidOutputs()
6868
{

src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/craft/multiplied/MultipliedCrafterComponent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ else if(efficiencyTicks > 0)
149149
lastInvHash = currentHash;
150150
}
151151

152-
ServerLevel serverWorld = (ServerLevel) behavior.getCrafterWorld();
152+
ServerLevel serverWorld = behavior.getCrafterWorld();
153153
MachineRecipeType recipeType = this.getRecipeType();
154154
List<RecipeHolder<MachineRecipe>> recipes = new ArrayList<>(recipeType.getFluidOnlyRecipes(serverWorld));
155155
for(ConfigurableItemStack stack : inventory.getItemInputs())
@@ -647,7 +647,7 @@ public void lockRecipe(ResourceLocation recipeId, Inventory inventory)
647647
{
648648
return;
649649
}
650-
Optional<RecipeHolder<MachineRecipe>> optionalMachineRecipe = recipeType.getRecipes(behavior.getCrafterWorld()).stream()
650+
Optional<RecipeHolder<MachineRecipe>> optionalMachineRecipe = recipeType.getRecipesWithCache(behavior.getCrafterWorld()).stream()
651651
.filter((recipe) -> recipe.id().equals(recipeId)).findFirst();
652652
if(optionalMachineRecipe.isEmpty())
653653
{

src/main/java/net/swedz/tesseract/neoforge/compat/mi/hack/HackedMachineRegistrationHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ public static void registerMachineTiers(String englishName, String machineName,
256256
registerReiTiers(
257257
englishName, machineName, type,
258258
new MachineCategoryParams(
259-
null, (ResourceLocation) null, items.sublist(0, itemInputCount),
259+
null, null, items.sublist(0, itemInputCount),
260260
items.sublist(itemInputCount, itemInputCount + itemOutputCount),
261261
fluids.sublist(0, fluidInputCount), fluids.sublist(fluidInputCount, fluidInputCount + fluidOutputCount), progressBarParams,
262-
null, false, SteamMode.BOTH
262+
null, null, false, SteamMode.BOTH
263263
),
264264
tiers
265265
);
@@ -286,7 +286,7 @@ private static void registerReiTiers(String englishName, String machine, Machine
286286
fullEnglishName, itemId, categoryParams.itemInputs,
287287
categoryParams.itemOutputs,
288288
categoryParams.fluidInputs, categoryParams.fluidOutputs, categoryParams.progressBarParams,
289-
recipe -> recipe.getType() == recipeType && minEu <= recipe.eu && recipe.eu <= maxEu, false,
289+
recipeType, (recipe) -> minEu <= recipe.eu && recipe.eu <= maxEu, false,
290290
i < 2 ? SteamMode.BOTH : SteamMode.ELECTRIC_ONLY
291291
);
292292
MIHookTracker.addReiCategoryName(itemId, fullEnglishName);

src/main/java/net/swedz/tesseract/neoforge/compat/mi/hook/MIHookTracker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static List<Consumer<MachineCasingModelsMIHookDatagenProvider>> getMachin
9797
return MACHINE_CASING_MODELS.computeIfAbsent(modId, (k) -> Lists.newArrayList());
9898
}
9999

100-
public static void addMachineCasingModel(String name, Consumer<MachineCasingModelsMIHookDatagenProvider> action)
100+
public static void addMachineCasingModel(Consumer<MachineCasingModelsMIHookDatagenProvider> action)
101101
{
102102
assertTracking();
103103

@@ -113,7 +113,7 @@ public record MachineModelProperties(
113113
{
114114
public void addToMachineJson(JsonObject json)
115115
{
116-
json.addProperty("casing", defaultCasing.name);
116+
json.addProperty("casing", defaultCasing.key.getNamespace().equals(MI.ID) ? defaultCasing.key.getPath() : defaultCasing.key.toString());
117117

118118
var defaultOverlays = new JsonObject();
119119

src/main/java/net/swedz/tesseract/neoforge/compat/mi/hook/context/listener/MachineCasingsMIHookContext.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@
1313

1414
public final class MachineCasingsMIHookContext implements MIHookContext
1515
{
16-
public MachineCasing register(String name, BiConsumer<MachineCasing, MachineCasingModelsMIHookDatagenProvider> model)
16+
public MachineCasing register(String id, String englishName, BiConsumer<MachineCasing, MachineCasingModelsMIHookDatagenProvider> model)
1717
{
18-
MachineCasing casing = MachineCasings.create(name);
19-
MIHookTracker.addMachineCasingModel(name, (provider) -> model.accept(casing, provider));
18+
MachineCasing casing = MachineCasings.create(MIHookTracker.id(id), englishName);
19+
MIHookTracker.addMachineCasingModel((provider) -> model.accept(casing, provider));
2020
return casing;
2121
}
2222

23-
public MachineCasing registerImitateBlock(String name, Supplier<Block> block)
23+
public MachineCasing registerImitateBlock(String id, Supplier<? extends Block> block)
2424
{
25-
return this.register(name, (casing, provider) -> provider.imitateBlock(casing, block.get()));
25+
MachineCasing casing = MachineCasings.createBlockImitation(MIHookTracker.id(id), block);
26+
MIHookTracker.addMachineCasingModel((provider) -> provider.imitateBlock(casing, block.get()));
27+
return casing;
2628
}
2729

28-
public MachineCasing registerCubeBottomTop(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top)
30+
public MachineCasing registerCubeBottomTop(String id, String englishName, ResourceLocation side, ResourceLocation bottom, ResourceLocation top)
2931
{
30-
return this.register(name, (casing, provider) -> provider.cubeBottomTop(casing, side, bottom, top));
32+
return this.register(id, englishName, (casing, provider) -> provider.cubeBottomTop(casing, side, bottom, top));
3133
}
3234

33-
public MachineCasing registerCubeAll(String name, ResourceLocation side)
35+
public MachineCasing registerCubeAll(String id, String englishName, ResourceLocation side)
3436
{
35-
return this.register(name, (casing, provider) -> provider.cubeAll(casing, side));
37+
return this.register(id, englishName, (casing, provider) -> provider.cubeAll(casing, side));
3638
}
3739
}

src/main/java/net/swedz/tesseract/neoforge/compat/mi/machine/blockentity/multiblock/BasicMultiblockMachineBlockEntity.java

Lines changed: 7 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
public abstract class BasicMultiblockMachineBlockEntity extends MultiblockMachineBlockEntity implements Tickable, MultiblockInventoryComponentHolder
1919
{
20-
protected ShapeMatcher shapeMatcher;
21-
22-
protected OperatingState operatingState = OperatingState.NOT_MATCHED;
23-
2420
protected final ActiveShapeComponent activeShape;
2521
protected final MultiblockInventoryComponent inventory;
2622
protected final IsActiveComponent isActive;
@@ -41,80 +37,26 @@ protected void updateActive(boolean active)
4137
isActive.updateActive(active, this);
4238
}
4339

44-
public void onLink(ShapeMatcher shapeMatcher)
45-
{
46-
}
47-
48-
public void onUnlink(ShapeMatcher shapeMatcher)
49-
{
50-
}
51-
52-
public void onSuccessfulMatch(ShapeMatcher shapeMatcher)
40+
@Override
41+
protected void onRematch(ShapeMatcher shapeMatcher)
5342
{
43+
if(shapeMatcher.isMatchSuccessful())
44+
{
45+
inventory.rebuild(shapeMatcher);
46+
}
5447
}
5548

5649
@Override
5750
public void tick()
5851
{
59-
if(level.isClientSide)
52+
if(level.isClientSide())
6053
{
6154
return;
6255
}
6356

6457
this.link();
6558
}
6659

67-
protected ShapeMatcher createShapeMatcher()
68-
{
69-
return new ShapeMatcher(level, worldPosition, orientation.facingDirection, this.getActiveShape());
70-
}
71-
72-
protected void link()
73-
{
74-
if(shapeMatcher == null)
75-
{
76-
shapeMatcher = this.createShapeMatcher();
77-
shapeMatcher.registerListeners(level);
78-
79-
this.onLink(shapeMatcher);
80-
}
81-
if(shapeMatcher.needsRematch())
82-
{
83-
operatingState = OperatingState.NOT_MATCHED;
84-
shapeValid.shapeValid = false;
85-
shapeMatcher.rematch(level);
86-
87-
if(shapeMatcher.isMatchSuccessful())
88-
{
89-
inventory.rebuild(shapeMatcher);
90-
91-
this.onSuccessfulMatch(shapeMatcher);
92-
93-
shapeValid.shapeValid = true;
94-
operatingState = OperatingState.TRYING_TO_RESUME;
95-
}
96-
97-
if(shapeValid.update())
98-
{
99-
this.sync(false);
100-
}
101-
}
102-
}
103-
104-
@Override
105-
public void unlink()
106-
{
107-
if(shapeMatcher != null)
108-
{
109-
shapeMatcher.unlinkHatches();
110-
shapeMatcher.unregisterListeners(level);
111-
112-
this.onUnlink(shapeMatcher);
113-
114-
shapeMatcher = null;
115-
}
116-
}
117-
11860
@Override
11961
public ShapeTemplate getActiveShape()
12062
{
@@ -138,21 +80,4 @@ protected MachineModelClientData getMachineModelData()
13880
{
13981
return new MachineModelClientData(null, orientation.facingDirection).active(isActive.isActive);
14082
}
141-
142-
public enum OperatingState
143-
{
144-
/**
145-
* Shape is not matched, don't do anything.
146-
*/
147-
NOT_MATCHED,
148-
/**
149-
* Trying to resume a recipe but the output might not fit anymore.
150-
* We wait until the output fits again before resuming normal operation.
151-
*/
152-
TRYING_TO_RESUME,
153-
/**
154-
* Normal operation.
155-
*/
156-
NORMAL_OPERATION
157-
}
15883
}

src/main/java/net/swedz/tesseract/neoforge/compat/mi/machine/blockentity/multiblock/multiplied/AbstractElectricMultipliedCraftingMultiblockBlockEntity.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ public List<? extends EnergyAccess> getEnergyComponents()
6464
}
6565

6666
@Override
67-
public void onSuccessfulMatch(ShapeMatcher shapeMatcher)
67+
protected void onRematch(ShapeMatcher shapeMatcher)
6868
{
69+
super.onRematch(shapeMatcher);
70+
6971
energyInputs.clear();
7072
for(HatchBlockEntity hatch : shapeMatcher.getMatchedHatches())
7173
{
@@ -83,15 +85,15 @@ protected ItemInteractionResult useItemOn(Player player, InteractionHand hand, D
8385
}
8486
if(!result.consumesAction())
8587
{
86-
result = this.mapComponentOrDefault(UpgradeComponent.class, upgrade -> upgrade.onUse(this, player, hand), result);
88+
result = components.mapOrDefault(UpgradeComponent.class, upgrade -> upgrade.onUse(this, player, hand), result);
8789
}
8890
if(!result.consumesAction())
8991
{
9092
result = redstoneControl.onUse(this, player, hand);
9193
}
9294
if(!result.consumesAction())
9395
{
94-
result = this.mapComponentOrDefault(OverdriveComponent.class, (overdrive) -> overdrive.onUse(this, player, hand), result);
96+
result = components.mapOrDefault(OverdriveComponent.class, (overdrive) -> overdrive.onUse(this, player, hand), result);
9597
}
9698
return result;
9799
}

src/main/java/net/swedz/tesseract/neoforge/compat/mi/machine/blockentity/multiblock/multiplied/AbstractMultipliedCraftingMultiblockBlockEntity.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import aztech.modern_industrialization.machines.BEP;
66
import aztech.modern_industrialization.machines.gui.MachineGuiParameters;
77
import aztech.modern_industrialization.machines.guicomponents.ReiSlotLocking;
8+
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
89
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
910
import aztech.modern_industrialization.machines.recipe.MachineRecipeType;
1011
import net.minecraft.resources.ResourceLocation;
11-
import net.minecraft.world.level.Level;
12+
import net.minecraft.server.level.ServerLevel;
1213
import net.swedz.tesseract.neoforge.compat.mi.component.craft.ModularCrafterAccessBehavior;
1314
import net.swedz.tesseract.neoforge.compat.mi.component.craft.multiplied.EuCostTransformer;
1415
import net.swedz.tesseract.neoforge.compat.mi.component.craft.multiplied.MultipliedCrafterComponent;
@@ -21,6 +22,8 @@ public abstract class AbstractMultipliedCraftingMultiblockBlockEntity extends Ba
2122
{
2223
protected final MultipliedCrafterComponent crafter;
2324

25+
protected OperatingState operatingState = OperatingState.NOT_MATCHED;
26+
2427
public AbstractMultipliedCraftingMultiblockBlockEntity(BEP bep, ResourceLocation id, ShapeTemplate[] shapeTemplates)
2528
{
2629
super(bep, new MachineGuiParameters.Builder(id, false).backgroundHeight(200).build(), shapeTemplates);
@@ -55,9 +58,9 @@ public CrafterAccess getCrafterComponent()
5558
}
5659

5760
@Override
58-
public Level getCrafterWorld()
61+
public ServerLevel getCrafterWorld()
5962
{
60-
return level;
63+
return (ServerLevel) level;
6164
}
6265

6366
@Override
@@ -66,6 +69,18 @@ public UUID getOwnerUuid()
6669
return placedBy.placerId;
6770
}
6871

72+
@Override
73+
protected void onRematch(ShapeMatcher shapeMatcher)
74+
{
75+
super.onRematch(shapeMatcher);
76+
77+
operatingState = OperatingState.NOT_MATCHED;
78+
if(shapeMatcher.isMatchSuccessful())
79+
{
80+
operatingState = OperatingState.TRYING_TO_RESUME;
81+
}
82+
}
83+
6984
@Override
7085
public void tick()
7186
{
@@ -104,4 +119,21 @@ public void tick()
104119
public void tickExtra()
105120
{
106121
}
122+
123+
public enum OperatingState
124+
{
125+
/**
126+
* Shape is not matched, don't do anything.
127+
*/
128+
NOT_MATCHED,
129+
/**
130+
* Trying to resume a recipe but the output might not fit anymore.
131+
* We wait until the output fits again before resuming normal operation.
132+
*/
133+
TRYING_TO_RESUME,
134+
/**
135+
* Normal operation.
136+
*/
137+
NORMAL_OPERATION
138+
}
107139
}

src/main/java/net/swedz/tesseract/neoforge/compat/mi/machine/blockentity/multiblock/multiplied/AbstractSteamMultipliedCraftingMultiblockBlockEntity.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ public AbstractSteamMultipliedCraftingMultiblockBlockEntity(BEP bep, ResourceLoc
3838
}
3939

4040
@Override
41-
public void onSuccessfulMatch(ShapeMatcher shapeMatcher)
41+
protected void onRematch(ShapeMatcher shapeMatcher)
4242
{
43+
super.onRematch(shapeMatcher);
44+
4345
steel = false;
4446
for(HatchBlockEntity hatch : shapeMatcher.getMatchedHatches())
4547
{

0 commit comments

Comments
 (0)