Skip to content

Commit

Permalink
Mi/fixes (#979)
Browse files Browse the repository at this point in the history
* chore: update ldlib to 1.0.24.a

* refactor: remove async recipe searching

* fix: make UI titles only roll on hover

* fix: move titlebar text to center again

* refactor: early return in GTRecipe.handlerContentsInternal()

* fix: reintroduce combined inventory for item bus machines (temporary)

* fix: only roll multiblock part names on hover
  • Loading branch information
mikerooni authored Mar 23, 2024
1 parent 272bd1d commit 95bcfcf
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 101 deletions.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencyResolutionManagement {
def vineFlowerVersion = "1.+"
def macheteVersion = "1.+"
def configurationVersion = "2.2.0"
def ldLibVersion = "1.0.23.a"
def ldLibVersion = "1.0.24.a"
def mixinextrasVersion = "0.2.0"
def shimmerVersion = "0.2.2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Widget createMainPage(FancyMachineUIWidget widget) {
new TextTexture(ChatFormatting.BLACK.toString() + page.getTitle().getString())
.setDropShadow(false)
.setWidth(118)
.setType(TextTexture.TextType.LEFT_ROLL_ALWAYS)
.setType(TextTexture.TextType.LEFT_ROLL)
));

scrollableGroup.addWidget(pageWidget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class TitleBarWidget extends WidgetGroup {
private static final int HEIGHT = 16;
private static final int BTN_WIDTH = 18;

// TODO make this work. The roll speed isn't getting applied currently and it's too fast.
private static final float ROLL_SPEED = 0.2f;
private static final float ROLL_SPEED = 0.7f;

private int width;
private boolean showBackButton = false;
Expand Down Expand Up @@ -80,7 +79,7 @@ public void updateState(IFancyUIProvider currentPage, boolean showBackButton, bo

titleText = new TextTexture(ChatFormatting.BLACK.toString() + currentPage.getTitle().copy().getString())
.setDropShadow(false)
.setType(TextTexture.TextType.ROLL_ALWAYS);
.setType(TextTexture.TextType.ROLL);
titleText.setRollSpeed(ROLL_SPEED);

tabIcon.setImage(currentPage.getTabIcon());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ public enum Status {
protected long totalContinuousRunningTime;
protected TickableSubscription subscription;
protected Object workingSound;
@Nullable
protected CompletableFuture<Boolean> completableFuture = null;
// if storage is dirty while async searching recipe, it will be set to true.
protected boolean dirtySearching = false;

public RecipeLogic(IRecipeLogicMachine machine) {
super(machine.self());
Expand Down Expand Up @@ -126,9 +122,6 @@ public void updateTickSubscription() {
}
} else {
subscription = getMachine().subscribeServerTick(subscription, this::serverTick);
if (completableFuture != null) {
dirtySearching = true;
}
}
}

Expand Down Expand Up @@ -176,11 +169,7 @@ public void serverTick() {
boolean unsubscribe = false;
if (isSuspend()) {
unsubscribe = true;
if (completableFuture != null) {
completableFuture.cancel(true);
completableFuture = null;
}
} else if (completableFuture == null && lastRecipe == null && isIdle() && !machine.keepSubscribing() && !recipeDirty && lastFailedMatches == null) {
} else if (lastRecipe == null && isIdle() && !machine.keepSubscribing() && !recipeDirty && lastFailedMatches == null) {
// machine isn't working enabled
// or
// there is no available recipes, so it will wait for notification.
Expand Down Expand Up @@ -270,56 +259,26 @@ public void findAndHandleRecipe() {
} else { // try to find and handle a new recipe
lastRecipe = null;
lastOriginRecipe = null;
if (completableFuture == null) {
// try to search recipe in threads.
if (ConfigHolder.INSTANCE.machines.asyncRecipeSearching) {
completableFuture = supplyAsyncSearchingTask();
} else {
handleSearchingRecipes(searchRecipe());
}
dirtySearching = false;
} else if (completableFuture.isDone()) {
var lastFuture = this.completableFuture;
completableFuture = null;
if (!lastFuture.isCancelled()) {
// if searching task is done, try to handle searched recipes.
try {
boolean matches = lastFuture.join();
if (!matches && dirtySearching) {
completableFuture = supplyAsyncSearchingTask();
}
} catch (Throwable throwable) {
// if error occurred, schedule a new async task.
completableFuture = supplyAsyncSearchingTask();
}
} else {
handleSearchingRecipes(searchRecipe());
}
dirtySearching = false;
}
handleSearchingRecipes(searchRecipe());
}
recipeDirty = false;
}

private CompletableFuture<Boolean> supplyAsyncSearchingTask() {
return CompletableFuture.supplyAsync(Util.wrapThreadWithTaskName("GTCEu Recipe Search", () -> handleSearchingRecipes(searchRecipe())), Util.backgroundExecutor());
}

private boolean handleSearchingRecipes(Iterator<GTRecipe> matches) {
private void handleSearchingRecipes(Iterator<GTRecipe> matches) {
while (matches != null && matches.hasNext()) {
GTRecipe match = matches.next();
if (match == null) continue;

// If a new recipe was found, cache found recipe.
if (checkMatchedRecipeAvailable(match)) return true;
if (checkMatchedRecipeAvailable(match))
return;

// cache matching recipes.
if (lastFailedMatches == null) {
lastFailedMatches = new ArrayList<>();
}
lastFailedMatches.add(match);
}
return false;
}

public boolean handleFuelRecipe() {
Expand Down
96 changes: 49 additions & 47 deletions src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,64 +269,66 @@ private Tuple<List, Map<String, List>> handlerContentsInternal(
RecipeCapability<?> capability, Set<IRecipeHandler<?>> used,
List content, Map<String, List> contentSlot,
List contentSearch, Map<String, List> contentSlotSearch,
boolean simulate) {
if (capabilityProxies.contains(capIO, capability)) {
var handlers = capabilityProxies.get(capIO, capability);
// handle distinct first
for (IRecipeHandler<?> handler : handlers) {
if (!handler.isDistinct()) continue;
var result = handler.handleRecipe(io, this, contentSearch, null, true);
if (result == null) {
// check distint slot handler
if (handler.getSlotNames() != null && handler.getSlotNames().containsAll(contentSlotSearch.keySet())) {
boolean success = true;
for (var entry : contentSlotSearch.entrySet()) {
List<?> left = handler.handleRecipe(io, this, entry.getValue(), entry.getKey(), true);
if (left != null) {
success = false;
break;
}
}
if (success) {
if (!simulate) {
for (var entry : contentSlot.entrySet()) {
handler.handleRecipe(io, this, entry.getValue(), entry.getKey(), false);
}
}
contentSlot.clear();
boolean simulate
) {
if (!capabilityProxies.contains(capIO, capability))
return new Tuple<>(content, contentSlot);

var handlers = capabilityProxies.get(capIO, capability);
// handle distinct first
for (IRecipeHandler<?> handler : handlers) {
if (!handler.isDistinct()) continue;
var result = handler.handleRecipe(io, this, contentSearch, null, true);
if (result == null) {
// check distint slot handler
if (handler.getSlotNames() != null && handler.getSlotNames().containsAll(contentSlotSearch.keySet())) {
boolean success = true;
for (var entry : contentSlotSearch.entrySet()) {
List<?> left = handler.handleRecipe(io, this, entry.getValue(), entry.getKey(), true);
if (left != null) {
success = false;
break;
}
}
if (contentSlot.isEmpty()) {
if (success) {
if (!simulate) {
handler.handleRecipe(io, this, content, null, false);
for (var entry : contentSlot.entrySet()) {
handler.handleRecipe(io, this, entry.getValue(), entry.getKey(), false);
}
}
content = null;
contentSlot.clear();
}
}
if (content == null && contentSlot.isEmpty()) {
break;
if (contentSlot.isEmpty()) {
if (!simulate) {
handler.handleRecipe(io, this, content, null, false);
}
content = null;
}
}
if (content != null || !contentSlot.isEmpty()) {
// handle undistinct later
for (IRecipeHandler<?> proxy : handlers) {
if (used.contains(proxy) || proxy.isDistinct()) continue;
used.add(proxy);
if (content != null) {
content = proxy.handleRecipe(io, this, content, null, simulate);
}
if (proxy.getSlotNames() != null) {
Iterator<String> iterator = contentSlot.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
if (proxy.getSlotNames().contains(key)) {
List<?> left = proxy.handleRecipe(io, this, contentSlot.get(key), key, simulate);
if (left == null) iterator.remove();
}
if (content == null && contentSlot.isEmpty()) {
break;
}
}
if (content != null || !contentSlot.isEmpty()) {
// handle undistinct later
for (IRecipeHandler<?> proxy : handlers) {
if (used.contains(proxy) || proxy.isDistinct()) continue;
used.add(proxy);
if (content != null) {
content = proxy.handleRecipe(io, this, content, null, simulate);
}
if (proxy.getSlotNames() != null) {
Iterator<String> iterator = contentSlot.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
if (proxy.getSlotNames().contains(key)) {
List<?> left = proxy.handleRecipe(io, this, contentSlot.get(key), key, simulate);
if (left == null) iterator.remove();
}
}
if (content == null && contentSlot.isEmpty()) break;
}
if (content == null && contentSlot.isEmpty()) break;
}
}
return new Tuple<>(content, contentSlot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ public class ItemBusPartMachine extends TieredIOPartMachine implements IDistinct
@Getter
@Persisted
protected final NotifiableItemStackHandler circuitInventory;
@Getter
protected final ItemHandlerProxyRecipeTrait combinedInventory;

public ItemBusPartMachine(IMachineBlockEntity holder, int tier, IO io, Object... args) {
super(holder, tier, io);
this.inventory = createInventory(args);
this.circuitInventory = createCircuitItemHandler(io);
this.combinedInventory = createCombinedItemHandler(io);
}

//////////////////////////////////////
Expand Down Expand Up @@ -89,6 +92,14 @@ protected NotifiableItemStackHandler createCircuitItemHandler(Object... args) {
}
}

protected ItemHandlerProxyRecipeTrait createCombinedItemHandler(Object... args) {
if (args.length > 0 && args[0] instanceof IO io && io == IO.IN) {
return new ItemHandlerProxyRecipeTrait(this, Set.of(getInventory(), circuitInventory), IO.IN, IO.NONE);
} else {
return new ItemHandlerProxyRecipeTrait(this, Set.of(getInventory(), circuitInventory), IO.NONE, IO.NONE);
}
}

@Override
public void onDrops(List<ItemStack> drops, Player entity) {
clearInventory(drops, getInventory().storage);
Expand All @@ -105,6 +116,8 @@ public void onLoad() {
serverLevel.getServer().tell(new TickTask(0, this::updateInventorySubscription));
}
inventorySubs = getInventory().addChangedListener(this::updateInventorySubscription);

combinedInventory.recomputeEnabledState();
}

@Override
Expand All @@ -125,6 +138,7 @@ public boolean isDistinct() {
public void setDistinct(boolean isDistinct) {
getInventory().setDistinct(isDistinct);
circuitInventory.setDistinct(isDistinct);
combinedInventory.setDistinct(isDistinct);
}

//////////////////////////////////////
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,6 @@ public static class MachineConfigs {
"Other mods can override this to true, regardless of the config file.",
"Default: false"})
public boolean highTierContent = false;
@Configurable
@Configurable.Comment({"Whether search for recipes asynchronously.", " Default: true"})
public boolean asyncRecipeSearching = true;
}

public static class ToolConfigs {
Expand Down

0 comments on commit 95bcfcf

Please sign in to comment.