Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework Multiblock Abilities #2420

Open
wants to merge 112 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
f5a8c13
initial work of multi abilities
ghzdude Mar 19, 2024
ad55eeb
add controller to notifiable
ghzdude Mar 19, 2024
87cd43d
save to nbt
ghzdude Mar 19, 2024
ab6a5e6
renames
ghzdude Mar 19, 2024
7cba9da
spotless
ghzdude Mar 19, 2024
b984e1d
initial impl of dual handlers
ghzdude Mar 19, 2024
4f88e36
sbobl
ghzdude Mar 19, 2024
fc33914
some work on combining abilities
ghzdude Apr 6, 2024
a4adf30
remove builder
ghzdude Apr 6, 2024
7628750
dual handler probably works now
ghzdude Apr 6, 2024
b2476f9
small fixes
ghzdude Apr 6, 2024
8692f11
a bit more work
ghzdude Apr 7, 2024
171ec62
try fix tests
ghzdude Apr 14, 2024
1b87e42
fix ghost circ init
ghzdude Apr 14, 2024
a097d61
fix inventory init
ghzdude Apr 14, 2024
05aaf4f
add and use better utility methods
ghzdude Jul 4, 2024
efaf857
add method overloads for multiple abilities
ghzdude Jul 4, 2024
be35c55
misc + spotless
ghzdude Jul 4, 2024
5966ed9
wtf distillation tower
ghzdude Jul 4, 2024
4ea5267
fix typo + spotless
ghzdude Jul 4, 2024
4b09bcf
forgor tank props
ghzdude Jul 4, 2024
80513ab
use new method
ghzdude Jul 4, 2024
86cf2a1
try and improve checks for dual handlers
ghzdude Jul 4, 2024
9d3a2cc
remove contains check
ghzdude Jul 4, 2024
0e8590c
mark delegates nonnull
ghzdude Jul 5, 2024
fcddf45
INotifiable is not needed
ghzdude Jul 5, 2024
4dad2ff
use new method
ghzdude Jul 5, 2024
ff7f908
improve handler checking
ghzdude Jul 5, 2024
c8620a1
forgor
ghzdude Jul 5, 2024
48bd73c
spobl
ghzdude Jul 5, 2024
f88ca61
move DualHandler to capability package
ghzdude Jul 10, 2024
aa463fb
add method for checking the ability at pos
ghzdude Jul 10, 2024
3664af0
remove unnecessary methods and usages
ghzdude Jul 10, 2024
c8101ea
move find recipe changes to MultiblockRecipeLogic
ghzdude Jul 10, 2024
e8ee8a3
remove unnecessary abilities
ghzdude Jul 10, 2024
b8357bf
return key set which is the correct size
ghzdude Jul 10, 2024
2202dd7
actually check correctly
ghzdude Jul 10, 2024
c15003a
minor oopsie
ghzdude Jul 10, 2024
946ff1b
fix issue in prepareRecipe
ghzdude Jul 10, 2024
2da9565
spblss
ghzdude Jul 10, 2024
a4b28c0
add DualEntry to implement IFluidTank
ghzdude Jul 11, 2024
15eb53d
lower interface check
ghzdude Jul 11, 2024
1c39bf6
move more logic to MultiblockRecipeLogic
ghzdude Jul 11, 2024
052a306
fix dt rebase
ghzdude Jul 11, 2024
8c96e48
sblss
ghzdude Jul 11, 2024
89b5578
fix props
ghzdude Jul 11, 2024
3b304fb
add constructor
ghzdude Jul 13, 2024
52e84a6
fix issue with tests and recipe matching
ghzdude Jul 15, 2024
4ab07fd
fix distinct recipe checking + misc
ghzdude Jul 19, 2024
6fdabaa
refactor IMultiblockAbilityPart to reduce list instantiations
ghzdude Jul 26, 2024
fbc5a23
use ObjectArrayList
ghzdude Jul 26, 2024
12aacf1
no need to use this method here
ghzdude Jul 26, 2024
f140fa1
fix rebase
ghzdude Jul 27, 2024
a0f56cd
return if there's nothing to check
ghzdude Jul 27, 2024
9f61a20
attempt to retain references to the handlers
ghzdude Jul 27, 2024
3ddd1fb
remove unused methods + spotless
ghzdude Jul 27, 2024
84c84a1
try reduce list depth
ghzdude Jul 27, 2024
87b079d
dual handler notifiable
ghzdude Jul 28, 2024
49f6887
size for notifiables
ghzdude Jul 28, 2024
4fc4790
casually refactor notifiables
ghzdude Jul 28, 2024
80ad4c7
fix issues with distinct consuming items
ghzdude Jul 28, 2024
1524846
address reviews
ghzdude Aug 2, 2024
0aae9eb
store class for type checking
ghzdude Aug 11, 2024
85a961e
utilize new list
ghzdude Aug 11, 2024
063071b
update registration to new list
ghzdude Aug 11, 2024
17e39ad
no need for dual handler here anymore
ghzdude Aug 11, 2024
5b4dd98
mark ability as nullable and add default
ghzdude Aug 11, 2024
61fde03
changes to recipe logic are no longer necessary
ghzdude Aug 11, 2024
32efe1f
override more methods
ghzdude Aug 12, 2024
06a20a7
simplify DualHandler and improve notifiability
ghzdude Aug 12, 2024
5c28ce5
make entry static again
ghzdude Aug 12, 2024
4ed45b9
add back simple checking of extra fluids from items only when distinc…
ghzdude Aug 13, 2024
2d44b0d
fix dual handler a bit
ghzdude Aug 13, 2024
65e7614
improve add method
ghzdude Aug 14, 2024
c8eeb0b
update to `getAbilities()`
ghzdude Aug 14, 2024
d7f83e1
fix warning
ghzdude Aug 14, 2024
ed378de
check object type and collect if iterable
ghzdude Aug 14, 2024
b8755af
unneeded javadoc
ghzdude Aug 14, 2024
19fe877
throw exception on adding or setting invalid element
ghzdude Aug 14, 2024
af173ab
better javadocs
ghzdude Aug 14, 2024
73b61c5
remove unnecessary override
ghzdude Aug 14, 2024
d8b1b16
always assume a size of one
ghzdude Aug 16, 2024
774ea04
fix potential npe with EMPTY
ghzdude Aug 16, 2024
ad93eea
always check for extra fluids, but only for multis
ghzdude Aug 16, 2024
394d02c
do not allow duplicate instances
ghzdude Aug 16, 2024
f2454c2
check fluids in controller init instead of recipe logic
ghzdude Aug 16, 2024
4d4b5ab
fix fluid voiding?
ghzdude Aug 16, 2024
6aef6f1
fix tank list creation
ghzdude Aug 16, 2024
b53525d
casually rework IMultipleTankHandler to use an extendable interface i…
ghzdude Aug 17, 2024
b669d56
add overloaded method
ghzdude Aug 17, 2024
79526e4
remove unnecessary overrides
ghzdude Aug 17, 2024
84b4350
spotless
ghzdude Oct 16, 2024
91d627d
add javadoc
ghzdude Dec 31, 2024
45592b1
improve javadoc slightly
ghzdude Dec 31, 2024
e20b0e6
improve javadoc slightly
ghzdude Jan 1, 2025
4ba0536
d
ghzdude Jan 1, 2025
10300da
fix rebase
ghzdude Jan 9, 2025
626139a
use reference equals instead
ghzdude Jan 14, 2025
0f1d889
move circuit inventory to `initializeInventory()`
ghzdude Jan 21, 2025
63188bc
switch variable names to match MultiFluidTankEntry
ghzdude Jan 21, 2025
7b34852
use better method
ghzdude Jan 21, 2025
4e8bc4d
add circuit slot to reservoir hatch
ghzdude Jan 25, 2025
38a789c
fix rebase + spotless
ghzdude Feb 3, 2025
37a0dcc
remove name registry
ghzdude Feb 16, 2025
b5b3485
reset extended fluid inputs
ghzdude Feb 16, 2025
d5c3556
add comment
ghzdude Feb 16, 2025
44b6745
use dual handler in qstorage controller
ghzdude Feb 22, 2025
7c92696
remove todo
ghzdude Feb 23, 2025
c59751b
check if already wrapped
ghzdude Feb 23, 2025
82c849f
replace IDualHandler with DualHandler
ghzdude Feb 27, 2025
707a57e
add various overrides to fix circuit in reservoir hatch
ghzdude Feb 27, 2025
83a4325
make cast list not null
ghzdude Mar 4, 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
238 changes: 238 additions & 0 deletions src/main/java/gregtech/api/capability/DualHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
package gregtech.api.capability;

import gregtech.api.capability.impl.FluidTankList;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.util.ItemStackHashStrategy;

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

import org.jetbrains.annotations.NotNull;

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

public class DualHandler implements IItemHandlerModifiable, IMultipleTankHandler, INotifiableHandler {

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

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

private final List<ITankEntry> unwrapped;

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

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

List<ITankEntry> list = new ArrayList<>();
for (ITankEntry tank : this.fluidDelegate) {
list.add(wrap(tank));
}
this.unwrapped = list;
}

public DualHandler(@NotNull IItemHandlerModifiable itemDelegate,
@NotNull IFluidTank fluidTank,
boolean isExport) {
this(itemDelegate, new FluidTankList(false, fluidTank), isExport);
}

private DualEntry wrap(ITankEntry entry) {
return entry instanceof DualEntry ? (DualEntry) entry : new DualEntry(this, entry);
}

public boolean isExport() {
return this.isExport;
}

@Override
public int getSlots() {
return itemDelegate.getSlots();
}

@Override
public @NotNull ItemStack getStackInSlot(int slot) {
return itemDelegate.getStackInSlot(slot);
}

@Override
public @NotNull ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
var remainder = itemDelegate.insertItem(slot, stack, simulate);
if (!simulate && !strategy.equals(remainder, stack))
onContentsChanged();
return remainder;
}

