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);
}
}
}
}
}
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);
}
}
}
}
}
}
}
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;
}
}
}
}
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);
}
}
Aggregations