LESU I\O logic change. Closes #1978

This commit is contained in:
drcrazy 2020-01-21 01:51:17 +03:00
parent 40cb57d451
commit ae691fcfc5
5 changed files with 105 additions and 71 deletions

View file

@ -118,7 +118,7 @@ public class DataDrivenBEProvider extends BlockEntityType<DataDrivenBEProvider.D
super(provider, provider.getSimpleName(), provider.maxInput, provider.energy, provider.block, provider.getEnergySlot());
this.provider = provider;
RebornRecipeType recipeType = ModRecipes.byName(provider.identifier);
RebornRecipeType<?> recipeType = ModRecipes.byName(provider.identifier);
Validate.notNull(recipeType);
this.inventory = new RebornInventory<>(provider.slots.size(), provider.getSimpleName() + "BlockEntity", 64, this);

View file

@ -24,6 +24,7 @@
package techreborn.blockentity.storage.energy.lesu;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@ -43,27 +44,27 @@ public class LSUStorageBlockEntity extends MachineBaseBlockEntity
super(TRBlockEntities.LSU_STORAGE);
}
public final void findAndJoinNetwork(World world, int x, int y, int z) {
public final void findAndJoinNetwork(World world, BlockPos pos) {
network = new LesuNetwork();
network.addElement(this);
for (Direction direction : Direction.values()) {
if (world.getBlockEntity(new BlockPos(x + direction.getOffsetX(), y + direction.getOffsetY(),
z + direction.getOffsetZ())) instanceof LSUStorageBlockEntity) {
LSUStorageBlockEntity lesu = (LSUStorageBlockEntity) world.getBlockEntity(new BlockPos(x + direction.getOffsetX(),
y + direction.getOffsetY(), z + direction.getOffsetZ()));
if (lesu.network != null) {
lesu.network.merge(network);
}
BlockEntity be = world.getBlockEntity(pos.offset(direction));
if (!(be instanceof LSUStorageBlockEntity)) {
continue;
}
LSUStorageBlockEntity lesuStorage = (LSUStorageBlockEntity) be;
if (lesuStorage.network != null) {
lesuStorage.network.merge(network);
}
}
}
public final void setNetwork(LesuNetwork n) {
if (n == null) {
} else {
network = n;
network.addElement(this);
return;
}
network = n;
network.addElement(this);
}
public final void resetNetwork() {
@ -72,14 +73,15 @@ public class LSUStorageBlockEntity extends MachineBaseBlockEntity
public final void removeFromNetwork() {
if (network == null) {
} else
network.removeElement(this);
return;
}
network.removeElement(this);
}
public final void rebuildNetwork() {
removeFromNetwork();
resetNetwork();
findAndJoinNetwork(world, pos.getX(), pos.getY(), pos.getZ());
findAndJoinNetwork(world, pos);
}
// TileMachineBase
@ -87,7 +89,7 @@ public class LSUStorageBlockEntity extends MachineBaseBlockEntity
public void tick() {
super.tick();
if (network == null) {
findAndJoinNetwork(world, pos.getX(), pos.getY(), pos.getZ());
findAndJoinNetwork(world, pos);
} else {
if (network.master != null
&& network.master.getWorld().getBlockEntity(new BlockPos(network.master.getPos().getX(),

View file

@ -43,44 +43,73 @@ import java.util.ArrayList;
public class LapotronicSUBlockEntity extends EnergyStorageBlockEntity implements IContainerProvider{
public int connectedBlocks = 0;
private int connectedBlocks = 0;
private ArrayList<LesuNetwork> countedNetworks = new ArrayList<>();
public LapotronicSUBlockEntity() {
super(TRBlockEntities.LAPOTRONIC_SU, "LESU", 2, TRContent.Machine.LAPOTRONIC_SU.block, EnergyTier.LOW, 1_000_000);
super(TRBlockEntities.LAPOTRONIC_SU, "LESU", 2, TRContent.Machine.LAPOTRONIC_SU.block, EnergyTier.LOW, TechRebornConfig.lesuStoragePerBlock);
checkOverfill = false;
this.maxOutput = TechRebornConfig.lesuBaseOutput;
}
private void setMaxStorage(){
maxStorage = (connectedBlocks + 1) * TechRebornConfig.lesuStoragePerBlock;
if (maxStorage < 0 || maxStorage > Integer.MAX_VALUE) {
maxStorage = Integer.MAX_VALUE;
}
}
private void setIORate(){
maxOutput = TechRebornConfig.lesuBaseOutput + (connectedBlocks * TechRebornConfig.lesuExtraIOPerBlock);
if (connectedBlocks < 32) {
return;
}
else if (connectedBlocks < 128) {
maxInput = EnergyTier.MEDIUM.getMaxInput();
}
else {
maxInput = EnergyTier.HIGH.getMaxInput();
}
}
private void checkNetwork() {
countedNetworks.clear();
connectedBlocks = 0;
for (Direction dir : Direction.values()) {
BlockEntity adjacent = world.getBlockEntity(pos.offset(dir));
if (!(adjacent instanceof LSUStorageBlockEntity)) {
continue;
}
LesuNetwork network = ((LSUStorageBlockEntity) adjacent).network;
if (network == null) {
continue;
}
if (countedNetworks.contains(network)) {
continue;
}
if (network.master == null || network.master == this) {
connectedBlocks += network.storages.size();
countedNetworks.add(network);
network.master = this;
break;
}
}
}
// EnergyStorageBlockEntity
@Override
public void tick() {
super.tick();
if (world.isClient) {
return;
}
countedNetworks.clear();
connectedBlocks = 0;
for (Direction dir : Direction.values()) {
BlockPos adjucentBlockPos = getPos().offset(dir);
BlockEntity adjucent = world.getBlockEntity(adjucentBlockPos);
if (!(adjucent instanceof LSUStorageBlockEntity)) {
continue;
}
if (((LSUStorageBlockEntity) adjucent).network == null) {
continue;
}
LesuNetwork network = ((LSUStorageBlockEntity) adjucent).network;
if (!countedNetworks.contains(network)) {
if (network.master == null || network.master == this) {
connectedBlocks += network.storages.size();
countedNetworks.add(network);
network.master = this;
break;
}
}
if (world.getTime() % 20 == 0) {
checkNetwork();
}
setMaxStorage();
maxOutput = (connectedBlocks * TechRebornConfig.lesuExtraIOPerBlock) + tier.getMaxOutput();
setIORate();
if (getEnergy() > getMaxStoredPower()) {
setEnergy(getMaxStoredPower());
@ -95,38 +124,40 @@ public class LapotronicSUBlockEntity extends EnergyStorageBlockEntity implements
}
return null;
}
public int getOutputRate() {
return maxOutput;
}
public void setOutputRate(int output) {
this.maxOutput = output;
}
public int getConnectedBlocksNum() {
return connectedBlocks;
}
public void setConnectedBlocksNum(int value) {
this.connectedBlocks = value;
if (world.isClient) {
setMaxStorage();
}
}
public void setMaxStorage(){
maxStorage = (connectedBlocks + 1) * TechRebornConfig.lesuStoragePerBlock;
if (maxStorage < 0 || maxStorage > Integer.MAX_VALUE) {
maxStorage = Integer.MAX_VALUE;
}
}
// IContainerProvider
@Override
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
return new ContainerBuilder("lesu").player(player.inventory).inventory().hotbar().armor().complete(8, 18)
.addArmor().addInventory().blockEntity(this).energySlot(0, 62, 45).energySlot(1, 98, 45).syncEnergyValue()
.sync(this::getOutputRate, this::setOutputRate)
.sync(this::getConnectedBlocksNum, this::setConnectedBlocksNum).addInventory().create(this, syncID);
}
// public int getOutputRate() {
// return maxOutput;
// }
//
// public void setOutputRate(int output) {
// this.maxOutput = output;
// }
//
// public int getInputRate(){
// return maxInput;
// }
//
// public void setInputRate(int input){
// this.maxInput = input;
// }
public int getConnectedBlocksNum() {
return connectedBlocks;
}
public void setConnectedBlocksNum(int value) {
this.connectedBlocks = value;
if (world.isClient) {
setMaxStorage();
setIORate();
}
}
}

View file

@ -46,15 +46,13 @@ public class LesuNetwork {
private void rebuild() {
master = null;
for (LSUStorageBlockEntity lesuStorage : storages) {
lesuStorage.findAndJoinNetwork(lesuStorage.getWorld(), lesuStorage.getPos().getX(),
lesuStorage.getPos().getY(), lesuStorage.getPos().getZ());
lesuStorage.findAndJoinNetwork(lesuStorage.getWorld(), lesuStorage.getPos());
}
}
public void merge(LesuNetwork network) {
if (network != this) {
ArrayList<LSUStorageBlockEntity> blockEntityLesuStorages = new ArrayList<>();
blockEntityLesuStorages.addAll(network.storages);
ArrayList<LSUStorageBlockEntity> blockEntityLesuStorages = new ArrayList<>(network.storages);
network.clear(false);
for (LSUStorageBlockEntity lesuStorage : blockEntityLesuStorages) {
lesuStorage.setNetwork(this);

View file

@ -313,7 +313,10 @@ public class TechRebornConfig {
public static int lesuStoragePerBlock = 1_000_000;
@Config(config = "machines", category = "lesu", key = "LesuExtraIO", comment = "LESU Extra I/O Multiplier")
public static int lesuExtraIOPerBlock = 8;
public static int lesuExtraIOPerBlock = 1;
@Config(config = "machines", category = "lesu", key = "LesuBaseOutput", comment = "LESU Base Output")
public static int lesuBaseOutput = 5;
@Config(config = "machines", category = "aesu", key = "AesuMaxEnergy", comment = "AESU Max Energy")
public static int aesuMaxEnergy = 100_000_000;