@Override
public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) {
var extracted = itemDelegate.extractItem(slot, amount, simulate);
if (!simulate && !extracted.isEmpty())
onContentsChanged();
return extracted;
}

@Override
public int getSlotLimit(int slot) {
return itemDelegate.getSlotLimit(slot);
}

@Override
public void setStackInSlot(int slot, @NotNull ItemStack stack) {
var oldStack = itemDelegate.getStackInSlot(slot);
itemDelegate.setStackInSlot(slot, stack);
if (!strategy.equals(oldStack, stack))
onContentsChanged();
}

@Override
public IFluidTankProperties[] getTankProperties() {
return this.fluidDelegate.getTankProperties();
}

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

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

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

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

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

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

@Override
public boolean allowSameFluidFill() {
return this.fluidDelegate.allowSameFluidFill();
}

public void onContentsChanged(Object handler) {
for (MetaTileEntity metaTileEntity : notifiableEntities) {
addToNotifiedList(metaTileEntity, handler, isExport);
}
}

public void onContentsChanged() {
onContentsChanged(this);
}

@Override
public void addNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) {
if (metaTileEntity == null || this.notifiableEntities.contains(metaTileEntity))
return;
this.notifiableEntities.add(metaTileEntity);
}

@Override
public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) {
this.notifiableEntities.remove(metaTileEntity);
}

public @NotNull IItemHandlerModifiable getItemDelegate() {
return itemDelegate;
}

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

public static class DualEntry implements ITankEntry, INotifiableHandler {

@NotNull
private final DualHandler tank;

@NotNull
private final ITankEntry delegate;

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();
}

@Override
public int fill(FluidStack resource, boolean doFill) {
int filled = getDelegate().fill(resource, doFill);
if (doFill && filled > 0)
tank.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);
return drained;
}

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

@Override
public void removeNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) {
this.tank.removeNotifiableMetaTileEntity(metaTileEntity);
}
}
}
14 changes: 0 additions & 14 deletions src/main/java/gregtech/api/capability/IDualHandler.java

This file was deleted.

Loading