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 100 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
1e83be0
initial work of multi abilities
ghzdude Mar 19, 2024
f6daf31
add controller to notifiable
ghzdude Mar 19, 2024
d4b52ff
save to nbt
ghzdude Mar 19, 2024
1f29159
renames
ghzdude Mar 19, 2024
1a9347f
spotless
ghzdude Mar 19, 2024
48692b7
initial impl of dual handlers
ghzdude Mar 19, 2024
97879c3
sbobl
ghzdude Mar 19, 2024
32fcbca
some work on combining abilities
ghzdude Apr 6, 2024
ce8a6f4
remove builder
ghzdude Apr 6, 2024
9adc061
dual handler probably works now
ghzdude Apr 6, 2024
3f1a93e
small fixes
ghzdude Apr 6, 2024
d875cbb
a bit more work
ghzdude Apr 7, 2024
3008757
try fix tests
ghzdude Apr 14, 2024
0e7c8df
fix ghost circ init
ghzdude Apr 14, 2024
edfc5ec
fix inventory init
ghzdude Apr 14, 2024
c856a10
add and use better utility methods
ghzdude Jul 4, 2024
1a0c0a0
add method overloads for multiple abilities
ghzdude Jul 4, 2024
94ea753
misc + spotless
ghzdude Jul 4, 2024
7495168
wtf distillation tower
ghzdude Jul 4, 2024
4f08937
fix typo + spotless
ghzdude Jul 4, 2024
8198390
forgor tank props
ghzdude Jul 4, 2024
a6c25cd
use new method
ghzdude Jul 4, 2024
647d062
try and improve checks for dual handlers
ghzdude Jul 4, 2024
14e1f5a
remove contains check
ghzdude Jul 4, 2024
82abff1
mark delegates nonnull
ghzdude Jul 5, 2024
63c2d41
INotifiable is not needed
ghzdude Jul 5, 2024
55bda4c
use new method
ghzdude Jul 5, 2024
1da6d2b
improve handler checking
ghzdude Jul 5, 2024
cb8b678
forgor
ghzdude Jul 5, 2024
0c5b3fc
spobl
ghzdude Jul 5, 2024
ac7c42d
move DualHandler to capability package
ghzdude Jul 10, 2024
c67797a
add method for checking the ability at pos
ghzdude Jul 10, 2024
85b0cc2
remove unnecessary methods and usages
ghzdude Jul 10, 2024
f4726f6
move find recipe changes to MultiblockRecipeLogic
ghzdude Jul 10, 2024
352654d
remove unnecessary abilities
ghzdude Jul 10, 2024
af5fa0c
return key set which is the correct size
ghzdude Jul 10, 2024
23576e0
actually check correctly
ghzdude Jul 10, 2024
3d6ad01
minor oopsie
ghzdude Jul 10, 2024
ba3300c
fix issue in prepareRecipe
ghzdude Jul 10, 2024
6c2e89d
spblss
ghzdude Jul 10, 2024
06fad3b
add DualEntry to implement IFluidTank
ghzdude Jul 11, 2024
2355238
lower interface check
ghzdude Jul 11, 2024
2aeaffe
move more logic to MultiblockRecipeLogic
ghzdude Jul 11, 2024
496107f
fix dt rebase
ghzdude Jul 11, 2024
ebccd04
sblss
ghzdude Jul 11, 2024
7666816
fix props
ghzdude Jul 11, 2024
ac3aa2d
add constructor
ghzdude Jul 13, 2024
21d2a7a
fix issue with tests and recipe matching
ghzdude Jul 15, 2024
88cf1ef
fix distinct recipe checking + misc
ghzdude Jul 19, 2024
671f64b
refactor IMultiblockAbilityPart to reduce list instantiations
ghzdude Jul 26, 2024
fa2a6a6
use ObjectArrayList
ghzdude Jul 26, 2024
6c5c857
no need to use this method here
ghzdude Jul 26, 2024
11fe724
fix rebase
ghzdude Jul 27, 2024
d6a9484
return if there's nothing to check
ghzdude Jul 27, 2024
6526f61
attempt to retain references to the handlers
ghzdude Jul 27, 2024
a355042
remove unused methods + spotless
ghzdude Jul 27, 2024
b7dc3bc
try reduce list depth
ghzdude Jul 27, 2024
e8fd9ba
dual handler notifiable
ghzdude Jul 28, 2024
c6356f0
size for notifiables
ghzdude Jul 28, 2024
d945704
casually refactor notifiables
ghzdude Jul 28, 2024
7d2f3ac
fix issues with distinct consuming items
ghzdude Jul 28, 2024
2491727
address reviews
ghzdude Aug 2, 2024
7786efc
store class for type checking
ghzdude Aug 11, 2024
8d83336
utilize new list
ghzdude Aug 11, 2024
bbf145b
update registration to new list
ghzdude Aug 11, 2024
b5370c3
no need for dual handler here anymore
ghzdude Aug 11, 2024
694532c
mark ability as nullable and add default
ghzdude Aug 11, 2024
9e83d60
changes to recipe logic are no longer necessary
ghzdude Aug 11, 2024
6376a61
override more methods
ghzdude Aug 12, 2024
0fb50cc
simplify DualHandler and improve notifiability
ghzdude Aug 12, 2024
48c3ac9
make entry static again
ghzdude Aug 12, 2024
ecab010
add back simple checking of extra fluids from items only when distinc…
ghzdude Aug 13, 2024
8a28d6f
fix dual handler a bit
ghzdude Aug 13, 2024
e75c48f
improve add method
ghzdude Aug 14, 2024
040a5a5
update to `getAbilities()`
ghzdude Aug 14, 2024
7e04dff
fix warning
ghzdude Aug 14, 2024
bce0914
check object type and collect if iterable
ghzdude Aug 14, 2024
4cd8e62
unneeded javadoc
ghzdude Aug 14, 2024
4b62204
throw exception on adding or setting invalid element
ghzdude Aug 14, 2024
b75f2e8
better javadocs
ghzdude Aug 14, 2024
5c7bfa4
remove unnecessary override
ghzdude Aug 14, 2024
8b3d528
always assume a size of one
ghzdude Aug 16, 2024
ccff22d
fix potential npe with EMPTY
ghzdude Aug 16, 2024
66183ff
always check for extra fluids, but only for multis
ghzdude Aug 16, 2024
ff47a7a
do not allow duplicate instances
ghzdude Aug 16, 2024
b3387eb
check fluids in controller init instead of recipe logic
ghzdude Aug 16, 2024
9b0295f
fix fluid voiding?
ghzdude Aug 16, 2024
92caafe
fix tank list creation
ghzdude Aug 16, 2024
35be693
casually rework IMultipleTankHandler to use an extendable interface i…
ghzdude Aug 17, 2024
e716fff
add overloaded method
ghzdude Aug 17, 2024
8018399
remove unnecessary overrides
ghzdude Aug 17, 2024
f15c3b8
spotless
ghzdude Oct 16, 2024
3df691c
add javadoc
ghzdude Dec 31, 2024
a70e49d
improve javadoc slightly
ghzdude Dec 31, 2024
d9656da
improve javadoc slightly
ghzdude Jan 1, 2025
69f24e7
d
ghzdude Jan 1, 2025
52177f4
fix rebase
ghzdude Jan 9, 2025
f268ffa
use reference equals instead
ghzdude Jan 14, 2025
1d4e47b
move circuit inventory to `initializeInventory()`
ghzdude Jan 21, 2025
e80cedd
switch variable names to match MultiFluidTankEntry
ghzdude Jan 21, 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
242 changes: 242 additions & 0 deletions src/main/java/gregtech/api/capability/DualHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, missing some annotations in this class, notnull, etc


