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;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity implements IListInfoProvider {
|
public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity implements IListInfoProvider {
|
||||||
public final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
|
private final SimpleSidedEnergyContainer energyContainer = new SimpleSidedEnergyContainer() {
|
||||||
@Override
|
@Override
|
||||||
public long getCapacity() {
|
public long getCapacity() {
|
||||||
return PowerAcceptorBlockEntity.this.getMaxStoredPower();
|
return PowerAcceptorBlockEntity.this.getMaxStoredPower();
|
||||||
|
@ -161,7 +161,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
|
||||||
|
|
||||||
EnergyStorageUtil.move(
|
EnergyStorageUtil.move(
|
||||||
ContainerItemContext.ofSingleSlot(InventoryStorage.of(inventory, null).getSlots().get(slot)).find(EnergyStorage.ITEM),
|
ContainerItemContext.ofSingleSlot(InventoryStorage.of(inventory, null).getSlots().get(slot)).find(EnergyStorage.ITEM),
|
||||||
energyContainer.getSideStorage(null),
|
getSideEnergyStorage(null),
|
||||||
Long.MAX_VALUE,
|
Long.MAX_VALUE,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
@ -188,7 +188,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
|
||||||
Inventory inventory = getOptionalInventory().get();
|
Inventory inventory = getOptionalInventory().get();
|
||||||
|
|
||||||
EnergyStorageUtil.move(
|
EnergyStorageUtil.move(
|
||||||
energyContainer.getSideStorage(null),
|
getSideEnergyStorage(null),
|
||||||
ContainerItemContext.ofSingleSlot(InventoryStorage.of(inventory, null).getSlots().get(slot)).find(EnergyStorage.ITEM),
|
ContainerItemContext.ofSingleSlot(InventoryStorage.of(inventory, null).getSlots().get(slot)).find(EnergyStorage.ITEM),
|
||||||
Long.MAX_VALUE,
|
Long.MAX_VALUE,
|
||||||
null
|
null
|
||||||
|
@ -330,7 +330,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
|
||||||
|
|
||||||
for (Direction side : Direction.values()) {
|
for (Direction side : Direction.values()) {
|
||||||
EnergyStorageUtil.move(
|
EnergyStorageUtil.move(
|
||||||
energyContainer.getSideStorage(side),
|
getSideEnergyStorage(side),
|
||||||
EnergyStorage.SIDED.find(world, pos.offset(side), side.getOpposite()),
|
EnergyStorage.SIDED.find(world, pos.offset(side), side.getOpposite()),
|
||||||
Long.MAX_VALUE,
|
Long.MAX_VALUE,
|
||||||
null
|
null
|
||||||
|
|
|
@ -31,6 +31,9 @@ import net.minecraft.world.PersistentState;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import reborncore.common.util.NBTSerializable;
|
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;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@ -77,8 +80,13 @@ public class IDSUManager extends PersistentState {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IDSUPlayer implements NBTSerializable {
|
public class IDSUPlayer implements NBTSerializable {
|
||||||
|
// This storage is never exposed directly, it's always wrapped behind getMaxInput()/getMaxOutput() checks
|
||||||
private long energy;
|
private final SimpleEnergyStorage storage = new SimpleEnergyStorage(TechRebornConfig.idsuMaxEnergy, Long.MAX_VALUE, Long.MAX_VALUE) {
|
||||||
|
@Override
|
||||||
|
protected void onFinalCommit() {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private IDSUPlayer() {
|
private IDSUPlayer() {
|
||||||
}
|
}
|
||||||
|
@ -91,21 +99,25 @@ public class IDSUManager extends PersistentState {
|
||||||
@Override
|
@Override
|
||||||
public NbtCompound write() {
|
public NbtCompound write() {
|
||||||
NbtCompound tag = new NbtCompound();
|
NbtCompound tag = new NbtCompound();
|
||||||
tag.putLong("energy", energy);
|
tag.putLong("energy", storage.amount);
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(@NotNull NbtCompound tag) {
|
public void read(@NotNull NbtCompound tag) {
|
||||||
energy = tag.getLong("energy");
|
storage.amount = tag.getLong("energy");
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnergyStorage getStorage() {
|
||||||
|
return storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getEnergy() {
|
public long getEnergy() {
|
||||||
return energy;
|
return storage.amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnergy(long energy) {
|
public void setEnergy(long energy) {
|
||||||
this.energy = energy;
|
storage.amount = energy;
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,15 +24,20 @@
|
||||||
|
|
||||||
package techreborn.blockentity.storage.energy.idsu;
|
package techreborn.blockentity.storage.energy.idsu;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import reborncore.client.screen.BuiltScreenHandlerProvider;
|
import reborncore.client.screen.BuiltScreenHandlerProvider;
|
||||||
import reborncore.client.screen.builder.BuiltScreenHandler;
|
import reborncore.client.screen.builder.BuiltScreenHandler;
|
||||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||||
import reborncore.common.powerSystem.RcEnergyTier;
|
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.blockentity.storage.energy.EnergyStorageBlockEntity;
|
||||||
import techreborn.config.TechRebornConfig;
|
import techreborn.config.TechRebornConfig;
|
||||||
import techreborn.init.TRBlockEntities;
|
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);
|
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
|
@Override
|
||||||
public long getStored() {
|
public long getStored() {
|
||||||
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
if (ownerUdid == null || ownerUdid.isEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue