Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
added gui to item retriever
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Aug 12, 2024
1 parent 4ef854d commit f578531
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
package muramasa.gregtech.cover;

import muramasa.antimatter.blockentity.BlockEntityBase;
import muramasa.antimatter.blockentity.pipe.BlockEntityItemPipe;
import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.BaseCover;
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.gui.ButtonOverlay;
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.gui.event.GuiEvents;
import muramasa.antimatter.gui.event.IGuiEvent;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.util.Utils;
import muramasa.gregtech.cover.base.CoverFilter;
import muramasa.gregtech.gui.ButtonOverlays;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tesseract.TesseractCapUtils;
import tesseract.api.item.PlatformItemHandler;
import tesseract.util.ItemHandlerUtils;

import java.util.ArrayList;
import java.util.HashMap;

public class CoverItemRetriever extends BaseCover {
public class CoverItemRetriever extends CoverFilter {
public CoverItemRetriever(@NotNull ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
getGui().getSlots().add(SlotType.DISPLAY_SETTABLE, 79, 53);
addGuiCallback(t -> {
t.addSwitchButton(70, 34, 16, 16, ButtonOverlay.WHITELIST, ButtonOverlay.BLACKLIST, h -> blacklist, true, b -> "tooltip.gti." + (b ? "blacklist" : "whitelist"));
t.addSwitchButton(88, 34, 16, 16, ButtonOverlays.NBT_OFF, ButtonOverlays.NBT_ON, h -> !ignoreNBT, true, b -> "tooltip.gti.nbt." + (b ? "on" : "off"));
});;
}

@Override
public void clearFilter(){
super.clearFilter();
getInventory(SlotType.DISPLAY_SETTABLE).clearContent();
}

@Override
Expand All @@ -37,7 +58,7 @@ public void onUpdate() {
BlockEntity a = p.getCachedBlockEntity(dir);
if (!(a instanceof BlockEntityItemPipe) && a != null){
PlatformItemHandler itemHandler = TesseractCapUtils.INSTANCE.getItemHandler(a, dir.getOpposite()).orElse(null);
if (itemHandler != null && Utils.transferItems(itemHandler, to, true)){
if (itemHandler != null && Utils.transferItems(itemHandler, to, true, s -> itemMatches(s, getInventory(SlotType.DISPLAY_SETTABLE).getItem(0)))){
for (BlockEntityItemPipe<?> tUsedPipe : tUsedPipes){
tUsedPipe.incrementTransferCounter(1);
}
Expand All @@ -52,4 +73,33 @@ public void onUpdate() {

}
}

private boolean itemMatches(ItemStack item, ItemStack filter) {
boolean empty = filter.isEmpty();
if (empty) {
if (!blacklist) {
return true;
}
}
boolean matches = ignoreNBT ? item.is(filter.getItem()) : ItemHandlerUtils.canItemStacksStack(item, filter);
return blacklist == matches;
}

@Override
public void onGuiEvent(IGuiEvent event, Player playerEntity) {
if (event.getFactory() == GuiEvents.EXTRA_BUTTON){
GuiEvents.GuiEvent ev = (GuiEvents.GuiEvent) event;
if (ev.data[1] == 0){
blacklist = !blacklist;
if (this.handler.getTile() instanceof BlockEntityBase<?> base){
base.sidedSync(true);
}
} else if (ev.data[1] == 1){
ignoreNBT = !ignoreNBT;
if (this.handler.getTile() instanceof BlockEntityBase<?> base){
base.sidedSync(true);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void deserialize(CompoundTag nbt) {
this.blacklist = nbt.getBoolean("blacklist");
this.ignoreNBT = nbt.getBoolean("ignoreNBT");
this.filterMode = nbt.getByte("filterMode");
if (this.handler.getTile().getLevel() != null && this.handler.getTile().getLevel().isClientSide()) {
if (this.handler.getTile().getLevel() != null && this.handler.getTile().getLevel().isClientSide() && factory.getTextures().size() == 2) {
if (this.handler instanceof CoverHandler<?> coverHandler && coverHandler.coverTexturer != null && coverHandler.coverTexturer.get(this.side) != null){
coverHandler.coverTexturer.get(this.side).invalidate();
}
Expand Down
21 changes: 19 additions & 2 deletions common/src/main/java/muramasa/gregtech/data/GregTechCovers.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,25 @@ public class GregTechCovers {
new ItemCover(a.getDomain(), a.getId(), b).tip(String.format("1 Stack every %dt(%ss), with configurable stack size limits (as Cover)", CoverConveyor.speeds.get(b), (float)CoverConveyor.speeds.get(b) / 20))
).addTextures(new Texture(GTIRef.ID, "block/cover/conveyor")).setTiers(Tier.getStandard()).build(GTIRef.ID, "item_regulator");
public static final CoverFactory COVER_ITEM_RETRIEVER = CoverFactory.builder(CoverItemRetriever::new).item((a, b) -> {
return new ItemCover(GTIRef.ID, "item_retriever");
}).addTextures(new Texture(GTIRef.ID, "block/cover/item_retriever")).setIsValid(b -> b instanceof BlockEntityItemPipe<?>).build(GTIRef.ID, "item_retriever");
return new ItemCoverCustomTooltip(GTIRef.ID, "item_filter", (stack, world, tooltip, flag) -> {
CompoundTag nbt = stack.getTag();
if (nbt != null && nbt.contains("coverInventories")){
CompoundTag coverInventories = nbt.getCompound("coverInventories");
if (coverInventories.contains("display_settable")){
CompoundTag displayManager = coverInventories.getCompound("display_settable");
if (displayManager.contains("Items")){
ListTag items = displayManager.getList("Items", Tag.TAG_COMPOUND);
if (!items.isEmpty()){
ItemStack contained = ItemStack.of(items.getCompound(0));
if (!contained.isEmpty()){
tooltip.add(contained.getHoverName());
}
}
}
}
}
}).tip("Can be placed as cover");
}).addTextures(new Texture(GTIRef.ID, "block/cover/item_retriever")).setIsValid(b -> b instanceof BlockEntityItemPipe<?>).gui().build(GTIRef.ID, "item_retriever");
public static final CoverFactory COVER_PUMP = CoverFactory.builder(CoverPump::new).gui().item((a, b) ->
new ItemCover(a.getDomain(), a.getId(), b).tip(String.format("%d L/t (as Cover)", CoverPump.speeds.get(b))))
.addTextures(new Texture(GTIRef.ID, "block/cover/pump")).setTiers(Tier.getStandard()).build(GTIRef.ID, "pump");
Expand Down

0 comments on commit f578531

Please sign in to comment.