use of de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork in project MCMOD-Industria by M-Marvin.
the class IBElectricConnectiveBlock method getNetwork.
public default ElectricityNetwork getNetwork(World worldIn, BlockPos pos) {
ElectricityNetworkHandler handler = ElectricityNetworkHandler.getHandlerForWorld(worldIn);
ElectricityNetwork network = handler.getNetwork(pos);
return network;
}
use of de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork in project MCMOD-Industria by M-Marvin.
the class BlockMFuseBox method beforNetworkChanges.
@Override
public NetworkChangeResult beforNetworkChanges(World world, BlockPos pos, BlockState state, ElectricityNetwork network, int lap) {
ElectricityNetworkHandler handler = ElectricityNetworkHandler.getHandlerForWorld(world);
float needCurrent = 0;
float produsedCurrent = 0;
for (Direction d : Direction.values()) {
if (this.canConnect(d, world, pos, state)) {
ElectricityNetwork networkState = handler.getNetworkState(world, pos, d);
if (networkState.getCapacity() - networkState.getNeedCurrent() > 0.001F) {
produsedCurrent += networkState.getCapacity() - networkState.getNeedCurrent();
} else if (networkState.getNeedCurrent() - networkState.getCapacity() > 0.001F) {
needCurrent += networkState.getNeedCurrent() - networkState.getCapacity();
}
}
}
int maxCurrent = 0;
TileEntity te = world.getBlockEntity(pos);
if (te instanceof TileEntityMFuseBox) {
maxCurrent = ((TileEntityMFuseBox) te).getMaxCurrent();
}
float transferingCurrent = Math.min(needCurrent, produsedCurrent);
boolean overload = transferingCurrent > maxCurrent;
boolean closed = state.getValue(ON);
if (closed && overload) {
world.setBlockAndUpdate(pos, state.setValue(ON, false));
world.playSound(null, pos, SoundEvents.WOODEN_BUTTON_CLICK_ON, SoundCategory.BLOCKS, 1, 0.5F);
return NetworkChangeResult.RETRY;
}
return NetworkChangeResult.CONTINUE;
}
use of de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork in project MCMOD-Industria by M-Marvin.
the class BlockElectricWire method entityInside.
@Override
public void entityInside(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
BlockState stateIn = worldIn.getBlockState(pos);
if (hasOpenEnd(stateIn) && entityIn instanceof LivingEntity) {
ElectricityNetworkHandler handler = ElectricityNetworkHandler.getHandlerForWorld(worldIn);
ElectricityNetwork network = handler.getNetwork(pos);
Voltage voltage = network.getVoltage();
int dammge = voltage.getVoltage() / 100;
if (dammge > 0)
entityIn.hurt(ModDamageSource.ELCTRIC_SHOCK, dammge);
}
}
use of de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork in project MCMOD-Industria by M-Marvin.
the class BlockMTransformatorContact method getEnergy.
public float getEnergy(World world, BlockPos pos) {
List<BlockPos> blocks = getBlocks(world, pos);
ElectricityNetworkHandler handler = ElectricityNetworkHandler.getHandlerForWorld(world);
float recivedEnergy = 0;
int energyOutputs = 0;
for (BlockPos pos2 : blocks) {
BlockState state = world.getBlockState(pos2);
if (state.getBlock() == ModItems.transformator_contact) {
if (state.getValue(INPUT)) {
ElectricityNetwork network = handler.getNetwork(pos2);
if (network.canMachinesRun() == state.getValue(VOLTAGE)) {
float energy = network.getCapacity() * network.getVoltage().getVoltage();
recivedEnergy += energy;
}
} else {
energyOutputs++;
}
}
}
return recivedEnergy / energyOutputs;
}
use of de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork in project MCMOD-Industria by M-Marvin.
the class BlockMTransformatorContact method getNeedEnergy.
public float getNeedEnergy(World world, BlockPos pos) {
List<BlockPos> blocks = getBlocks(world, pos);
ElectricityNetworkHandler handler = ElectricityNetworkHandler.getHandlerForWorld(world);
float needEnergy = 0;
for (BlockPos pos2 : blocks) {
BlockState state = world.getBlockState(pos2);
if (state.getBlock() == ModItems.transformator_contact) {
if (!state.getValue(INPUT)) {
ElectricityNetwork network = handler.getNetwork(pos2);
float energy = network.getVoltage().getVoltage() * network.getNeedCurrent();
needEnergy += energy;
}
}
}
return needEnergy;
}
Aggregations