private static final ItemStackHashStrategy strategy = ItemStackHashStrategy.builder()
.compareItem(true)
.compareDamage(true)
.compareTag(true)
.compareCount(true)
.build();
@NotNull
IItemHandlerModifiable itemDelegate;
@NotNull
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 (var tank : this.fluidDelegate) {
list.add(new DualEntry(this, tank));
}
this.unwrapped = list;
}

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

public IItemHandlerModifiable getItemDelegate() {
return this.itemDelegate;
}

public IMultipleTankHandler getFluidDelegate() {
return this.fluidDelegate;
}

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

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

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

@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
var remainder = itemDelegate.insertItem(slot, stack, simulate);
if (!simulate && !strategy.equals(remainder, stack))
ghzdude marked this conversation as resolved.
Show resolved Hide resolved
onContentsChanged();
return remainder;
}

@Override
public 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, ItemStack stack) {
var oldStack = itemDelegate.getStackInSlot(slot);
itemDelegate.setStackInSlot(slot, stack);
if (!strategy.equals(oldStack, stack))
ghzdude marked this conversation as resolved.
Show resolved Hide resolved
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 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 IFluidTank getDelegate() {
return this.delegate;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two backwards? Returning the wrong thing for the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with respect to MultiFluidTankEntry, these methods return the correct objects, but their names are reversed


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

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

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

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

// this method might be redundant
private @NotNull ITankEntry getTank() {
return this.delegate;
}

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

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