A load of fixes to the power net, should be better, but needs testing

This commit is contained in:
modmuss50 2016-03-20 15:32:22 +00:00
parent 5460f2f9a2
commit 8f3811c9d8
2 changed files with 33 additions and 4 deletions

View file

@ -159,6 +159,9 @@ public abstract class CableMultipart extends Multipart implements INormallyOcclu
public void onNeighborBlockChange(Block block) {
super.onNeighborBlockChange(block);
nearByChange();
if(network != null){
network.buildEndpoint();
}
findAndJoinNetwork(getWorld(), getPos());
}
@ -174,7 +177,7 @@ public abstract class CableMultipart extends Multipart implements INormallyOcclu
}
}
public CableMultipart getPartFromWorld(World world, BlockPos pos, EnumFacing side) {
public static CableMultipart getPartFromWorld(World world, BlockPos pos, EnumFacing side) {
if(world == null || pos == null){
return null;
}

View file

@ -3,6 +3,7 @@ package techreborn.power;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import reborncore.api.power.IEnergyInterfaceTile;
@ -47,6 +48,9 @@ public class TRPowerNet {
}
cables.removeAll(oldCables);
}
if(tick % 1200 == 0){
buildEndpoint();
}
if (!cables.isEmpty()) {
ArrayList<EnergyHandler> collectibles = new ArrayList();
ArrayList<EnergyHandler> insertibles = new ArrayList();
@ -64,6 +68,8 @@ public class TRPowerNet {
energy += handler.collectEnergy(cableType.transferRate);
}
System.out.println("energy + " + energy + this);
for (EnergyHandler handler : insertibles) {
energy -= handler.addEnergy(Math.min(energy, cableType.transferRate));
}
@ -84,7 +90,26 @@ public class TRPowerNet {
this.rebuild();
}
private void rebuild() {
public void buildEndpoint(){
for(CableMultipart cable : cables){
for(EnumFacing facing : EnumFacing.VALUES){
BlockPos pos = cable.getPos().offset(facing);
TileEntity tile = cable.getWorld().getTileEntity(pos);
if(tile != null && tile instanceof IEnergyInterfaceTile){
IEnergyInterfaceTile eit = (IEnergyInterfaceTile) tile;
addConnection(eit, facing);
}
CableMultipart cableMultipart = CableMultipart.getPartFromWorld(cable.getWorld(), pos, null);
if(cableMultipart != null){
if(cableMultipart.getNetwork() != this){
cableMultipart.findAndJoinNetwork(cableMultipart.getWorld(), cableMultipart.getPos());
}
}
}
}
}
public void rebuild() {
for (int i = 0; i < cables.size(); i++) {
CableMultipart te = cables.get(i);
te.setNetwork(null);
@ -124,6 +149,7 @@ public class TRPowerNet {
CableMultipart wire = li.get(i);
wire.setNetwork(this);
}
rebuild();
MinecraftForge.EVENT_BUS.unregister(n);
}
}
@ -190,7 +216,7 @@ public class TRPowerNet {
public int collectEnergy(int max) {
int total = 0;
if (tile.canProvideEnergy(EnumFacing.NORTH)) {
if (tile.canProvideEnergy(side)) {
int collect = (int) Math.min(max, tile.getMaxOutput());
total = (int) tile.useEnergy(collect, false);
}
@ -199,7 +225,7 @@ public class TRPowerNet {
public int addEnergy(int max) {
int total = 0;
if (tile.canAcceptEnergy(EnumFacing.NORTH) && max > 0) {
if (tile.canAcceptEnergy(side.getOpposite()) && max > 0) {
if (type.tier.ordinal() > tile.getTier().ordinal()) {
if (tile instanceof TileEntity) {
((TileEntity) tile).getWorld().createExplosion(new EntityTNTPrimed(((TileEntity) tile).getWorld()), ((TileEntity) tile).getPos().getX(), ((TileEntity) tile).getPos().getY(), ((TileEntity) tile).getPos().getZ(), 2.5F, true);