-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Quantum Storage Controller Network (#1963)
Co-authored-by: Serenibyss <dane@strandboge.com>
- Loading branch information
1 parent
067d32f
commit ebc0338
Showing
47 changed files
with
1,620 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package gregtech.api.capability; | ||
|
||
import net.minecraftforge.items.IItemHandler; | ||
|
||
public interface IDualHandler { | ||
|
||
boolean hasFluidTanks(); | ||
|
||
boolean hasItemHandlers(); | ||
|
||
IMultipleTankHandler getFluidTanks(); | ||
|
||
IItemHandler getItemHandlers(); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/gregtech/api/capability/IQuantumController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package gregtech.api.capability; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraftforge.common.capabilities.ICapabilityProvider; | ||
|
||
// ICapabilityProvider is needed because getCapability is called in the quantum proxy against this interface | ||
public interface IQuantumController extends ICapabilityProvider { | ||
|
||
/** | ||
* Constructs the network upon placement and when storages are added/removed | ||
* <br /> | ||
*/ | ||
void rebuildNetwork(); | ||
|
||
/** | ||
* Return whether this storage block can connect. Can be used to implement a maximum distance from controller for | ||
* example. | ||
*/ | ||
boolean canConnect(IQuantumStorage<?> storage); | ||
|
||
BlockPos getPos(); | ||
|
||
IDualHandler getHandler(); | ||
|
||
boolean isPowered(); | ||
|
||
long getEnergyUsage(); | ||
|
||
int getCount(IQuantumStorage.Type type); | ||
|
||
long getTypeEnergy(IQuantumStorage<?> storage); | ||
|
||
void updateHandler(); | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/gregtech/api/capability/IQuantumStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package gregtech.api.capability; | ||
|
||
import gregtech.api.cover.CoverableView; | ||
import gregtech.api.metatileentity.MetaTileEntity; | ||
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; | ||
|
||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface IQuantumStorage<T> extends CoverableView { | ||
|
||
Type getType(); | ||
|
||
void setConnected(IQuantumController controller); | ||
|
||
void setDisconnected(); | ||
|
||
BlockPos getControllerPos(); | ||
|
||
@Nullable | ||
IQuantumController getQuantumController(); | ||
|
||
BlockPos getPos(); | ||
|
||
default boolean isConnected() { | ||
// use controllerPos here because it is synced | ||
// on both sides, where controller is not | ||
return getControllerPos() != null; | ||
} | ||
|
||
default void tryFindNetwork() { | ||
for (EnumFacing facing : EnumFacing.VALUES) { | ||
var offset = getPos().offset(facing); | ||
var state = getWorld().getBlockState(offset); | ||
if (state.getBlock().isAir(state, getWorld(), offset)) continue; | ||
MetaTileEntity mte; | ||
if (getNeighbor(facing) instanceof IGregTechTileEntity gtte) { | ||
mte = gtte.getMetaTileEntity(); | ||
} else { | ||
continue; | ||
} | ||
|
||
IQuantumController candidate = null; | ||
if (mte instanceof IQuantumStorage<?>storage) { | ||
if (storage.isConnected()) { | ||
IQuantumController controller = storage.getQuantumController(); | ||
if (controller != null && controller.canConnect(this)) { | ||
candidate = controller; | ||
} | ||
} | ||
} else if (mte instanceof IQuantumController quantumController) { | ||
if (quantumController.canConnect(this)) { | ||
candidate = quantumController; | ||
} | ||
} | ||
if (candidate != null) { | ||
candidate.rebuildNetwork(); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
T getTypeValue(); | ||
|
||
enum Type { | ||
|
||
ITEM, | ||
FLUID, | ||
EXTENDER, | ||
PROXY, | ||
ENERGY; | ||
|
||
public static final Type[] VALUES = values(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.