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

Commit

Permalink
made base class for both fluid and item filter covers, moved some bas…
Browse files Browse the repository at this point in the history
…e classes

also changed default redstone mode of pump and conveyor
  • Loading branch information
Trinsdar committed Sep 19, 2023
1 parent 167a83f commit 0f79191
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 74 deletions.
72 changes: 15 additions & 57 deletions common/src/main/java/muramasa/gregtech/cover/CoverConveyor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import muramasa.antimatter.gui.event.IGuiEvent;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.util.Utils;
import muramasa.gregtech.cover.base.CoverBasicTransport;
import muramasa.gregtech.data.GregTechData;
import muramasa.gregtech.data.SlotTypes;
import muramasa.gregtech.blockentity.single.IFilterable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -32,10 +34,6 @@

public class CoverConveyor extends CoverBasicTransport implements IFilterable {

static {
CoverGuiEvent.init();
}

public static String ID = "conveyor";

private boolean extracting = true;
Expand All @@ -54,6 +52,19 @@ public CoverConveyor(ICoverHandler<?> source, @Nullable Tier tier, Direction sid
}


@Override
public boolean onTransfer(Object object, boolean inputSide, boolean simulate) {
if (object instanceof ItemStack stack){
ItemStack compare = getInventory(SlotTypes.FILTERABLE).getItem(0);
if (compare.hasTag()){
CompoundTag nbt = compare.getTag();
boolean blacklist = nbt.getBoolean("blacklist");

}
}
return super.onTransfer(object, inputSide, simulate);
}

@Override
public <T> boolean blocksCapability(Class<T> cap, Direction side) {
return side == null && cap != ExtendedItemContainer.class;
Expand Down Expand Up @@ -124,57 +135,4 @@ protected boolean canMove(Direction side){
public boolean accepts(ItemStack stack) {
return stack.getItem() == GregTechData.COVER_ITEM_FILTER.getItem().getItem();
}


static class CoverGuiEvent implements IGuiEvent {

public static void init() {

}
enum ConveyorEvent {
INPUT_OUTPUT,
}
public final ConveyorEvent event;
public CoverGuiEvent(IGuiEventFactory fac, FriendlyByteBuf buffer) {
this.event = ConveyorEvent.values()[buffer.readVarInt()];
}

public CoverGuiEvent(ConveyorEvent ev) {
this.event = ev;
}

@Override
public boolean forward() {
return false;
}

@Override
public void write(FriendlyByteBuf buffer) {
buffer.writeVarInt(event.ordinal());
}

@Override
public void handle(Player player, GuiInstance instance) {
CoverConveyor source = (CoverConveyor) instance.handler;
switch (event) {
case INPUT_OUTPUT -> source.extracting = !source.extracting;
}
}
public static final IGuiEvent.IGuiEventFactory INSTANCE = AntimatterAPI.register(IGuiEventFactory.class, new IGuiEventFactory() {
@Override
public BiFunction<IGuiEventFactory, FriendlyByteBuf, IGuiEvent> factory() {
return CoverGuiEvent::new;
}

@Override
public String getId() {
return "cover_gui_factory";
}
});

@Override
public IGuiEventFactory getFactory() {
return INSTANCE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.machine.Tier;
import muramasa.gregtech.cover.base.CoverFilter;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tesseract.util.ItemHandlerUtils;

public class CoverFluidFilter extends BaseCover {
boolean blacklist = false;
boolean ignoreNBt = false;
public class CoverFluidFilter extends CoverFilter {
public CoverFluidFilter(@NotNull ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
getGui().getSlots().add(SlotType.DISPLAY_SETTABLE, 80, 25);
Expand Down Expand Up @@ -47,7 +45,7 @@ public boolean onTransfer(Object object, boolean inputSide, boolean execute) {
}
boolean matches = FluidHooks.safeGetItemFluidManager(filter).map(f -> {
for (int i = 0; i < f.getTankAmount(); i++){
boolean match = ignoreNBt ? fluidHolder.getFluid() == f.getFluidInTank(i).getFluid() : f.getFluidInTank(i).matches(fluidHolder);
boolean match = ignoreNBT ? fluidHolder.getFluid() == f.getFluidInTank(i).getFluid() : f.getFluidInTank(i).matches(fluidHolder);
if (match){
return true;
}
Expand All @@ -63,12 +61,12 @@ public boolean onTransfer(Object object, boolean inputSide, boolean execute) {

@Override
protected String getRenderId() {
return "item_filter";
return "fluid_filter";
}

@Override
public String getId() {
return "item_filter";
return "fluid_filter";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.util.AntimatterPlatformUtils;
import muramasa.gregtech.cover.base.CoverFilter;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tesseract.util.ItemHandlerUtils;

public class CoverItemFilter extends BaseCover {
boolean blacklist = false;
boolean ignoreNBt = false;
public class CoverItemFilter extends CoverFilter {
public CoverItemFilter(@NotNull ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
getGui().getSlots().add(SlotType.DISPLAY_SETTABLE, 80, 25);
Expand All @@ -30,15 +29,14 @@ public <T> boolean blocksCapability(Class<T> cap, @Nullable Direction side) {
public boolean onTransfer(Object object, boolean inputSide, boolean execute) {
super.onTransfer(object, inputSide, execute);
if (object instanceof ItemStack item) {
boolean stop = false;
ItemStack filter = getInventory(SlotType.DISPLAY_SETTABLE).getItem(0);
boolean empty = filter.isEmpty();
if (empty) {
if (!blacklist) {
return true;
}
}
boolean matches = ignoreNBt ? item.is(filter.getItem()) : ItemHandlerUtils.canItemStacksStack(item, filter);
boolean matches = ignoreNBT ? item.is(filter.getItem()) : ItemHandlerUtils.canItemStacksStack(item, filter);
if (blacklist == matches){
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.util.Utils;
import muramasa.gregtech.cover.base.CoverBasicTransport;
import muramasa.gregtech.data.GregTechData;
import muramasa.gregtech.data.SlotTypes;
import muramasa.gregtech.blockentity.single.IFilterable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package muramasa.gregtech.cover;
package muramasa.gregtech.cover.base;

import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.BaseCover;
Expand All @@ -8,6 +8,7 @@
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.blockentity.pipe.BlockEntityPipe;
import muramasa.gregtech.cover.RedstoneMode;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package muramasa.gregtech.cover;
package muramasa.gregtech.cover.base;

import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.CoverFactory;
Expand All @@ -9,6 +9,9 @@
import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.blockentity.pipe.BlockEntityPipe;
import muramasa.gregtech.GTIRef;
import muramasa.gregtech.cover.ICoverRedstoneSensitive;
import muramasa.gregtech.cover.ImportExportMode;
import muramasa.gregtech.cover.RedstoneMode;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
Expand All @@ -27,6 +30,7 @@ public abstract class CoverBasicTransport extends CoverBasicRedstone implements
public CoverBasicTransport(ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
this.exportMode = source.getTile() instanceof BlockEntityPipe<?> ? IMPORT : EXPORT;
redstoneMode = RedstoneMode.NO_WORK;
coverModeInt = exportMode.ordinal();
addGuiCallback(t -> {
t.addCycleButton(70, 34, 16, 16, h -> ((CoverBasicRedstone)h).redstoneMode.ordinal(), i -> "tooltip.gti.redstone_mode." + i, ButtonOverlay.TORCH_OFF, ButtonOverlay.TORCH_ON, ButtonOverlay.REDSTONE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
package muramasa.gregtech.cover.base;public class CoverFilter {
package muramasa.gregtech.cover.base;

import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.BaseCover;
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.machine.Tier;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CoverFilter extends BaseCover {
protected boolean blacklist = false;
protected boolean ignoreNBT = false;
public CoverFilter(@NotNull ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
}

@Override
public ItemStack getDroppedStack() {
ItemStack stack = super.getDroppedStack();
stack.getOrCreateTag().putBoolean("blacklist", blacklist);
stack.getOrCreateTag().putBoolean("ignoreNBT", ignoreNBT);
return stack;
}

@Override
public void addInfoFromStack(ItemStack stack) {
super.addInfoFromStack(stack);
CompoundTag tag = stack.getTag();
blacklist = tag.getBoolean("blacklist");
ignoreNBT = tag.getBoolean("ignoreNBT");
}

@Override
public void onUpdate() {
super.onUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import muramasa.antimatter.gui.event.IGuiEvent;
import muramasa.antimatter.machine.MachineState;
import muramasa.antimatter.machine.Tier;
import muramasa.gregtech.cover.CoverBasicRedstone;
import muramasa.gregtech.cover.RedstoneMode;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
Expand Down

0 comments on commit 0f79191

Please sign in to comment.