Search in sources :

Example 1 with BlockGasFluid

use of de.industria.fluids.util.BlockGasFluid in project MCMOD-Industria by M-Marvin.

the class Events method onRightClickBlock.

@SubscribeEvent
public static void onRightClickBlock(net.minecraftforge.event.entity.player.FillBucketEvent event) {
    World worldIn = event.getWorld();
    PlayerEntity playerIn = event.getPlayer();
    RayTraceResult result = event.getTarget();
    Vector3d vec1p = event.getPlayer().getLookAngle();
    int x = (int) (result.getLocation().x % 1 == 0 ? result.getLocation().x + (vec1p.x > 0 ? 0 : -1) : Math.floor(result.getLocation().x));
    int y = (int) (result.getLocation().y % 1 == 0 ? result.getLocation().y + (vec1p.y > 0 ? 0 : -1) : Math.floor(result.getLocation().y));
    int z = (int) (result.getLocation().z % 1 == 0 ? result.getLocation().z + (vec1p.z > 0 ? 0 : -1) : Math.floor(result.getLocation().z));
    BlockPos fluidPos = new BlockPos(x, y, z);
    FluidState fluidState = worldIn.getFluidState(fluidPos);
    if (fluidState.createLegacyBlock().getBlock() instanceof BlockGasFluid && event.getEmptyBucket().getItem() != ModItems.fluid_cannister) {
        ItemStack bucketItem = event.getEmptyBucket();
        if (fluidState.createLegacyBlock().getBlock() instanceof IBucketPickupHandler) {
            Fluid fluid = ((IBucketPickupHandler) fluidState.createLegacyBlock().getBlock()).takeLiquid(worldIn, fluidPos, fluidState.createLegacyBlock());
            if (fluid != Fluids.EMPTY) {
                playerIn.awardStat(Stats.ITEM_USED.get(bucketItem.getItem()));
                SoundEvent soundevent = fluid.is(FluidTags.LAVA) ? SoundEvents.BUCKET_FILL_LAVA : SoundEvents.BUCKET_FILL;
                playerIn.playSound(soundevent, 1.0F, 1.0F);
                ItemStack itemstack1 = DrinkHelper.createFilledResult(bucketItem.copy(), playerIn, new ItemStack(fluid.getBucket()));
                if (!worldIn.isClientSide) {
                    CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayerEntity) playerIn, new ItemStack(fluid.getBucket()));
                    event.setFilledBucket(itemstack1);
                    playerIn.setItemSlot(EquipmentSlotType.MAINHAND, itemstack1);
                }
            }
        }
    }
}
Also used : BlockGasFluid(de.industria.fluids.util.BlockGasFluid) SoundEvent(net.minecraft.util.SoundEvent) IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockGasFluid(de.industria.fluids.util.BlockGasFluid) Fluid(net.minecraft.fluid.Fluid) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FluidState(net.minecraft.fluid.FluidState) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with BlockGasFluid

use of de.industria.fluids.util.BlockGasFluid in project MCMOD-Industria by M-Marvin.

the class TileEntityMFluidOutput method tick.

