fixed diodes voiding energy, fixed side restriction confusion

This commit is contained in:
Boblet 2023-02-09 13:06:07 +01:00
parent 0e334262ac
commit 3ce962018d
11 changed files with 53 additions and 29 deletions

View File

@ -26,6 +26,7 @@ public interface IEnergyConnector extends ILoadedTile {
/**
* Whether the given side can be connected to
* dir refers to the side of this block, not the connecting block doing the check
* @param dir
* @return
*/

View File

@ -58,7 +58,7 @@ public interface IEnergyUser extends IEnergyConnector {
if(te instanceof IEnergyConductor) {
IEnergyConductor con = (IEnergyConductor) te;
if(con.getPowerNet() != null && con.getPowerNet().isSubscribed(this)) {
if(con.canConnect(dir.getOpposite()) && con.getPowerNet() != null && con.getPowerNet().isSubscribed(this)) {
con.getPowerNet().unsubscribe(this);
wasSubscribed = true;
}
@ -105,7 +105,8 @@ public interface IEnergyUser extends IEnergyConnector {
public default void updateStandardConnections(World world, int x, int y, int z) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
this.trySubscribe(world, x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir);
}
}
}

View File

@ -18,8 +18,8 @@ public class RBMKLoader extends BlockGeneric implements IFluidConnectorBlock {
@Override
public boolean canConnect(FluidType type, IBlockAccess world, int x, int y, int z, ForgeDirection dir) {
if(type.hasTrait(FT_Heatable.class)) return dir == ForgeDirection.DOWN;
return type.hasTrait(FT_Coolable.class) && dir != ForgeDirection.DOWN;
if(dir == ForgeDirection.UP) return type.hasTrait(FT_Heatable.class);
return type.hasTrait(FT_Coolable.class);
}
}

View File

@ -107,25 +107,26 @@ public class Library {
/*
* Is putting this into this trash can a good idea? No. Do I have a better idea? Not currently.
*/
public static boolean canConnect(IBlockAccess world, int x, int y, int z, ForgeDirection dir) {
public static boolean canConnect(IBlockAccess world, int x, int y, int z, ForgeDirection dir /* cable's connecting side */) {
if(y > 255 || y < 0)
return false;
Block b = world.getBlock(x, y, z);
TileEntity te = world.getTileEntity(x, y, z);
if(b instanceof IEnergyConnectorBlock) {
IEnergyConnectorBlock con = (IEnergyConnectorBlock) b;
if(con.canConnect(world, x, y, z, dir))
if(con.canConnect(world, x, y, z, dir.getOpposite() /* machine's connecting side */))
return true;
}
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof IEnergyConnector) {
IEnergyConnector con = (IEnergyConnector) te;
if(con.canConnect(dir))
if(con.canConnect(dir.getOpposite() /* machine's connecting side */))
return true;
}
@ -133,25 +134,26 @@ public class Library {
}
/** dir is the direction along the fluid duct entering the block */
public static boolean canConnectFluid(IBlockAccess world, int x, int y, int z, ForgeDirection dir, FluidType type) {
public static boolean canConnectFluid(IBlockAccess world, int x, int y, int z, ForgeDirection dir /* duct's connecting side */, FluidType type) {
if(y > 255 || y < 0)
return false;
Block b = world.getBlock(x, y, z);
TileEntity te = world.getTileEntity(x, y, z);
if(b instanceof IFluidConnectorBlock) {
IFluidConnectorBlock con = (IFluidConnectorBlock) b;
if(con.canConnect(type, world, x, y, z, dir.getOpposite()))
if(con.canConnect(type, world, x, y, z, dir.getOpposite() /* machine's connecting side */))
return true;
}
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof IFluidConnector) {
IFluidConnector con = (IFluidConnector) te;
if(con.canConnect(type, dir.getOpposite()))
if(con.canConnect(type, dir.getOpposite() /* machine's connecting side */))
return true;
}

View File

@ -56,12 +56,12 @@ public class RenderCable implements ISimpleBlockRenderingHandler {
tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
tessellator.setColorOpaque_F(1, 1, 1);
boolean pX = Library.canConnect(world, x + 1, y, z, Library.NEG_X);
boolean nX = Library.canConnect(world, x - 1, y, z, Library.POS_X);
boolean pY = Library.canConnect(world, x, y + 1, z, Library.NEG_Y);
boolean nY = Library.canConnect(world, x, y - 1, z, Library.POS_Y);
boolean pZ = Library.canConnect(world, x, y, z + 1, Library.NEG_Z);
boolean nZ = Library.canConnect(world, x, y, z - 1, Library.POS_Z);
boolean pX = Library.canConnect(world, x + 1, y, z, Library.POS_X);
boolean nX = Library.canConnect(world, x - 1, y, z, Library.NEG_X);
boolean pY = Library.canConnect(world, x, y + 1, z, Library.POS_Y);
boolean nY = Library.canConnect(world, x, y - 1, z, Library.NEG_Y);
boolean pZ = Library.canConnect(world, x, y, z + 1, Library.POS_Z);
boolean nZ = Library.canConnect(world, x, y, z - 1, Library.NEG_Z);
tessellator.addTranslation(x + 0.5F, y + 0.5F, z + 0.5F);

View File

@ -81,12 +81,12 @@ public class RenderTestPipe implements ISimpleBlockRenderingHandler {
tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
tessellator.setColorOpaque_F(1, 1, 1);
boolean pX = Library.canConnectFluid(world, x + 1, y, z, Library.NEG_X, type);
boolean nX = Library.canConnectFluid(world, x - 1, y, z, Library.POS_X, type);
boolean pY = Library.canConnectFluid(world, x, y + 1, z, Library.NEG_Y, type);
boolean nY = Library.canConnectFluid(world, x, y - 1, z, Library.POS_Y, type);
boolean pZ = Library.canConnectFluid(world, x, y, z + 1, Library.NEG_Z, type);
boolean nZ = Library.canConnectFluid(world, x, y, z - 1, Library.POS_Z, type);
boolean pX = Library.canConnectFluid(world, x + 1, y, z, Library.POS_X, type);
boolean nX = Library.canConnectFluid(world, x - 1, y, z, Library.NEG_X, type);
boolean pY = Library.canConnectFluid(world, x, y + 1, z, Library.POS_Y, type);
boolean nY = Library.canConnectFluid(world, x, y - 1, z, Library.NEG_Y, type);
boolean pZ = Library.canConnectFluid(world, x, y, z + 1, Library.POS_Z, type);
boolean nZ = Library.canConnectFluid(world, x, y, z - 1, Library.NEG_Z, type);
int mask = 0 + (pX ? 32 : 0) + (nX ? 16 : 0) + (pY ? 8 : 0) + (nY ? 4 : 0) + (pZ ? 2 : 0) + (nZ ? 1 : 0);

View File

@ -206,7 +206,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
//if it's a cable, buffer both the network and all subscribers of the net
if(te instanceof IEnergyConductor) {
IEnergyConductor con = (IEnergyConductor) te;
if(con.getPowerNet() != null) {
if(con.canConnect(dir.getOpposite()) && con.getPowerNet() != null) {
nets.add(con.getPowerNet());
con.getPowerNet().unsubscribe(this);
consumers.addAll(con.getPowerNet().getSubscribers());

View File

@ -72,7 +72,7 @@ public class TileEntityCableBaseNT extends TileEntity implements IEnergyConducto
@Override
public boolean canConnect(ForgeDirection dir) {
return true;
return dir != ForgeDirection.UNKNOWN;
}
@Override

View File

@ -3,6 +3,8 @@ package com.hbm.tileentity.network;
import java.util.ArrayList;
import java.util.List;
import api.hbm.energy.IEnergyConductor;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
@ -27,14 +29,32 @@ public class TileEntityConnector extends TileEntityPylonBase {
public List<int[]> getConnectionPoints() {
List<int[]> pos = new ArrayList(connected);
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
pos.add(new int[] {xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ});
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()).getOpposite();
//pos.add(new int[] {xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ});
TileEntity te = worldObj.getTileEntity(xCoord, yCoord, zCoord);
if(te instanceof IEnergyConductor) {
IEnergyConductor conductor = (IEnergyConductor) te;
if(conductor.canConnect(dir.getOpposite())) {
if(this.getPowerNet() == null && conductor.getPowerNet() != null) {
conductor.getPowerNet().joinLink(this);
}
if(this.getPowerNet() != null && conductor.getPowerNet() != null && this.getPowerNet() != conductor.getPowerNet()) {
conductor.getPowerNet().joinNetworks(this.getPowerNet());
}
}
}
return pos;
}
@Override
public boolean canConnect(ForgeDirection dir) { //i've about had it with your fucking bullshit
return true;
return ForgeDirection.getOrientation(this.getBlockMetadata()).getOpposite() == dir;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B