Skip to content

Commit

Permalink
- Add MEPatternProvider enhanced blocking mode.
Browse files Browse the repository at this point in the history
- MEItemBus / MEFluidBus performance improvements.
  • Loading branch information
KasumiNova committed Oct 9, 2024
1 parent b851778 commit 6d3a273
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {

// Project properties
group = "hellfirepvp.modularmachinery"
version = "2.0.3"
version = "2.1.0"

// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public GuiMEPatternProvider(final MEPatternProvider owner, final EntityPlayer pl
.addElement(MEPatternProvider.WorkModeSetting.BLOCKING_MODE, TextureProperties.of(140 + 18, 196, 16, 16))
// ButtonTexture 3
.addElement(MEPatternProvider.WorkModeSetting.CRAFTING_LOCK_MODE, TextureProperties.of(140 + 18 + 18, 196, 16, 16))
// ButtonTexture 0
.addElement(MEPatternProvider.WorkModeSetting.ENHANCED_BLOCKING_MODE, TextureProperties.of(140 - 18, 196, 16, 16))
// ButtonTexture 5
.setMouseDownTexture(140 + 18 + 18 + 18 + 18 + 18, 196)
// ButtonTexture 5
Expand All @@ -123,6 +125,8 @@ public GuiMEPatternProvider(final MEPatternProvider owner, final EntityPlayer pl
+ I18n.format("gui.mepatternprovider.blocking_mode.desc"));
tooltips.add((current == MEPatternProvider.WorkModeSetting.CRAFTING_LOCK_MODE ? I18n.format("gui.mepatternprovider.current") : "")
+ I18n.format("gui.mepatternprovider.crafting_lock_mode.desc"));
tooltips.add((current == MEPatternProvider.WorkModeSetting.ENHANCED_BLOCKING_MODE ? I18n.format("gui.mepatternprovider.current") : "")
+ I18n.format("gui.mepatternprovider.enhanced_blocking_mode.desc"));
return tooltips;
})
.setOnClickedListener((btn) -> {
Expand All @@ -132,8 +136,9 @@ public GuiMEPatternProvider(final MEPatternProvider owner, final EntityPlayer pl
}
switch (current) {
case DEFAULT -> ModularMachinery.NET_CHANNEL.sendToServer(new PktMEPatternProviderAction(PktMEPatternProviderAction.Action.ENABLE_DEFAULT_MODE));
case BLOCKING_MODE ->ModularMachinery.NET_CHANNEL.sendToServer(new PktMEPatternProviderAction(PktMEPatternProviderAction.Action.ENABLE_BLOCKING_MODE));
case BLOCKING_MODE -> ModularMachinery.NET_CHANNEL.sendToServer(new PktMEPatternProviderAction(PktMEPatternProviderAction.Action.ENABLE_BLOCKING_MODE));
case CRAFTING_LOCK_MODE -> ModularMachinery.NET_CHANNEL.sendToServer(new PktMEPatternProviderAction(PktMEPatternProviderAction.Action.ENABLE_CRAFTING_LOCK_MODE));
case ENHANCED_BLOCKING_MODE -> ModularMachinery.NET_CHANNEL.sendToServer(new PktMEPatternProviderAction(PktMEPatternProviderAction.Action.ENABLE_ENHANCED_BLOCKING_MODE));
}
})
.setWidthHeight(16, 16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public IMessage onMessage(final PktMEPatternProviderAction message, final Messag
case ENABLE_BLOCKING_MODE -> provider.setWorkMode(MEPatternProvider.WorkModeSetting.BLOCKING_MODE);
case ENABLE_DEFAULT_MODE -> provider.setWorkMode(MEPatternProvider.WorkModeSetting.DEFAULT);
case ENABLE_CRAFTING_LOCK_MODE -> provider.setWorkMode(MEPatternProvider.WorkModeSetting.CRAFTING_LOCK_MODE);
case ENABLE_ENHANCED_BLOCKING_MODE -> provider.setWorkMode(MEPatternProvider.WorkModeSetting.ENHANCED_BLOCKING_MODE);
case RETURN_ITEMS -> provider.returnItemsScheduled();
}
});
Expand All @@ -52,6 +53,7 @@ public enum Action {
ENABLE_BLOCKING_MODE,
ENABLE_DEFAULT_MODE,
ENABLE_CRAFTING_LOCK_MODE,
ENABLE_ENHANCED_BLOCKING_MODE,
RETURN_ITEMS,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,13 @@ public TickRateModulation tickingRequest(@Nonnull final IGridNode node, final in
int countToReceive = cfgStack.getCount() - invStack.getCount();
ItemStack stack = extractStackFromAE(inv, ItemUtils.copyStackWithSize(invStack, countToReceive));
if (!stack.isEmpty()) {
inventory.setStackInSlot(slot, ItemUtils.copyStackWithSize(
invStack, invStack.getCount() + stack.getCount())
);
int newCount = invStack.getCount() + stack.getCount();
inventory.setStackInSlot(slot, ItemUtils.copyStackWithSize(invStack, newCount));
successAtLeastOnce = true;
failureCounter[slot] = 0;
} else {
// If AE doesn't have enough item?
failureCounter[slot]++;
}
} else {
int countToExtract = invStack.getCount() - cfgStack.getCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class MEPatternProvider extends MEMachineComponent implements ICraftingPr
protected boolean shouldReturnItems = false;
protected boolean handlerDirty = false;

protected int currentPatternIdx = -1;
protected ICraftingPatternDetails currentPattern = null;

public MEPatternProvider() {
// Initialize details...
IntStream.range(0, 36).<ICraftingPatternDetails>mapToObj(i -> null).forEach(details::add);
Expand Down Expand Up @@ -151,7 +154,7 @@ public void provideCrafting(final ICraftingProviderHelper craftingTracker) {

@Override
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final InventoryCrafting table) {
if (patternDetails.isCraftable() || !proxy.isActive() || !proxy.isPowered()) {
if (!acceptsPattern(patternDetails)) {
return false;
}

Expand Down Expand Up @@ -180,10 +183,29 @@ public boolean pushPattern(final ICraftingPatternDetails patternDetails, final I
handler.appendItem(stackInSlot);
}

handleNewPattern(patternDetails);
machineCompleted = workMode != WorkModeSetting.CRAFTING_LOCK_MODE;
return true;
}

private boolean acceptsPattern(final ICraftingPatternDetails patternDetails) {
if (patternDetails.isCraftable() || !proxy.isActive() || !proxy.isPowered()) {
return false;
}
// If workMode is Enhanced Blocking Mode, and the handler is not empty, and the current pattern is not the same as the new pattern, return false.
return workMode != WorkModeSetting.ENHANCED_BLOCKING_MODE || handler.isEmpty() || currentPattern == null || currentPattern.equals(patternDetails);
}

private void handleNewPattern(final ICraftingPatternDetails patternDetails) {
if (workMode == WorkModeSetting.ENHANCED_BLOCKING_MODE) {
if (!patternDetails.equals(currentPattern)) {
setCurrentPattern(patternDetails);
}
} else {
resetCurrentPattern();
}
}

@Override
public void notifyNeighbors() {
if (this.getProxy().isActive()) {
Expand All @@ -206,6 +228,9 @@ protected void refreshPatterns() {
for (int i = 0; i < PATTERNS; i++) {
refreshPattern(i);
}
if (currentPatternIdx != -1 && currentPatternIdx < details.size()) {
setCurrentPattern(details.get(currentPatternIdx));
}
try {
this.getProxy().getGrid().postEvent(new MENetworkCraftingPatternChange(this, this.getProxy().getNode()));
} catch (GridAccessException ignored) {
Expand All @@ -225,6 +250,10 @@ protected void refreshPattern(final int slot) {
if (detail != null && !detail.isCraftable()) {
details.set(slot, detail);
}

if (workMode == WorkModeSetting.ENHANCED_BLOCKING_MODE && slot == currentPatternIdx && !currentPattern.equals(detail)) {
resetCurrentPattern();
}
}

public void returnItemsScheduled() {
Expand Down Expand Up @@ -315,6 +344,20 @@ private <T extends IAEStack<T>> T insertStackToAE(final IMEMonitor<T> inv, final
return Platform.poweredInsert(proxy.getEnergy(), inv, stack.copy(), source);
}

private void resetCurrentPattern() {
currentPatternIdx = -1;
currentPattern = null;
}

private void setCurrentPattern(final ICraftingPatternDetails pattern) {
if (pattern == null) {
resetCurrentPattern();
return;
}
currentPatternIdx = details.indexOf(pattern);
currentPattern = pattern;
}

public AppEngInternalInventory getSubItemHandler() {
return subItemHandler;
}
Expand All @@ -340,6 +383,9 @@ public void setWorkMode(final WorkModeSetting workMode) {
if (workMode != WorkModeSetting.CRAFTING_LOCK_MODE) {
this.machineCompleted = true;
}
if (workMode != WorkModeSetting.ENHANCED_BLOCKING_MODE) {
resetCurrentPattern();
}
}

@Override
Expand Down Expand Up @@ -375,8 +421,11 @@ public void readProviderNBT(final NBTTagCompound compound) {
handler.readFromNBT(compound, "handler");
patterns.readFromNBT(compound, "patterns");
workMode = WorkModeSetting.values()[compound.getByte("workMode")];
if (compound.hasKey("blockingMode") && compound.getBoolean("blockingMode")) {
workMode = WorkModeSetting.BLOCKING_MODE;

if (compound.hasKey("currentPatternIdx") && workMode == WorkModeSetting.ENHANCED_BLOCKING_MODE) {
currentPatternIdx = compound.getByte("currentPatternIdx");
} else {
resetCurrentPattern();
}
}

Expand All @@ -395,6 +444,9 @@ public NBTTagCompound writeProviderNBT(final NBTTagCompound compound) {
if (workMode != WorkModeSetting.DEFAULT) {
compound.setByte("workMode", (byte) workMode.ordinal());
}
if (!handler.isEmpty() && currentPatternIdx != -1) {
compound.setByte("currentPatternIdx", (byte) currentPatternIdx);
}
return compound;
}

Expand Down Expand Up @@ -493,6 +545,7 @@ public enum WorkModeSetting {
DEFAULT,
BLOCKING_MODE,
CRAFTING_LOCK_MODE,
ENHANCED_BLOCKING_MODE,
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import github.kasuminova.mmce.common.util.AEFluidInventoryUpgradeable;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
Expand Down Expand Up @@ -62,7 +64,14 @@ protected synchronized int[] getNeedUpdateSlots() {
lastFullCheckTick = current;
return IntStream.range(0, tanks.getSlots()).toArray();
}
return IntStream.range(0, changedSlots.length).filter(i -> changedSlots[i]).toArray();
IntList needUpdateSlots = new IntArrayList(changedSlots.length + 1);
int bound = changedSlots.length;
for (int i = 0; i < bound; i++) {
if (changedSlots[i]) {
needUpdateSlots.add(i);
}
}
return needUpdateSlots.toIntArray();
}

public IAEFluidTank getTanks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.mekeng.github.common.me.inventory.impl.GasInventory;
import com.mekeng.github.common.me.storage.IGasStorageChannel;
import github.kasuminova.mmce.common.util.GasInventoryHandler;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import mekanism.api.gas.IGasHandler;
import mekanism.common.capabilities.Capabilities;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -63,7 +65,14 @@ protected synchronized int[] getNeedUpdateSlots() {
lastFullCheckTick = current;
return IntStream.range(0, tanks.size()).toArray();
}
return IntStream.range(0, changedSlots.length).filter(i -> changedSlots[i]).toArray();
IntList needUpdateSlots = new IntArrayList(changedSlots.length + 1);
int bound = changedSlots.length;
for (int i = 0; i < bound; i++) {
if (changedSlots[i]) {
needUpdateSlots.add(i);
}
}
return needUpdateSlots.toIntArray();
}

public GasInventory getTanks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.storage.channels.IItemStorageChannel;
import hellfirepvp.modularmachinery.common.util.IOInventory;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
Expand Down Expand Up @@ -36,7 +38,14 @@ protected synchronized int[] getNeedUpdateSlots() {
lastFullCheckTick = current;
return IntStream.range(0, inventory.getSlots()).toArray();
}
return IntStream.range(0, changedSlots.length).filter(i -> changedSlots[i]).toArray();
IntList needUpdateSlots = new IntArrayList(changedSlots.length + 1);
int bound = changedSlots.length;
for (int i = 0; i < bound; i++) {
if (changedSlots[i] && failureCounter[i] <= 0) {
needUpdateSlots.add(i);
}
}
return needUpdateSlots.toIntArray();
}

public IOInventory getInternalInventory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ public void writeToNBT(final NBTTagCompound tag, final String subTagName) {
tag.setTag(subTagName, subTag);
}


public void readFromNBT(final NBTTagCompound tag, final String subTagName) {
NBTTagCompound subTag = tag.getCompoundTag(subTagName);
fluidStackList.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
"after:tconstruct@[1.12.2-2.12.0.157,);" +
"after:thermalexpansion@[5.5.0,);",
acceptedMinecraftVersions = "[1.12, 1.13)",
acceptableRemoteVersions = "[2.0.0, 2.1.0)"
acceptableRemoteVersions = "[2.1.0, 2.2.0)"
)
public class ModularMachinery {

public static final String MODID = "modularmachinery";
public static final String NAME = "Modular Machinery: Community Edition";
public static final String VERSION = "2.0.0";
public static final String VERSION = Tags.VERSION;
public static final String CLIENT_PROXY = "hellfirepvp.modularmachinery.client.ClientProxy";
public static final String COMMON_PROXY = "hellfirepvp.modularmachinery.common.CommonProxy";
public static final SimpleNetworkWrapper NET_CHANNEL = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/modularmachinery/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ gui.mepatternprovider.current=§a[Currently Enabled]
gui.mepatternprovider.default.desc=Default: The provider works normally.
gui.mepatternprovider.crafting_lock_mode.desc=Crafting Lock Mode: Items will only continue to be stored when the machine completes the recipe.
gui.mepatternprovider.blocking_mode.desc=Blocking Mode: Items will not continue to be stored when there are items in the provider.
gui.mepatternprovider.work_mode.desc=Provider work mode (Click to switch between the 3 modes):
gui.mepatternprovider.enhanced_blocking_mode.desc=Enhanced Blocking Mode: builds on the blocking mode so that the current recipe can still continue to store items.
gui.mepatternprovider.work_mode.desc=Provider work mode (Click to switch between the 4 modes):
gui.mepatternprovider.return_items=Return Items
gui.mepatternprovider.return_items.desc=Return all items and fluids in the provider to the ME network. This will reset the state of the Crafting Lock Mode.

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/modularmachinery/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ gui.mepatternprovider.current=§a[当前启用]
gui.mepatternprovider.default.desc=默认:供应器正常工作。
gui.mepatternprovider.crafting_lock_mode.desc=合成锁定模式:只有当机器完成配方时才会继续存储物品。
gui.mepatternprovider.blocking_mode.desc=阻挡模式:供应器内含有物品时不继续存储物品。
gui.mepatternprovider.work_mode.desc=供应器工作模式(点击在三个模式中切换):
gui.mepatternprovider.enhanced_blocking_mode.desc=强化阻挡模式:在阻挡模式的基础上,使当前配方仍然可以继续存储物品。
gui.mepatternprovider.work_mode.desc=供应器工作模式(点击在四个模式中切换):
gui.mepatternprovider.return_items=清空物品
gui.mepatternprovider.return_items.desc=将供应器中的所有物品和流体返还给 ME 网络,这会重置合成锁定模式的状态。
gui.mepatternprovider.nbt_stored=供应器已配置。
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6d3a273

Please sign in to comment.