@SuppressWarnings("deprecation")
@Override
public void tick() {
    if (!this.level.isClientSide()) {
        if (this.fluid.getAmount() >= 1000) {
            BlockPos tankBeginPos = this.worldPosition.relative(this.getBlockState().getValue(BlockMFluidInput.FACING));
            BlockPos outputPos = new FluidTankHelper(this.level, tankBeginPos).insertFluidInTank(this.fluid.getFluid());
            if (!this.fluid.getFluid().getAttributes().isGaseous()) {
                if (outputPos != null) {
                    EntityFallingFluid fallingFluid = new EntityFallingFluid(this.level, tankBeginPos.getX() + 0.5F, tankBeginPos.getY(), tankBeginPos.getZ() + 0.5F, FluidStackStateTagHelper.makeStateFromStack(this.fluid));
                    fallingFluid.setAirSpawned();
                    this.level.addFreshEntity(fallingFluid);
                    this.fluid.shrink(1000);
                }
            } else {
                if (outputPos != null) {
                    FluidState fluidState = FluidStackStateTagHelper.makeStateFromStack(this.fluid);
                    this.level.setBlockAndUpdate(outputPos, fluidState.createLegacyBlock());
                    this.fluid.shrink(1000);
                } else {
                    BlockState replaceState = this.level.getBlockState(tankBeginPos);
                    if (replaceState.getBlock() instanceof BlockGasFluid) {
                        ((BlockGasFluid) replaceState.getBlock()).pushFluid(new ArrayList<BlockPos>(), replaceState, (ServerWorld) this.level, tankBeginPos, level.random);
                        replaceState = this.level.getBlockState(tankBeginPos);
                        if (replaceState.isAir()) {
                            FluidState fluidState = FluidStackStateTagHelper.makeStateFromStack(this.fluid);
                            this.level.setBlockAndUpdate(tankBeginPos, fluidState.createLegacyBlock());
                            this.fluid.shrink(1000);
                        }
                    }
                }
            }
        }
    }
}
Also used : BlockGasFluid(de.industria.fluids.util.BlockGasFluid) BlockState(net.minecraft.block.BlockState) FluidTankHelper(de.industria.util.handler.FluidTankHelper) EntityFallingFluid(de.industria.entity.EntityFallingFluid) BlockPos(net.minecraft.util.math.BlockPos) FluidState(net.minecraft.fluid.FluidState)

Example 3 with BlockGasFluid

use of de.industria.fluids.util.BlockGasFluid in project MCMOD-Industria by M-Marvin.

the class BlockBiomass method compost.

@SuppressWarnings("deprecation")
public void compost(BlockState state, World world, BlockPos pos) {
    if (isHeated(state, world, pos)) {
        BlockPos exhaustPos = pos.above();
        BlockState gasState = ModFluids.BIOGAS.defaultFluidState().createLegacyBlock();
        BlockState replaceState = world.getBlockState(exhaustPos);
        int layers = world.random.nextInt(5) == 0 ? state.getValue(LAYERS) - 1 : state.getValue(LAYERS);
        if (layers == 0) {
            world.setBlockAndUpdate(pos, gasState);
            return;
        }
        if (replaceState.isAir()) {
            world.setBlockAndUpdate(exhaustPos, gasState);
            world.setBlockAndUpdate(pos, this.defaultBlockState().setValue(LAYERS, layers));
            return;
        } else if (replaceState.getBlock() instanceof BlockGasFluid) {
            ((BlockGasFluid) replaceState.getBlock()).pushFluid(new ArrayList<BlockPos>(), replaceState, (ServerWorld) world, exhaustPos, world.random);
            replaceState = world.getBlockState(exhaustPos);
            if (replaceState.isAir()) {
                world.setBlockAndUpdate(exhaustPos, gasState);
                world.setBlockAndUpdate(pos, this.defaultBlockState().setValue(LAYERS, layers));
                return;
            }
        }
    }
}
Also used : BlockGasFluid(de.industria.fluids.util.BlockGasFluid) ServerWorld(net.minecraft.world.server.ServerWorld) BlockState(net.minecraft.block.BlockState) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with BlockGasFluid

use of de.industria.fluids.util.BlockGasFluid in project MCMOD-Industria by M-Marvin.

the class TileEntityMSteamGenerator method tick.

