Skip to content

Commit

Permalink
Robot arm cover (#192)
Browse files Browse the repository at this point in the history
* feat: basic UI for robot arm cover

* feat: adjust item filter display for better UI in robot arm

* fix: robot arm & conveyor UI fixes

* refactor: extract stack size inputs from robot arm & conveyor covers

* feat: icon buttons for robot arm & conveyor cover

icons for IO modes by @Irgendwer01

* refactor: move source & target matching up into ConveyorCover.update()

* feat: implement robot arm logic

Ported from 1.12

* fix: robot arm cover syncs correctly & respects global transfer limit

* feat: add tooltips to conveyor & robot arm selector buttons

* feat: update keep_exact.png to better reflect its transfer mode

* clean up

---------

Co-authored-by: KilaBash <yefancy@foxmail.com>
  • Loading branch information
mikerooni and Yefancy authored Jul 24, 2023
1 parent 46b7b35 commit 4fde739
Show file tree
Hide file tree
Showing 26 changed files with 791 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.gregtechceu.gtceu.api.capability.recipe;

import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture;
import com.lowdragmc.lowdraglib.gui.texture.ResourceTexture;

/**
* The capability can be input or output or both
*/
public enum IO {
IN,
OUT,
BOTH,
NONE;
IN("gtceu.io.import", "import"),
OUT("gtceu.io.export", "export"),
BOTH("gtceu.io.both", "both"),
NONE("gtceu.io.none", "none");

public final String localeName;
public final IGuiTexture icon;

IO(String localeName, String textureName) {
this.localeName = localeName;
this.icon = new ResourceTexture("gtceu:textures/gui/icon/io_mode/" + textureName + ".png");
}

public boolean support(IO io) {
if (io == this) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang3.NotImplementedException;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;

/**
Expand All @@ -20,4 +24,43 @@ static ItemFilter loadFilter(ItemStack itemStack) {
return FILTERS.get(itemStack.getItem()).apply(itemStack);
}

/**
* Retrieves the configured item count for the supplied item.
*
* @return The amount configured for the supplied item stack.<br>
* If the stack is not matched by this filter, 0 is returned instead.
*/
int testItemCount(ItemStack itemStack);

default boolean isBlackList() {
return false;
}


/**
* An empty item filter that allows all items.<br>
* ONLY TO BE USED FOR ITEM MATCHING! All other functionality will throw an exception.
*/
ItemFilter EMPTY = new ItemFilter() {
@Override public int testItemCount(ItemStack itemStack) {
return Integer.MAX_VALUE;
}

@Override public boolean test(ItemStack itemStack) {
return true;
}

@Override public WidgetGroup openConfigurator(int x, int y) {
throw new NotImplementedException("Not available for empty item filter");
}

@Override public CompoundTag saveFilter() {
throw new NotImplementedException("Not available for empty item filter");
}

@Override public void setOnUpdated(Consumer<ItemFilter> onUpdated) {
throw new NotImplementedException("Not available for empty item filter");
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class SimpleItemFilter implements ItemFilter {
@Getter
protected boolean isBlackList;
@Getter
protected boolean ignoreNbt;
Expand All @@ -35,8 +34,13 @@ public class SimpleItemFilter implements ItemFilter {
@Setter
protected Consumer<ItemFilter> onUpdated;

@Getter
protected int maxStackSize;


protected SimpleItemFilter() {
Arrays.fill(matches, ItemStack.EMPTY);
maxStackSize = 1;
}

public static SimpleItemFilter loadFilter(ItemStack itemStack) {
Expand Down Expand Up @@ -70,49 +74,94 @@ public CompoundTag saveFilter() {

public void setBlackList(boolean blackList) {
isBlackList = blackList;
if (blackList) {
setMaxStackSize(1);
} else {
setMaxStackSize(Integer.MAX_VALUE);
}
onUpdated.accept(this);
}

@Override
public boolean isBlackList() {
return isBlackList;
}

public void setIgnoreNbt(boolean ingoreNbt) {
this.ignoreNbt = ingoreNbt;
onUpdated.accept(this);
}

public WidgetGroup openConfigurator(int x, int y) {
WidgetGroup group = new WidgetGroup(x, y, 18 * 3 + 25, 18 * 3); // 80 55
var filterSlots = new PhantomSlotWidget[9];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
final int index = i * 3 + j;
var handler = new ItemStackTransfer(matches[index]);
var slot = new PhantomSlotWidget(handler, 0, i * 18, j * 18);
slot.setMaxStackSize(1);
filterSlots[i] = new PhantomSlotWidget(handler, 0, i * 18, j * 18) {
@Override
public void updateScreen() {
super.updateScreen();
setMaxStackSize(maxStackSize);
}

@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
setMaxStackSize(maxStackSize);
}
};
var slot = filterSlots[i];
slot.setChangeListener(() -> {
matches[index] = handler.getStackInSlot(0);
onUpdated.accept(this);
}).setBackground(GuiTextures.SLOT);
group.addWidget(slot);
}
}
group.addWidget(new ToggleButtonWidget(18 * 3 + 5, 0, 20, 20,
group.addWidget(new ToggleButtonWidget(18 * 3 + 2, 9, 18, 18,
GuiTextures.BUTTON_BLACKLIST, this::isBlackList, this::setBlackList));
group.addWidget(new ToggleButtonWidget(18 * 3 + 5, 20, 20, 20,
group.addWidget(new ToggleButtonWidget(18 * 3 + 2, (18) + 9, 18, 18,
GuiTextures.BUTTON_FILTER_NBT, this::isIgnoreNbt, this::setIgnoreNbt));
return group;
}

@Override
public boolean test(ItemStack itemStack) {
boolean found = false;
for (var match : matches) {
if (ignoreNbt) {
found = match.sameItem(itemStack);
} else {
found = ItemTransferHelper.canItemStacksStack(match, itemStack);
}
if (found) {
break;
return testItemCount(itemStack) > 0;
}

@Override
public int testItemCount(ItemStack itemStack) {
int totalItemCount = getTotalConfiguredItemCount(itemStack);

if (isBlackList) {
return (totalItemCount > 0) ? 0 : Integer.MAX_VALUE;
}

return totalItemCount;
}

public int getTotalConfiguredItemCount(ItemStack itemStack) {
int totalCount = 0;

for (var candidate : matches) {
if (ignoreNbt && candidate.sameItem(itemStack)) {
totalCount += candidate.getCount();
} else if (ItemTransferHelper.canItemStacksStack(candidate, itemStack)) {
totalCount += candidate.getCount();
}
}
return isBlackList != found;

return totalCount;
}

public void setMaxStackSize(int maxStackSize) {
this.maxStackSize = maxStackSize;

for (ItemStack match : matches) {
match.setCount(Math.min(match.getCount(), maxStackSize));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public boolean test(ItemStack itemStack) {
cache.put(itemStack.getItem(), false);
return false;
}

@Override
public int testItemCount(ItemStack itemStack) {
return test(itemStack) ? Integer.MAX_VALUE : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec2;

import javax.annotation.Nullable;
import java.util.List;
Expand Down Expand Up @@ -92,6 +94,10 @@ public void apply(boolean isTESR, RenderType layer) {
.setBackgroundTexture(new GuiTextureGroup(GuiTextures.SLOT, GuiTextures.FILTER_SLOT_OVERLAY)));
slotWidget.setVisible(false);
slotWidget.setActive(false);


var playerRotation = gui.entityPlayer.getRotationVector();
sceneWidget.setCameraYawAndPitch(playerRotation.x, playerRotation.y);
}

private void coverRemoved() {
Expand Down
Loading

0 comments on commit 4fde739

Please sign in to comment.