Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a5ac73f
new fluid tank list
ghzdude Dec 15, 2024
e9a7185
to string
ghzdude Dec 15, 2024
f5075e3
interface
ghzdude Dec 15, 2024
be2b680
make entry implement tank property
ghzdude Dec 20, 2024
75d1cd2
rework transfer logic
ghzdude Dec 24, 2024
8514379
a bit more work
ghzdude Dec 24, 2024
4af53e5
switch to inner class
ghzdude Dec 24, 2024
444a53b
add new constructor
ghzdude Dec 24, 2024
8b3efe8
make abstract class instead of interface
ghzdude Dec 26, 2024
8f5842f
new method
ghzdude Dec 26, 2024
5e483f3
test new impl
ghzdude Dec 27, 2024
7741b1b
fix overflow + spotless
ghzdude Dec 27, 2024
e6623f7
fix filling distinct tanks
ghzdude Dec 27, 2024
daaee26
update parallel logic test
ghzdude Dec 27, 2024
0604fa7
we do a little replace all
ghzdude Dec 27, 2024
935067f
do tank instead of handler
ghzdude Dec 27, 2024
13b1537
simplify constructor slightly
ghzdude Dec 27, 2024
fceccae
move methods
ghzdude Dec 27, 2024
8aa7d29
add filtering to base handler classes
ghzdude Dec 27, 2024
7c8c20b
reorder methods again
ghzdude Dec 27, 2024
671364b
fix test
ghzdude Dec 27, 2024
4ad58a9
remove unneeded method
ghzdude Dec 27, 2024
18ee565
pull out inner interfaces
ghzdude Dec 27, 2024
30f6bd7
pull out inner interfaces
ghzdude Dec 27, 2024
5ab6dd9
we still need this, actually
ghzdude Dec 27, 2024
43b5bf3
merge fill loops
ghzdude Dec 29, 2024
1482fb3
add comments
ghzdude Dec 30, 2024
1164b11
undeprecate
ghzdude Dec 30, 2024
dfee2e0
fix rebase
ghzdude Mar 19, 2025
7d00ece
replace more instances of FluidTankList with MultipleTankHandler
ghzdude Apr 12, 2025
64a02c7
fix null return
ghzdude Apr 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 43 additions & 48 deletions src/main/java/gregtech/api/capability/DualHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,42 @@
import gregtech.api.util.ItemStackHashStrategy;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler, INotifiableHandler {
public class DualHandler extends MultipleTankHandler implements IItemHandlerModifiable, INotifiableHandler {

@NotNull
private static final ItemStackHashStrategy strategy = ItemStackHashStrategy.comparingAll();

@NotNull
protected IItemHandlerModifiable itemDelegate;
@NotNull
protected IMultipleTankHandler fluidDelegate;
protected MultipleTankHandler fluidDelegate;

private final List<ITankEntry> unwrapped;
private final List<Entry> unwrapped;

List<MetaTileEntity> notifiableEntities = new ArrayList<>();
private final boolean isExport;

public DualHandler(@NotNull IItemHandlerModifiable itemDelegate,
@NotNull IMultipleTankHandler fluidDelegate,
@NotNull MultipleTankHandler fluidDelegate,
boolean isExport) {
this.itemDelegate = itemDelegate;
this.fluidDelegate = fluidDelegate;
this.isExport = isExport;

List<ITankEntry> list = new ArrayList<>();
for (ITankEntry tank : this.fluidDelegate) {
List<Entry> list = new ArrayList<>();
for (Entry tank : this.fluidDelegate) {
list.add(wrap(tank));
}
this.unwrapped = list;
Expand All @@ -50,8 +52,9 @@ public DualHandler(@NotNull IItemHandlerModifiable itemDelegate,
this(itemDelegate, new FluidTankList(false, fluidTank), isExport);
}

private DualEntry wrap(ITankEntry entry) {
return entry instanceof DualEntry ? (DualEntry) entry : new DualEntry(this, entry);
@Override
protected Entry wrap(IFluidTank tank) {
return tank instanceof DualEntry ? (DualEntry) tank : new DualEntry(this, super.wrap(tank));
}

public boolean isExport() {
Expand Down Expand Up @@ -124,17 +127,17 @@ public FluidStack drain(int maxDrain, boolean doDrain) {
}

@Override
public @NotNull List<ITankEntry> getFluidTanks() {
public @NotNull List<Entry> getFluidTanks() {
return this.unwrapped;
}

@Override
public int getTanks() {
return this.fluidDelegate.getTanks();
public int size() {
return this.fluidDelegate.size();
}

@Override
public @NotNull ITankEntry getTankAt(int index) {
public @NotNull Entry getTankAt(int index) {
return this.unwrapped.get(index);
}

Expand Down Expand Up @@ -169,70 +172,62 @@ public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) {
return itemDelegate;
}

public @NotNull IMultipleTankHandler getFluidDelegate() {
public @NotNull MultipleTankHandler getFluidDelegate() {
return fluidDelegate;
}

public static class DualEntry implements ITankEntry, INotifiableHandler {

@NotNull
private final DualHandler tank;
public static class DualEntry extends Entry implements INotifiableHandler {

@NotNull
private final ITankEntry delegate;
private final DualHandler parent;

public DualEntry(@NotNull DualHandler tank, @NotNull ITankEntry delegate) {
this.delegate = delegate;
this.tank = tank;
}

@Override
public @NotNull IMultipleTankHandler getParent() {
return this.tank;
}

@Override
public @NotNull ITankEntry getDelegate() {
return this.delegate;
}

@Override
public IFluidTankProperties[] getTankProperties() {
return this.getDelegate().getTankProperties();
public DualEntry(@NotNull DualHandler parent, @NotNull Entry tank) {
super(tank, tank.getParentHandler());
this.parent = parent;
}

@Override
public int fill(FluidStack resource, boolean doFill) {
int filled = getDelegate().fill(resource, doFill);
if (doFill && filled > 0)
tank.onContentsChanged(this);
this.parent.onContentsChanged(this);
return filled;
}

@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
var drained = getDelegate().drain(resource, doDrain);
if (doDrain && drained != null)
tank.onContentsChanged(this);
return drained;
}

@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
var drained = getDelegate().drain(maxDrain, doDrain);
if (doDrain && drained != null)
tank.onContentsChanged(this);
this.parent.onContentsChanged(this);
return drained;
}

@Override
public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) {
this.tank.addNotifiableMetaTileEntity(metaTileEntity);
this.parent.addNotifiableMetaTileEntity(metaTileEntity);
}

@Override
public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) {
this.tank.removeNotifiableMetaTileEntity(metaTileEntity);
this.parent.removeNotifiableMetaTileEntity(metaTileEntity);
}
}

@Override
public NBTTagCompound serializeNBT() {
NBTTagCompound root = new NBTTagCompound();
if (this.itemDelegate instanceof ItemStackHandler handler) {
root.setTag("item", handler.serializeNBT());
}
root.setTag("fluid", getFluidDelegate().serializeNBT());
return root;
}

@Override
public void deserializeNBT(NBTTagCompound nbt) {
if (this.itemDelegate instanceof ItemStackHandler handler) {
handler.deserializeNBT(nbt.getCompoundTag("item"));
}
getFluidDelegate().deserializeNBT(nbt.getCompoundTag("fluid"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,5 @@

import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.Nullable;

import java.util.Comparator;

/**
* Interface for fluid containers ({@link net.minecraftforge.fluids.IFluidTank IFluidTank} or
* {@link net.minecraftforge.fluids.capability.IFluidHandler IFluidHandler}) associated with {@link IFilter}.
*/
public interface IFilteredFluidContainer {

/**
* Compare logic for filtered instances.
*/
Comparator<IFilteredFluidContainer> COMPARATOR = Comparator.nullsLast(
Comparator.comparing(IFilteredFluidContainer::getFilter, IFilter.FILTER_COMPARATOR));

/**
* @return instance of {@link IFilter} associated to this object, or {@code null} if there's no filter
* associated.
*/
@Nullable
IFilter<FluidStack> getFilter();
}
// for type safe casting
public interface IFilteredFluidContainer extends IFilteredHandler<FluidStack> {}
25 changes: 25 additions & 0 deletions src/main/java/gregtech/api/capability/IFilteredHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gregtech.api.capability;

import org.jetbrains.annotations.Nullable;

import java.util.Comparator;

/**
* Interface for fluid containers ({@link net.minecraftforge.fluids.IFluidTank IFluidTank} or
* {@link net.minecraftforge.fluids.capability.IFluidHandler IFluidHandler}) associated with {@link IFilter}.
*/
public interface IFilteredHandler<T> {

/**
* Compare logic for filtered instances.
*/
Comparator<IFilteredHandler<?>> COMPARATOR = Comparator.nullsLast(
Comparator.comparing(IFilteredHandler::getFilter, IFilter.FILTER_COMPARATOR));

/**
* @return instance of {@link IFilter} associated to this object, or {@code null} if there's no filter
* associated.
*/
@Nullable
IFilter<T> getFilter();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gregtech.api.capability;

import net.minecraft.item.ItemStack;

public interface IFilteredItemContainer extends IFilteredHandler<ItemStack> {}
153 changes: 0 additions & 153 deletions src/main/java/gregtech/api/capability/IMultipleTankHandler.java

This file was deleted.

Loading