Skip to content
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
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod_github=https://github.com/Swedz/tesseract-neoforge
# Dependencies
mixinextras_version=0.3.5
emi_version=1.1.10+1.21
modern_industrialization_version=2.2.23
modern_industrialization_version_range=[2.2.21-beta, 2.3-)
modern_industrialization_version=2.2.27
modern_industrialization_version_range=[2.2.27, 2.3-)
grandpower_version=3.0.0
cloth_config_version=15.0.127
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import aztech.modern_industrialization.stats.PlayerStatistics;
import aztech.modern_industrialization.stats.PlayerStatisticsData;
import aztech.modern_industrialization.util.Simulation;
import net.minecraft.world.level.Level;
import net.minecraft.server.level.ServerLevel;
import net.swedz.tesseract.neoforge.compat.mi.hook.MIHookEfficiency;
import net.swedz.tesseract.neoforge.compat.mi.hook.MIHooks;
import net.swedz.tesseract.neoforge.compat.mi.hook.context.machine.EfficiencyMIHookContext;
Expand Down Expand Up @@ -43,7 +43,7 @@ default long getMaxRecipeEu()
{
long maxRecipeEu = this.getBaseMaxRecipeEu();
if(this instanceof MachineBlockEntity machineBlockEntity &&
machineBlockEntity instanceof CrafterComponentHolder crafterComponentHolder)
machineBlockEntity instanceof CrafterComponentHolder crafterComponentHolder)
{
CrafterAccess crafter = crafterComponentHolder.getCrafterComponent();
EfficiencyMIHookContext context = new EfficiencyMIHookContext(
Expand All @@ -62,7 +62,7 @@ default boolean isOverdriving()
}

// can't use getWorld() or the remapping will fail
Level getCrafterWorld();
ServerLevel getCrafterWorld();

default int getMaxFluidOutputs()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ else if(efficiencyTicks > 0)
lastInvHash = currentHash;
}

ServerLevel serverWorld = (ServerLevel) behavior.getCrafterWorld();
ServerLevel serverWorld = behavior.getCrafterWorld();
MachineRecipeType recipeType = this.getRecipeType();
List<RecipeHolder<MachineRecipe>> recipes = new ArrayList<>(recipeType.getFluidOnlyRecipes(serverWorld));
for(ConfigurableItemStack stack : inventory.getItemInputs())
Expand Down Expand Up @@ -647,7 +647,7 @@ public void lockRecipe(ResourceLocation recipeId, Inventory inventory)
{
return;
}
Optional<RecipeHolder<MachineRecipe>> optionalMachineRecipe = recipeType.getRecipes(behavior.getCrafterWorld()).stream()
Optional<RecipeHolder<MachineRecipe>> optionalMachineRecipe = recipeType.getRecipesWithCache(behavior.getCrafterWorld()).stream()
.filter((recipe) -> recipe.id().equals(recipeId)).findFirst();
if(optionalMachineRecipe.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ public static void registerMachineTiers(String englishName, String machineName,
registerReiTiers(
englishName, machineName, type,
new MachineCategoryParams(
null, (ResourceLocation) null, items.sublist(0, itemInputCount),
null, null, items.sublist(0, itemInputCount),
items.sublist(itemInputCount, itemInputCount + itemOutputCount),
fluids.sublist(0, fluidInputCount), fluids.sublist(fluidInputCount, fluidInputCount + fluidOutputCount), progressBarParams,
null, false, SteamMode.BOTH
null, null, false, SteamMode.BOTH
),
tiers
);
Expand All @@ -286,7 +286,7 @@ private static void registerReiTiers(String englishName, String machine, Machine
fullEnglishName, itemId, categoryParams.itemInputs,
categoryParams.itemOutputs,
categoryParams.fluidInputs, categoryParams.fluidOutputs, categoryParams.progressBarParams,
recipe -> recipe.getType() == recipeType && minEu <= recipe.eu && recipe.eu <= maxEu, false,
recipeType, (recipe) -> minEu <= recipe.eu && recipe.eu <= maxEu, false,
i < 2 ? SteamMode.BOTH : SteamMode.ELECTRIC_ONLY
);
MIHookTracker.addReiCategoryName(itemId, fullEnglishName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static List<Consumer<MachineCasingModelsMIHookDatagenProvider>> getMachin
return MACHINE_CASING_MODELS.computeIfAbsent(modId, (k) -> Lists.newArrayList());
}

public static void addMachineCasingModel(String name, Consumer<MachineCasingModelsMIHookDatagenProvider> action)
public static void addMachineCasingModel(Consumer<MachineCasingModelsMIHookDatagenProvider> action)
{
assertTracking();

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

var defaultOverlays = new JsonObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@

public final class MachineCasingsMIHookContext implements MIHookContext
{
public MachineCasing register(String name, BiConsumer<MachineCasing, MachineCasingModelsMIHookDatagenProvider> model)
public MachineCasing register(String id, String englishName, BiConsumer<MachineCasing, MachineCasingModelsMIHookDatagenProvider> model)
{
MachineCasing casing = MachineCasings.create(name);
MIHookTracker.addMachineCasingModel(name, (provider) -> model.accept(casing, provider));
MachineCasing casing = MachineCasings.create(MIHookTracker.id(id), englishName);
MIHookTracker.addMachineCasingModel((provider) -> model.accept(casing, provider));
return casing;
}

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

public MachineCasing registerCubeBottomTop(String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top)
public MachineCasing registerCubeBottomTop(String id, String englishName, ResourceLocation side, ResourceLocation bottom, ResourceLocation top)
{
return this.register(name, (casing, provider) -> provider.cubeBottomTop(casing, side, bottom, top));
return this.register(id, englishName, (casing, provider) -> provider.cubeBottomTop(casing, side, bottom, top));
}

public MachineCasing registerCubeAll(String name, ResourceLocation side)
public MachineCasing registerCubeAll(String id, String englishName, ResourceLocation side)
{
return this.register(name, (casing, provider) -> provider.cubeAll(casing, side));
return this.register(id, englishName, (casing, provider) -> provider.cubeAll(casing, side));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

public abstract class BasicMultiblockMachineBlockEntity extends MultiblockMachineBlockEntity implements Tickable, MultiblockInventoryComponentHolder
{
protected ShapeMatcher shapeMatcher;

protected OperatingState operatingState = OperatingState.NOT_MATCHED;

protected final ActiveShapeComponent activeShape;
protected final MultiblockInventoryComponent inventory;
protected final IsActiveComponent isActive;
Expand All @@ -41,80 +37,26 @@ protected void updateActive(boolean active)
isActive.updateActive(active, this);
}

public void onLink(ShapeMatcher shapeMatcher)
{
}

public void onUnlink(ShapeMatcher shapeMatcher)
{
}

public void onSuccessfulMatch(ShapeMatcher shapeMatcher)
@Override
protected void onRematch(ShapeMatcher shapeMatcher)
{
if(shapeMatcher.isMatchSuccessful())
{
inventory.rebuild(shapeMatcher);
}
}

@Override
public void tick()
{
if(level.isClientSide)
if(level.isClientSide())
{
return;
}

this.link();
}

protected ShapeMatcher createShapeMatcher()
{
return new ShapeMatcher(level, worldPosition, orientation.facingDirection, this.getActiveShape());
}

protected void link()
{
if(shapeMatcher == null)
{
shapeMatcher = this.createShapeMatcher();
shapeMatcher.registerListeners(level);

this.onLink(shapeMatcher);
}
if(shapeMatcher.needsRematch())
{
operatingState = OperatingState.NOT_MATCHED;
shapeValid.shapeValid = false;
shapeMatcher.rematch(level);

if(shapeMatcher.isMatchSuccessful())
{
inventory.rebuild(shapeMatcher);

this.onSuccessfulMatch(shapeMatcher);

shapeValid.shapeValid = true;
operatingState = OperatingState.TRYING_TO_RESUME;
}

if(shapeValid.update())
{
this.sync(false);
}
}
}

@Override
public void unlink()
{
if(shapeMatcher != null)
{
shapeMatcher.unlinkHatches();
shapeMatcher.unregisterListeners(level);

this.onUnlink(shapeMatcher);

shapeMatcher = null;
}
}

@Override
public ShapeTemplate getActiveShape()
{
Expand All @@ -138,21 +80,4 @@ protected MachineModelClientData getMachineModelData()
{
return new MachineModelClientData(null, orientation.facingDirection).active(isActive.isActive);
}

public enum OperatingState
{
/**
* Shape is not matched, don't do anything.
*/
NOT_MATCHED,
/**
* Trying to resume a recipe but the output might not fit anymore.
* We wait until the output fits again before resuming normal operation.
*/
TRYING_TO_RESUME,
/**
* Normal operation.
*/
NORMAL_OPERATION
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public List<? extends EnergyAccess> getEnergyComponents()
}

@Override
public void onSuccessfulMatch(ShapeMatcher shapeMatcher)
protected void onRematch(ShapeMatcher shapeMatcher)
{
super.onRematch(shapeMatcher);

energyInputs.clear();
for(HatchBlockEntity hatch : shapeMatcher.getMatchedHatches())
{
Expand All @@ -83,15 +85,15 @@ protected ItemInteractionResult useItemOn(Player player, InteractionHand hand, D
}
if(!result.consumesAction())
{
result = this.mapComponentOrDefault(UpgradeComponent.class, upgrade -> upgrade.onUse(this, player, hand), result);
result = components.mapOrDefault(UpgradeComponent.class, upgrade -> upgrade.onUse(this, player, hand), result);
}
if(!result.consumesAction())
{
result = redstoneControl.onUse(this, player, hand);
}
if(!result.consumesAction())
{
result = this.mapComponentOrDefault(OverdriveComponent.class, (overdrive) -> overdrive.onUse(this, player, hand), result);
result = components.mapOrDefault(OverdriveComponent.class, (overdrive) -> overdrive.onUse(this, player, hand), result);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import aztech.modern_industrialization.machines.BEP;
import aztech.modern_industrialization.machines.gui.MachineGuiParameters;
import aztech.modern_industrialization.machines.guicomponents.ReiSlotLocking;
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
import aztech.modern_industrialization.machines.recipe.MachineRecipeType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.server.level.ServerLevel;
import net.swedz.tesseract.neoforge.compat.mi.component.craft.ModularCrafterAccessBehavior;
import net.swedz.tesseract.neoforge.compat.mi.component.craft.multiplied.EuCostTransformer;
import net.swedz.tesseract.neoforge.compat.mi.component.craft.multiplied.MultipliedCrafterComponent;
Expand All @@ -21,6 +22,8 @@ public abstract class AbstractMultipliedCraftingMultiblockBlockEntity extends Ba
{
protected final MultipliedCrafterComponent crafter;

protected OperatingState operatingState = OperatingState.NOT_MATCHED;

public AbstractMultipliedCraftingMultiblockBlockEntity(BEP bep, ResourceLocation id, ShapeTemplate[] shapeTemplates)
{
super(bep, new MachineGuiParameters.Builder(id, false).backgroundHeight(200).build(), shapeTemplates);
Expand Down Expand Up @@ -55,9 +58,9 @@ public CrafterAccess getCrafterComponent()
}

@Override
public Level getCrafterWorld()
public ServerLevel getCrafterWorld()
{
return level;
return (ServerLevel) level;
}

@Override
Expand All @@ -66,6 +69,18 @@ public UUID getOwnerUuid()
return placedBy.placerId;
}

@Override
protected void onRematch(ShapeMatcher shapeMatcher)
{
super.onRematch(shapeMatcher);

operatingState = OperatingState.NOT_MATCHED;
if(shapeMatcher.isMatchSuccessful())
{
operatingState = OperatingState.TRYING_TO_RESUME;
}
}

@Override
public void tick()
{
Expand Down Expand Up @@ -104,4 +119,21 @@ public void tick()
public void tickExtra()
{
}

public enum OperatingState
{
/**
* Shape is not matched, don't do anything.
*/
NOT_MATCHED,
/**
* Trying to resume a recipe but the output might not fit anymore.
* We wait until the output fits again before resuming normal operation.
*/
TRYING_TO_RESUME,
/**
* Normal operation.
*/
NORMAL_OPERATION
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public AbstractSteamMultipliedCraftingMultiblockBlockEntity(BEP bep, ResourceLoc
}

@Override
public void onSuccessfulMatch(ShapeMatcher shapeMatcher)
protected void onRematch(ShapeMatcher shapeMatcher)
{
super.onRematch(shapeMatcher);

steel = false;
for(HatchBlockEntity hatch : shapeMatcher.getMatchedHatches())
{
Expand Down
Loading