Search in sources :

Example 1 with ElectricityNetwork

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;
}
Also used : ElectricityNetworkHandler(de.industria.util.handler.ElectricityNetworkHandler) ElectricityNetwork(de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork)

Example 2 with ElectricityNetwork

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityMFuseBox(de.industria.tileentity.TileEntityMFuseBox) Direction(net.minecraft.util.Direction) ElectricityNetworkHandler(de.industria.util.handler.ElectricityNetworkHandler) ElectricityNetwork(de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork)

Example 3 with ElectricityNetwork

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);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) BlockState(net.minecraft.block.BlockState) ElectricityNetworkHandler(de.industria.util.handler.ElectricityNetworkHandler) ElectricityNetwork(de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork)

Example 4 with ElectricityNetwork

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;
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) ElectricityNetworkHandler(de.industria.util.handler.ElectricityNetworkHandler) ElectricityNetwork(de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork)

Example 5 with ElectricityNetwork

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;
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) ElectricityNetworkHandler(de.industria.util.handler.ElectricityNetworkHandler) ElectricityNetwork(de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork)

Aggregations

ElectricityNetwork (de.industria.util.handler.ElectricityNetworkHandler.ElectricityNetwork)32 ElectricityNetworkHandler (de.industria.util.handler.ElectricityNetworkHandler)13 BlockPos (net.minecraft.util.math.BlockPos)9 ItemStack (net.minecraft.item.ItemStack)8 BlockState (net.minecraft.block.BlockState)6 IParticleData (net.minecraft.particles.IParticleData)6 Direction (net.minecraft.util.Direction)6 FluidStack (net.minecraftforge.fluids.FluidStack)6 LivingEntity (net.minecraft.entity.LivingEntity)3 ITickableTileEntity (net.minecraft.tileentity.ITickableTileEntity)3 TileEntity (net.minecraft.tileentity.TileEntity)3 Entity (net.minecraft.entity.Entity)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ItemParticleData (net.minecraft.particles.ItemParticleData)2 BlockMultipart (de.industria.blocks.BlockMultipart)1 AlloyRecipe (de.industria.recipetypes.AlloyRecipe)1 BlastFurnaceRecipe (de.industria.recipetypes.BlastFurnaceRecipe)1 BlendingRecipe (de.industria.recipetypes.BlendingRecipe)1 FluidBathRecipe (de.industria.recipetypes.FluidBathRecipe)1