-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for draconic evolution (#37)
- Loading branch information
Showing
9 changed files
with
265 additions
and
15 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
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
102 changes: 102 additions & 0 deletions
102
src/main/java/se/gory_moon/chargers/compat/bc/BrandonsCoreCompat.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,102 @@ | ||
package se.gory_moon.chargers.compat.bc; | ||
|
||
import com.brandon3055.brandonscore.api.power.IOPStorage; | ||
import com.brandon3055.brandonscore.capability.CapabilityOP; | ||
import it.unimi.dsi.fastutil.Pair; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.util.LazyOptional; | ||
import net.minecraftforge.energy.IEnergyStorage; | ||
import net.minecraftforge.fml.ModList; | ||
import org.jetbrains.annotations.NotNull; | ||
import se.gory_moon.chargers.power.CustomEnergyStorage; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class BrandonsCoreCompat { | ||
public static BrandonsCoreCompat INSTANCE = new BrandonsCoreCompat(); | ||
private final boolean loaded; | ||
|
||
private BrandonsCoreCompat() { | ||
loaded = ModList.get().isLoaded("brandonscore"); | ||
} | ||
|
||
/** | ||
* Returns if BrandonsCore is loaded or not | ||
* | ||
* @return The mod is loaded or not | ||
*/ | ||
public boolean isLoaded() { | ||
return loaded; | ||
} | ||
|
||
/** | ||
* Tries to extract from an OP Storage | ||
* | ||
* @param storage The storage to check | ||
* @param extractAmount The max amount to extract | ||
* @return The amount that was successfully extracted, or empty if the storage wasn't an IOPStorage | ||
*/ | ||
public Optional<Long> extractAmount(IEnergyStorage storage, long extractAmount) { | ||
if (storage instanceof IOPStorage opStorage) { | ||
return Optional.of(opStorage.extractOP(extractAmount, false)); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
/** | ||
* Tries to receive energy into an OP Storage | ||
* | ||
* @param storage The storage to check | ||
* @param receiveAmount The max amount to insert | ||
* @return The amount that was successfully inserted, or empty if the storage wasn't an IOPStorage | ||
*/ | ||
public Optional<Long> receiveAmount(IEnergyStorage storage, long receiveAmount) { | ||
if (storage instanceof IOPStorage opStorage) { | ||
return Optional.of(opStorage.receiveOP(receiveAmount, false)); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
/** | ||
* Checks if the storage is full or not | ||
* | ||
* @param storage The storage to check | ||
* @return If the storage is full or not, or empty if the storage wasn't an IOPStorage | ||
*/ | ||
public Optional<Boolean> isStorageFull(IEnergyStorage storage) { | ||
if (storage instanceof IOPStorage opStorage) { | ||
return Optional.of(opStorage.getOPStored() >= opStorage.getMaxOPStored()); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
/** | ||
* Checks if BrandonsCore is loaded and that the provided capability is an OP cap | ||
* | ||
* @param cap The cap to check | ||
* @param <T> The cap type | ||
* @return If the provided cap is a OP cap | ||
*/ | ||
public <T> boolean isOpCapability(@NotNull Capability<T> cap) { | ||
if (loaded) { | ||
return cap == CapabilityOP.OP; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Creates a wrapper around the provided storage, invalidates any previous lazy optionals if available. | ||
* | ||
* @param storage The storage to wrap | ||
* @param compatWrappers The map holding the wrappers | ||
*/ | ||
public void createOpWrapper(CustomEnergyStorage storage, Map<Capability<?>, Pair<IEnergyStorage, LazyOptional<IEnergyStorage>>> compatWrappers) { | ||
if (compatWrappers.containsKey(CapabilityOP.OP)) { | ||
compatWrappers.get(CapabilityOP.OP).second().invalidate(); | ||
} | ||
var opWrapper = new OpStorageWrapper(storage); | ||
compatWrappers.put(CapabilityOP.OP, Pair.of(opWrapper, LazyOptional.of(() -> opWrapper))); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/se/gory_moon/chargers/compat/bc/OpStorageWrapper.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,99 @@ | ||
package se.gory_moon.chargers.compat.bc; | ||
|
||
import com.brandon3055.brandonscore.api.power.IOInfo; | ||
import com.brandon3055.brandonscore.api.power.IOPStorage; | ||
import org.jetbrains.annotations.Nullable; | ||
import se.gory_moon.chargers.power.CustomEnergyStorage; | ||
|
||
public class OpStorageWrapper implements IOPStorage { | ||
private final CustomEnergyStorage storage; | ||
private final CustomIOInfo info; | ||
|
||
public OpStorageWrapper(CustomEnergyStorage storage) { | ||
this.storage = storage; | ||
this.info = new CustomIOInfo(storage); | ||
} | ||
|
||
@Override | ||
public long receiveOP(long maxReceive, boolean simulate) { | ||
return storage.receiveLongEnergy(maxReceive, simulate); | ||
} | ||
|
||
@Override | ||
public long extractOP(long maxExtract, boolean simulate) { | ||
return storage.extractLongEnergy(maxExtract, simulate); | ||
} | ||
|
||
@Override | ||
public int receiveEnergy(int maxReceive, boolean simulate) { | ||
return storage.receiveEnergy(maxReceive, simulate); | ||
} | ||
|
||
@Override | ||
public int extractEnergy(int maxExtract, boolean simulate) { | ||
return storage.extractEnergy(maxExtract, simulate); | ||
} | ||
|
||
@Override | ||
public long getMaxOPStored() { | ||
return storage.getLongMaxEnergyStored(); | ||
} | ||
|
||
@Override | ||
public long getOPStored() { | ||
return storage.getLongEnergyStored(); | ||
} | ||
|
||
@Override | ||
public int getEnergyStored() { | ||
return storage.getEnergyStored(); | ||
} | ||
|
||
@Override | ||
public int getMaxEnergyStored() { | ||
return storage.getMaxEnergyStored(); | ||
} | ||
|
||
@Override | ||
public boolean canExtract() { | ||
return storage.canExtract(); | ||
} | ||
|
||
@Override | ||
public boolean canReceive() { | ||
return storage.canReceive(); | ||
} | ||
|
||
@Override | ||
public long maxExtract() { | ||
return storage.getMaxOutput(); | ||
} | ||
|
||
@Override | ||
public long maxReceive() { | ||
return storage.getMaxInput(); | ||
} | ||
|
||
@Override | ||
public long modifyEnergyStored(long amount) { | ||
storage.setEnergy(amount); | ||
return Math.abs(amount); | ||
} | ||
|
||
@Override | ||
public @Nullable IOInfo getIOInfo() { | ||
return info; | ||
} | ||
|
||
public record CustomIOInfo(CustomEnergyStorage storage) implements IOInfo { | ||
@Override | ||
public long currentInput() { | ||
return storage.getAverageIn(); | ||
} | ||
|
||
@Override | ||
public long currentOutput() { | ||
return storage.getAverageOut(); | ||
} | ||
} | ||
} |
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.