parent
b300456e77
commit
7b4306a883
3 changed files with 49 additions and 10 deletions
|
@ -54,7 +54,7 @@ import java.util.List;
|
|||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity implements IListInfoProvider {
|
||||
public final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
|
||||
private final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return PowerAcceptorBlockEntity.this.getMaxStoredPower();
|
||||
|
@ -161,7 +161,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
|
|||
|
||||
EnergyStorageUtil.move(
|
||||
ContainerItemContext.ofSingleSlot(InventoryStorage.of(inventory, null).getSlots().get(slot)).find(EnergyStorage.ITEM),
|
||||
energyContainer.getSideStorage(null),
|
||||
getSideEnergyStorage(null),
|
||||
Long.MAX_VALUE,
|
||||
null
|
||||
);
|
||||
|
@ -188,7 +188,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
|
|||
Inventory inventory = getOptionalInventory().get();
|
||||
|
||||
EnergyStorageUtil.move(
|
||||
energyContainer.getSideStorage(null),
|
||||
getSideEnergyStorage(null),
|
||||
ContainerItemContext.ofSingleSlot(InventoryStorage.of(inventory, null).getSlots().get(slot)).find(EnergyStorage.ITEM),
|
||||
Long.MAX_VALUE,
|
||||
null
|
||||
|
@ -330,7 +330,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
|
|||
|
||||
for (Direction side : Direction.values()) {
|
||||
EnergyStorageUtil.move(
|
||||
energyContainer.getSideStorage(side),
|
||||
getSideEnergyStorage(side),
|
||||
EnergyStorage.SIDED.find(world, pos.offset(side), side.getOpposite()),
|
||||
Long.MAX_VALUE,
|
||||
null
|
||||
|
|
|
@ -31,6 +31,9 @@ import net.minecraft.world.PersistentState;
|
|||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import reborncore.common.util.NBTSerializable;
|
||||
import team.reborn.energy.api.EnergyStorage;
|
||||
import team.reborn.energy.api.base.SimpleEnergyStorage;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
@ -77,8 +80,13 @@ public class IDSUManager extends PersistentState {
|
|||
}
|
||||
|
||||
public class IDSUPlayer implements NBTSerializable {
|
||||
|
||||
private long energy;
|
||||
// This storage is never exposed directly, it's always wrapped behind getMaxInput()/getMaxOutput() checks
|
||||
private final SimpleEnergyStorage storage = new SimpleEnergyStorage(TechRebornConfig.idsuMaxEnergy, Long.MAX_VALUE, Long.MAX_VALUE) {
|
||||
@Override
|
||||
protected void onFinalCommit() {
|
||||
markDirty();
|
||||
}
|
||||
};
|
||||
|
||||
private IDSUPlayer() {
|
||||
}
|
||||
|
@ -91,21 +99,25 @@ public class IDSUManager extends PersistentState {
|
|||
@Override
|
||||
public NbtCompound write() {
|
||||
NbtCompound tag = new NbtCompound();
|
||||
tag.putLong("energy", energy);
|
||||
tag.putLong("energy", storage.amount);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(@NotNull NbtCompound tag) {
|
||||
energy = tag.getLong("energy");
|
||||
storage.amount = tag.getLong("energy");
|
||||
}
|
||||
|
||||
public EnergyStorage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public long getEnergy() {
|
||||
return energy;
|
||||
return storage.amount;
|
||||
}
|
||||
|
||||
public void setEnergy(long energy) {
|
||||
this.energy = energy;
|
||||
storage.amount = energy;
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,15 +24,20 @@
|
|||
|
||||
package techreborn.blockentity.storage.energy.idsu;
|
||||
|
||||
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reborncore.client.screen.BuiltScreenHandlerProvider;
|
||||
import reborncore.client.screen.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.powerSystem.RcEnergyTier;
|
||||
import team.reborn.energy.api.EnergyStorage;
|
||||
import team.reborn.energy.api.base.DelegatingEnergyStorage;
|
||||
import techreborn.blockentity.storage.energy.EnergyStorageBlockEntity;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.TRBlockEntities;
|
||||
|
@ -49,6 +54,28 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
|
|||
super(TRBlockEntities.INTERDIMENSIONAL_SU, pos, state, "IDSU", 2, TRContent.Machine.INTERDIMENSIONAL_SU.block, RcEnergyTier.INSANE, TechRebornConfig.idsuMaxEnergy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnergyStorage getSideEnergyStorage(@Nullable Direction side) {
|
||||
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
||||
return EnergyStorage.EMPTY;
|
||||
}
|
||||
if (world.isClient) {
|
||||
throw new UnsupportedOperationException("Energy API may only be queried on the server side.");
|
||||
}
|
||||
EnergyStorage globalStorage = IDSUManager.getPlayer(world.getServer(), ownerUdid).getStorage();
|
||||
return new DelegatingEnergyStorage(globalStorage, null) {
|
||||
@Override
|
||||
public long insert(long maxAmount, TransactionContext transaction) {
|
||||
return backingStorage.get().insert(Math.min(maxAmount, getMaxInput(side)), transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long extract(long maxAmount, TransactionContext transaction) {
|
||||
return backingStorage.get().extract(Math.min(maxAmount, getMaxOutput(side)), transaction);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStored() {
|
||||
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
||||
|
|
Loading…
Reference in a new issue