@SuppressWarnings("deprecation")
@Override
public void tick() {
    if (!this.level.isClientSide()) {
        if (BlockMultipart.getInternPartPos(this.getBlockState()).equals(new BlockPos(0, 0, 0))) {
            int capacity = Math.min(this.maxFluid - this.steamOut.getAmount(), this.maxEnergy / wattPerMB);
            int transfer = Math.max(0, Math.min(steamIn.getAmount(), capacity));
            if (transfer > 0) {
                this.steamIn.shrink(transfer);
                if (this.steamOut.isEmpty()) {
                    this.steamOut = new FluidStack(ModFluids.STEAM, transfer);
                } else {
                    this.steamOut.grow(transfer);
                }
                float speed = transfer / (float) (this.maxEnergy / this.wattPerMB);
                this.accerlation = Math.min(20F, this.accerlation + speed * 0.06F);
            } else {
                this.accerlation = Math.max(0F, this.accerlation - 0.04F);
            }
            float capacityEnergy = this.maxEnergy * this.accerlation / 20;
            this.generatedAmperes = capacityEnergy / this.generatedVoltage.getVoltage();
            if (!this.steamOut.isEmpty()) {
                Direction direction = this.getBlockState().getValue(BlockMSteamGenerator.FACING);
                if (this.steamOut.getAmount() >= 1000) {
                    BlockPos pos1 = this.worldPosition.relative(direction.getClockWise()).relative(direction, 1).above();
                    BlockPos pos2 = this.worldPosition.relative(direction.getClockWise()).relative(direction.getOpposite(), 2).above();
                    BlockPos exhaustPos = this.level.random.nextBoolean() ? pos1 : pos2;
                    BlockState replaceState = this.level.getBlockState(exhaustPos);
                    if (replaceState.isAir()) {
                        this.level.setBlockAndUpdate(exhaustPos, this.steamOut.getFluid().defaultFluidState().createLegacyBlock());
                        this.steamOut.shrink(1000);
                    } else if (replaceState.getBlock() instanceof BlockGasFluid) {
                        ((BlockGasFluid) replaceState.getBlock()).pushFluid(new ArrayList<BlockPos>(), replaceState, (ServerWorld) this.level, exhaustPos, level.random);
                        replaceState = this.level.getBlockState(exhaustPos);
                        if (replaceState.isAir()) {
                            this.level.setBlockAndUpdate(exhaustPos, this.steamOut.getFluid().defaultFluidState().createLegacyBlock());
                            this.steamOut.shrink(1000);
                        }
                    }
                }
            }
            this.turbinRotation += this.accerlation;
            if (this.turbinRotation >= 360)
                this.turbinRotation -= 360;
        } else if (BlockMultipart.getInternPartPos(this.getBlockState()).equals(new BlockPos(1, 0, 0)) || BlockMultipart.getInternPartPos(this.getBlockState()).equals(new BlockPos(1, 0, 1))) {
            ElectricityNetworkHandler handler = ElectricityNetworkHandler.getHandlerForWorld(this.level);
            handler.updateNetwork(level, worldPosition);
        }
    } else if (BlockMultipart.getInternPartPos(this.getBlockState()).equals(new BlockPos(0, 0, 0))) {
        MachineSoundHelper.startSoundTurbinIfNotRunning(this);
    }
}
Also used : BlockGasFluid(de.industria.fluids.util.BlockGasFluid) ServerWorld(net.minecraft.world.server.ServerWorld) BlockState(net.minecraft.block.BlockState) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) ElectricityNetworkHandler(de.industria.util.handler.ElectricityNetworkHandler)

Aggregations

BlockGasFluid (de.industria.fluids.util.BlockGasFluid)4 BlockPos (net.minecraft.util.math.BlockPos)4 BlockState (net.minecraft.block.BlockState)3 ArrayList (java.util.ArrayList)2 FluidState (net.minecraft.fluid.FluidState)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 EntityFallingFluid (de.industria.entity.EntityFallingFluid)1 ElectricityNetworkHandler (de.industria.util.handler.ElectricityNetworkHandler)1 FluidTankHelper (de.industria.util.handler.FluidTankHelper)1 IBucketPickupHandler (net.minecraft.block.IBucketPickupHandler)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Fluid (net.minecraft.fluid.Fluid)1 ItemStack (net.minecraft.item.ItemStack)1 Direction (net.minecraft.util.Direction)1 SoundEvent (net.minecraft.util.SoundEvent)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1