-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Backport Reborn Energy support
- Loading branch information
1 parent
5359279
commit e181741
Showing
4 changed files
with
72 additions
and
0 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
19 changes: 19 additions & 0 deletions
19
fabric/src/main/java/net/blay09/mods/balm/fabric/compat/energy/RebornEnergy.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,19 @@ | ||
package net.blay09.mods.balm.fabric.compat.energy; | ||
|
||
import net.blay09.mods.balm.api.energy.BalmEnergyStorageProvider; | ||
import team.reborn.energy.api.EnergyStorage; | ||
|
||
public class RebornEnergy { | ||
public RebornEnergy() { | ||
EnergyStorage.SIDED.registerFallback((world, pos, state, blockEntity, direction) -> { | ||
if (blockEntity instanceof BalmEnergyStorageProvider energyStorageProvider) { | ||
final var energyStorage = energyStorageProvider.getEnergyStorage(direction); | ||
if (energyStorage != null) { | ||
return new RebornEnergyStorage(energyStorage); | ||
} | ||
} | ||
|
||
return null; | ||
}); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
fabric/src/main/java/net/blay09/mods/balm/fabric/compat/energy/RebornEnergyStorage.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,49 @@ | ||
package net.blay09.mods.balm.fabric.compat.energy; | ||
|
||
import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; | ||
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; | ||
import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant; | ||
import team.reborn.energy.api.EnergyStorage; | ||
|
||
public class RebornEnergyStorage extends SnapshotParticipant<Long> implements EnergyStorage { | ||
|
||
private final net.blay09.mods.balm.api.energy.EnergyStorage energyStorage; | ||
|
||
public RebornEnergyStorage(net.blay09.mods.balm.api.energy.EnergyStorage energyStorage) { | ||
this.energyStorage = energyStorage; | ||
} | ||
|
||
@Override | ||
public long insert(long maxAmount, TransactionContext transaction) { | ||
StoragePreconditions.notNegative(maxAmount); | ||
updateSnapshots(transaction); | ||
return energyStorage.fill((int) maxAmount, false); | ||
} | ||
|
||
@Override | ||
public long extract(long maxAmount, TransactionContext transaction) { | ||
StoragePreconditions.notNegative(maxAmount); | ||
updateSnapshots(transaction); | ||
return energyStorage.drain((int) maxAmount, false); | ||
} | ||
|
||
@Override | ||
public long getAmount() { | ||
return energyStorage.getEnergy(); | ||
} | ||
|
||
@Override | ||
public long getCapacity() { | ||
return energyStorage.getCapacity(); | ||
} | ||
|
||
@Override | ||
protected Long createSnapshot() { | ||
return (long) energyStorage.getEnergy(); | ||
} | ||
|
||
@Override | ||
protected void readSnapshot(Long snapshot) { | ||
energyStorage.setEnergy(snapshot.intValue()); | ||
} | ||
} |