Increased internal buffer for cable to x6 of transfer rate. Closes #1296

This commit is contained in:
drcrazy 2017-10-12 18:23:50 +03:00
parent b80bf1240d
commit 416361ff3b
2 changed files with 36 additions and 18 deletions

View file

@ -30,14 +30,14 @@ import reborncore.api.power.EnumPowerTier;
import techreborn.init.ModBlocks;
public enum EnumCableType implements IStringSerializable {
COPPER("copper", "techreborn:blocks/cables/copper_cable", 128, 12.0, true, EnumPowerTier.LOW),
TIN("tin", "techreborn:blocks/cables/tin_cable", 32, 12.0, true, EnumPowerTier.MEDIUM),
GOLD("gold", "techreborn:blocks/cables/gold_cable", 512, 12.0, true, EnumPowerTier.MEDIUM),
HV("hv", "techreborn:blocks/cables/hv_cable", 2048, 12.0, true, EnumPowerTier.HIGH),
GLASSFIBER("glassfiber", "techreborn:blocks/cables/glass_fiber_cable", 8192, 12.0, false, EnumPowerTier.HIGH),
ICOPPER("insulatedcopper", "techreborn:blocks/cables/copper_insulated_cable", 128, 10.0, false, EnumPowerTier.LOW),
IGOLD("insulatedgold", "techreborn:blocks/cables/gold_insulated_cable", 512, 10.0, false, EnumPowerTier.MEDIUM),
IHV("insulatedhv", "techreborn:blocks/cables/hv_insulated_cable", 2048, 10.0, false, EnumPowerTier.HIGH);
COPPER("copper", "techreborn:blocks/cables/copper_cable", 128, 12.0, true, EnumPowerTier.MEDIUM),
TIN("tin", "techreborn:blocks/cables/tin_cable", 32, 12.0, true, EnumPowerTier.LOW),
GOLD("gold", "techreborn:blocks/cables/gold_cable", 512, 12.0, true, EnumPowerTier.HIGH),
HV("hv", "techreborn:blocks/cables/hv_cable", 2048, 12.0, true, EnumPowerTier.EXTREME),
GLASSFIBER("glassfiber", "techreborn:blocks/cables/glass_fiber_cable", 8192, 12.0, false, EnumPowerTier.INSANE),
ICOPPER("insulatedcopper", "techreborn:blocks/cables/copper_insulated_cable", 128, 10.0, false, EnumPowerTier.MEDIUM),
IGOLD("insulatedgold", "techreborn:blocks/cables/gold_insulated_cable", 512, 10.0, false, EnumPowerTier.HIGH),
IHV("insulatedhv", "techreborn:blocks/cables/hv_insulated_cable", 2048, 10.0, false, EnumPowerTier.EXTREME);
public String textureName = "minecraft:blocks/iron_block";
public int transferRate = 128;

View file

@ -25,6 +25,7 @@
package techreborn.tiles.cable;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
@ -33,19 +34,24 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import reborncore.api.IListInfoProvider;
import reborncore.common.RebornCoreConfig;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.StringUtils;
import techreborn.blocks.cable.BlockCable;
import techreborn.blocks.cable.EnumCableType;
/**
* Created by modmuss50 on 19/05/2017.
*/
public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
public class TileCable extends TileEntity implements ITickable, IEnergyStorage, IListInfoProvider {
public int power = 0;
private int maxPower = 0;
private int transferRate = 0;
private EnumCableType cableType = null;
@Override
public void update() {
@ -53,8 +59,9 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
return;
}
if (this.maxPower == 0 ){
this.maxPower = getCableType().transferRate * RebornCoreConfig.euPerFU;
if (this.cableType == null ){
this.cableType = getCableType();
this.transferRate = this.cableType.transferRate * RebornCoreConfig.euPerFU;
}
ArrayList<IEnergyStorage> acceptors = new ArrayList<IEnergyStorage>();
@ -81,12 +88,13 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
}
if (cables.size() > 0){
int drain = Math.min(power, maxPower);
int drain = Math.min(power, transferRate);
int energyShare = drain / cables.size();
int remainingEnergy = drain;
if (energyShare > 0) {
for (TileCable cable : cables) {
// Push energy to connected cables
int move = cable.receiveEnergy(Math.min(energyShare, remainingEnergy), false);
if (move > 0) {
remainingEnergy -= move;
@ -97,12 +105,13 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
}
if (acceptors.size() > 0){
int drain = Math.min(power, maxPower);
int drain = Math.min(power, transferRate);
int energyShare = drain / acceptors.size();
int remainingEnergy = drain;
if (energyShare > 0) {
for (IEnergyStorage tile : acceptors){
// Push energy to connected tile acceptors
int move = tile.receiveEnergy(Math.min(energyShare, remainingEnergy), false);
if (move > 0) {
remainingEnergy -= move;
@ -114,7 +123,6 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
}
private EnumCableType getCableType() {
//Todo cache this
return world.getBlockState(pos).getValue(BlockCable.TYPE);
}
@ -124,7 +132,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
return 0;
}
int energyReceived = Math.min(maxPower - power, Math.min(maxPower, maxReceive));
int energyReceived = Math.min(getMaxEnergyStored() - getEnergyStored(), Math.min(transferRate, maxReceive));
if (!simulate)
power += energyReceived;
return energyReceived;
@ -136,7 +144,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
return 0;
}
int energyExtracted = Math.min(power, Math.min(this.maxPower, maxExtract));
int energyExtracted = Math.min(getEnergyStored(), Math.min(transferRate, maxExtract));
if (!simulate)
power -= energyExtracted;
return energyExtracted;
@ -149,7 +157,7 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
@Override
public int getMaxEnergyStored() {
return this.maxPower;
return this.transferRate * 6;
}
@Override
@ -223,4 +231,14 @@ public class TileCable extends TileEntity implements ITickable, IEnergyStorage {
}
return compound;
}
@Override
public void addInfo(List<String> info, boolean isRealTile) {
if (isRealTile) {
info.add(TextFormatting.GRAY + "Transfer Rate: " + TextFormatting.GOLD
+ PowerSystem.getLocaliszedPowerFormatted(this.transferRate / RebornCoreConfig.euPerFU) + "/t");
info.add(TextFormatting.GRAY + "Tier: " + TextFormatting.GOLD
+ StringUtils.toFirstCapitalAllLowercase(this.cableType.tier.toString()));
}
}
}