Skip to content

Commit

Permalink
- Structure Preview now expands the menu by default.
Browse files Browse the repository at this point in the history
- Fixed the problem of incorrectly judging space for scrollbars.
- Optimised performance of MEItemBus / MEFluidBus / MEGasBus.
- Added gas judgement to InfItemFluidHandler#isEmpty.
- Fix typos.
  • Loading branch information
KasumiNova committed Oct 2, 2024
1 parent bd41c13 commit f7716a1
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 57 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.2"
version = "2.0.3"

// 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 @@ -103,6 +103,14 @@ protected void mouseClicked(final int mouseX, final int mouseY, final int mouseB
super.mouseClicked(mouseX, mouseY, mouseButton);
}

@Override
protected void mouseClickMove(final int mouseX, final int mouseY, final int mouseButton, final long timeSinceLastClick) {
if (widgetController.onMouseClickMove(new MousePos(mouseX, mouseY), mouseButton)) {
return;
}
super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
}

@Override
protected void mouseReleased(final int mouseX, final int mouseY, final int state) {
if (widgetController.onMouseReleased(new MousePos(mouseX, mouseY))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public boolean onMouseClick(final MousePos mousePos, final RenderPos renderPos,
return false;
}
RenderPos scrollbarRenderPos = new RenderPos(
width - (scrollbar.getMarginLeft() + scrollbar.getWidth() + scrollbar.getMarginRight()),
height - (scrollbar.getMarginUp() + scrollbar.getHeight() + scrollbar.getMarginDown()));
width - (scrollbar.getWidth() + scrollbar.getMarginRight()),
height - (scrollbar.getHeight() + scrollbar.getMarginDown()));
MousePos scrollbarRelativeMousePos = mousePos.relativeTo(scrollbarRenderPos);
if (scrollbar.isMouseOver(scrollbarRelativeMousePos)) {
return scrollbar.onMouseClick(scrollbarRelativeMousePos, renderPos.add(scrollbarRenderPos), mouseButton);
Expand Down Expand Up @@ -183,7 +183,7 @@ public boolean onMouseClickMove(final MousePos mousePos, final RenderPos renderP
}
RenderPos scrollbarRenderPos = new RenderPos(
width - (scrollbar.getWidth() + scrollbar.getMarginRight()),
height - (scrollbar.getMarginUp() + scrollbar.getHeight() + scrollbar.getMarginDown()));
height - (scrollbar.getHeight() + scrollbar.getMarginDown()));
return scrollbar.onMouseClickMove(mousePos.relativeTo(scrollbarRenderPos), renderPos.add(scrollbarRenderPos), mouseButton);
}

Expand Down Expand Up @@ -214,7 +214,7 @@ public boolean onMouseReleased(final MousePos mousePos, final RenderPos renderPo
}
RenderPos scrollbarRenderPos = new RenderPos(
width - (scrollbar.getWidth() + scrollbar.getMarginRight()),
height - (scrollbar.getMarginUp() + scrollbar.getHeight() + scrollbar.getMarginDown()));
height - (scrollbar.getHeight() + scrollbar.getMarginDown()));
return scrollbar.onMouseReleased(mousePos.relativeTo(scrollbarRenderPos), renderPos.add(scrollbarRenderPos));
}

Expand Down Expand Up @@ -246,7 +246,7 @@ public boolean onMouseDWheel(final MousePos mousePos, final RenderPos renderPos,
if (isMouseOver(mousePos)) {
RenderPos scrollbarRenderPos = new RenderPos(
width - (scrollbar.getWidth() + scrollbar.getMarginRight()),
height - (scrollbar.getMarginUp() + scrollbar.getHeight() + scrollbar.getMarginDown()));
height - (scrollbar.getHeight() + scrollbar.getMarginDown()));
MousePos scrollbarRelativeMousePos = mousePos.relativeTo(scrollbarRenderPos);
return scrollbar.onMouseDWheel(scrollbarRelativeMousePos, renderPos.add(scrollbarRenderPos), wheel);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ public List<String> getHoverTooltips(final WidgetGui widgetGui, final MousePos m

RenderPos scrollbarRenderPos = new RenderPos(
width - (scrollbar.getWidth() + scrollbar.getMarginRight()),
height - (scrollbar.getMarginUp() + scrollbar.getHeight() + scrollbar.getMarginDown()));
height - (scrollbar.getHeight() + scrollbar.getMarginDown()));
MousePos scrollbarMousePos = mousePos.relativeTo(scrollbarRenderPos);
if (scrollbar.isMouseOver(scrollbarMousePos)) {
List<String> hoverTooltips = scrollbar.getHoverTooltips(widgetGui, scrollbarMousePos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ public MachineStructurePreviewPanel(final DynamicMachine machine) {
Row bottomMenu = new Row();
if (!machine.getDynamicPatterns().isEmpty()) {
bottomMenu.addWidgets(
dynamicPatternPlus.setMarginRight(2).setDisabled(true),
dynamicPatternSubtract.setMarginRight(2).setDisabled(true)
dynamicPatternPlus.setMarginRight(2),
dynamicPatternSubtract.setMarginRight(2)
);
}
bottomMenu.addWidgets(
placeWorldPreview.setMarginRight(2).setDisabled(true),
enableCycleReplaceableBlocks.setClicked(true).setMarginRight(2).setDisabled(true),
toggleLayerRender.setMarginRight(2).setDisabled(true),
menuBtn.setMarginRight(2)
placeWorldPreview.setMarginRight(2),
enableCycleReplaceableBlocks.setClicked(true).setMarginRight(2),
toggleLayerRender.setMarginRight(2),
menuBtn.setClicked(true).setMarginRight(2)
);
bottomMenu.setAbsXY(PANEL_WIDTH - (bottomMenu.getWidth() + 6), 161);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class ModelBufferSize {

// 6 Faces, 4 Vertexes
private static final int BYTES_PER_CUBE = MachineControllerRenderer.VERTEX_FORMAT.getSize() * (6 * 4);

private int bufferSize = BYTES_PER_CUBE; // preventing last grow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.locks.ReadWriteLock;

public class MEItemInputBus extends MEItemBus {
// A simple cache for AEItemStack.
private static final Map<ItemStack, IAEItemStack> AE_STACK_CACHE = new WeakHashMap<>();
private IOInventory configInventory = buildConfigInventory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
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 @@ -49,7 +47,7 @@ public abstract class MEFluidBus extends MEMachineComponent implements
protected final UpgradeInventory upgrades;
protected final AEFluidInventoryUpgradeable tanks;
protected boolean[] changedSlots;
protected int fullCheckCounter = 5;
protected long lastFullCheckTick = 0;
protected boolean inTick = false;

public MEFluidBus() {
Expand All @@ -59,16 +57,12 @@ public MEFluidBus() {
}

protected synchronized int[] getNeedUpdateSlots() {
fullCheckCounter++;
if (fullCheckCounter >= 5) {
fullCheckCounter = 0;
long current = world.getTotalWorldTime();
if (lastFullCheckTick + 100 < current) {
lastFullCheckTick = current;
return IntStream.range(0, tanks.getSlots()).toArray();
}
IntList list = new IntArrayList();
IntStream.range(0, changedSlots.length)
.filter(i -> changedSlots[i])
.forEach(list::add);
return list.toIntArray();
return IntStream.range(0, changedSlots.length).filter(i -> changedSlots[i]).toArray();
}

public IAEFluidTank getTanks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
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 @@ -48,7 +46,7 @@ public abstract class MEGasBus extends MEMachineComponent implements
protected final GasInventory tanks;
protected final GasInventoryHandler handler;
protected boolean[] changedSlots;
protected int fullCheckCounter = 5;
protected long lastFullCheckTick = 0;

protected boolean inTick = false;

Expand All @@ -60,16 +58,12 @@ public MEGasBus() {
}

protected synchronized int[] getNeedUpdateSlots() {
fullCheckCounter++;
if (fullCheckCounter >= 5) {
fullCheckCounter = 0;
long current = world.getTotalWorldTime();
if (lastFullCheckTick + 100 < current) {
lastFullCheckTick = current;
return IntStream.range(0, tanks.size()).toArray();
}
IntList list = new IntArrayList();
IntStream.range(0, changedSlots.length)
.filter(i -> changedSlots[i])
.forEach(list::add);
return list.toArray(new int[0]);
return IntStream.range(0, changedSlots.length).filter(i -> changedSlots[i]).toArray();
}

public GasInventory getTanks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
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 All @@ -26,22 +24,19 @@ public abstract class MEItemBus extends MEMachineComponent implements IGridTicka

protected IOInventory inventory = buildInventory();
protected boolean[] changedSlots = new boolean[inventory.getSlots()];
protected int fullCheckCounter = 5;
protected int[] failureCounter = new int[inventory.getSlots()];
protected long lastFullCheckTick = 0;
protected boolean inTick = false;

public abstract IOInventory buildInventory();

protected synchronized int[] getNeedUpdateSlots() {
fullCheckCounter++;
if (fullCheckCounter >= 5) {
fullCheckCounter = 0;
long current = world.getTotalWorldTime();
if (lastFullCheckTick + 100 < current) {
lastFullCheckTick = current;
return IntStream.range(0, inventory.getSlots()).toArray();
}
IntList list = new IntArrayList();
IntStream.range(0, changedSlots.length)
.filter(i -> changedSlots[i])
.forEach(list::add);
return list.toIntArray();
return IntStream.range(0, changedSlots.length).filter(i -> changedSlots[i]).toArray();
}

public IOInventory getInternalInventory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ public int getSlotLimit(final int slot) {
}

public boolean isEmpty() {
return itemStackList.stream().allMatch(ItemStack::isEmpty) && fluidStackList.stream().allMatch(Objects::isNull);
return itemStackList.stream().allMatch(ItemStack::isEmpty) &&
fluidStackList.stream().allMatch(Objects::isNull) &&
gasStackList.stream().allMatch(Objects::isNull);
}

public List<ItemStack> getItemStackList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,11 @@ public RecipePrimer addGasPerTickOutputs(IGasStack... gasStacks) {
@ZenMethod
public RecipePrimer addItemInput(IIngredient input) {
if (input instanceof IItemStack) {
requireFuel(IOType.INPUT, (IItemStack) input);
requireItem(IOType.INPUT, (IItemStack) input);
} else if (input instanceof IOreDictEntry) {
requireFuel(IOType.INPUT, ((IOreDictEntry) input).getName(), 1);
requireItem(IOType.INPUT, ((IOreDictEntry) input).getName(), 1);
} else if (input instanceof IngredientStack && input.getInternal() instanceof IOreDictEntry) {
requireFuel(IOType.INPUT, ((IOreDictEntry) input.getInternal()).getName(), input.getAmount());
requireItem(IOType.INPUT, ((IOreDictEntry) input.getInternal()).getName(), input.getAmount());
} else {
CraftTweakerAPI.logError(String.format("[ModularMachinery] Invalid input type %s(%s)! Ignored.", input, input.getClass()));
}
Expand All @@ -621,7 +621,7 @@ public RecipePrimer addItemInput(IIngredient input) {
@Deprecated
@ZenMethod
public RecipePrimer addItemInput(IOreDictEntry oreDict, int amount) {
requireFuel(IOType.INPUT, oreDict.getName(), amount);
requireItem(IOType.INPUT, oreDict.getName(), amount);
CraftTweakerAPI.logWarning(String.format("[ModularMachinery] Deprecated method " +
"`addItemInput(<ore:%s>, %s)`! Consider using `addItemInput(<ore:%s> * %s)`",
oreDict.getName(), amount, oreDict.getName(), amount)
Expand Down Expand Up @@ -667,11 +667,11 @@ public RecipePrimer addRandomItemOutput(IngredientArrayPrimer ingredientArrayPri
@ZenMethod
public RecipePrimer addItemOutput(IIngredient output) {
if (output instanceof IItemStack) {
requireFuel(IOType.OUTPUT, (IItemStack) output);
requireItem(IOType.OUTPUT, (IItemStack) output);
} else if (output instanceof IOreDictEntry) {
requireFuel(IOType.OUTPUT, ((IOreDictEntry) output).getName(), 1);
requireItem(IOType.OUTPUT, ((IOreDictEntry) output).getName(), 1);
} else if (output instanceof IngredientStack && output.getInternal() instanceof IOreDictEntry) {
requireFuel(IOType.OUTPUT, ((IOreDictEntry) output.getInternal()).getName(), output.getAmount());
requireItem(IOType.OUTPUT, ((IOreDictEntry) output.getInternal()).getName(), output.getAmount());
} else {
CraftTweakerAPI.logError(String.format("[ModularMachinery] Invalid output type %s(%s)! Ignored.", output, output.getClass()));
}
Expand All @@ -682,7 +682,7 @@ public RecipePrimer addItemOutput(IIngredient output) {
@Deprecated
@ZenMethod
public RecipePrimer addItemOutput(IOreDictEntry oreDict, int amount) {
requireFuel(IOType.OUTPUT, oreDict.getName(), amount);
requireItem(IOType.OUTPUT, oreDict.getName(), amount);
CraftTweakerAPI.logWarning(String.format("[ModularMachinery] Deprecated method " +
"`addItemOutput(<ore:%s>, %s)`! Consider using `addItemOutput(<ore:%s> * %s)`",
oreDict.getName(), amount, oreDict.getName(), amount)
Expand Down Expand Up @@ -786,7 +786,7 @@ private void requireFuel(int requiredTotalBurnTime) {
appendComponent(new RequirementItem(IOType.INPUT, requiredTotalBurnTime));
}

private void requireFuel(IOType ioType, IItemStack stack) {
private void requireItem(IOType ioType, IItemStack stack) {
ItemStack mcStack = CraftTweakerMC.getItemStack(stack);
if (mcStack.isEmpty()) {
CraftTweakerAPI.logError("[ModularMachinery] ItemStack not found/unknown item: " + stack.toString());
Expand All @@ -800,7 +800,7 @@ private void requireFuel(IOType ioType, IItemStack stack) {
appendComponent(ri);
}

private void requireFuel(IOType ioType, String oreDictName, int amount) {
private void requireItem(IOType ioType, String oreDictName, int amount) {
appendComponent(new RequirementItem(ioType, oreDictName, amount));
}

Expand Down

0 comments on commit f7716a1

Please sign in to comment.