Search in sources :

Example 6 with Fluid

use of net.minecraft.fluid.Fluid in project AgriCraft by AgriCraft.

the class BlockCropSticks method onFluidChanged.

@Override
protected boolean onFluidChanged(World world, BlockPos pos, BlockState state, Fluid oldFluid, Fluid newFluid) {
    Optional<IAgriCrop> optCrop = this.getCrop(world, pos);
    boolean noMorePlant = optCrop.map(crop -> {
        if (!crop.hasPlant()) {
            return true;
        }
        IAgriGrowthResponse response = crop.getPlant().getGrowthRequirement(crop.getGrowthStage()).getFluidResponse(newFluid, crop.getStats().getStrength());
        if (response.killInstantly()) {
            response.onPlantKilled(crop);
            crop.removeGenome();
            return true;
        }
        return false;
    }).orElse(true);
    if (this.getVariant().canExistInFluid(newFluid)) {
        // the crop sticks remain, regardless of what happened to the plant
        return false;
    } else {
        if (noMorePlant) {
            // no more crop sticks, no more plant, only fluid
            world.setBlockState(pos, newFluid.getDefaultState().getBlockState());
            if (world instanceof ServerWorld) {
                double x = pos.getX() + 0.5;
                double y = pos.getY() + 0.5;
                double z = pos.getZ() + 0.5;
                for (int i = 0; i < 2; i++) {
                    ((ServerWorld) world).spawnParticle(ParticleTypes.SMOKE, x + 0.25 * world.getRandom().nextDouble(), y, z + 0.25 * world.getRandom().nextDouble(), 1, 0, 1, 0, 0.25);
                }
                world.playSound(null, x, y, z, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 0.2F + world.getRandom().nextFloat() * 0.2F, 0.9F + world.getRandom().nextFloat() * 0.05F);
            }
        } else {
            // no more crop sticks, but still plant, and fluid
            BlockState newState = AgriCraft.instance.getModBlockRegistry().crop_plant.getDefaultState();
            newState = BlockCropBase.PLANT.mimic(state, newState);
            newState = BlockCropBase.LIGHT.mimic(state, newState);
            newState = InfProperty.Defaults.fluidlogged().mimic(state, newState);
            world.setBlockState(pos, newState);
            // If there was trouble, reset and abort.
            TileEntity tile = world.getTileEntity(pos);
            if (!(tile instanceof TileEntityCropPlant)) {
                world.setBlockState(pos, state);
                return false;
            }
            // Mimic plant and weed
            ((TileEntityCropPlant) tile).mimicFrom(optCrop.get());
        }
        return true;
    }
}
Also used : net.minecraft.util(net.minecraft.util) ServerWorld(net.minecraft.world.server.ServerWorld) TypeHelper(com.agricraft.agricore.util.TypeHelper) Arrays(java.util.Arrays) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) BiFunction(java.util.function.BiFunction) IAgriGrowthResponse(com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthResponse) IAgriGenome(com.infinityraider.agricraft.api.v1.genetics.IAgriGenome) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) IAgriClipperItem(com.infinityraider.agricraft.api.v1.content.items.IAgriClipperItem) ItemStack(net.minecraft.item.ItemStack) LootContext(net.minecraft.loot.LootContext) Lists(com.google.common.collect.Lists) IBlockReader(net.minecraft.world.IBlockReader) net.minecraft.block(net.minecraft.block) Map(java.util.Map) IAgriTrowelItem(com.infinityraider.agricraft.api.v1.content.items.IAgriTrowelItem) ISelectionContext(net.minecraft.util.math.shapes.ISelectionContext) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) InfProperty(com.infinityraider.infinitylib.block.property.InfProperty) AgriCraft(com.infinityraider.agricraft.AgriCraft) MethodsReturnNonnullByDefault(mcp.MethodsReturnNonnullByDefault) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) IBooleanFunction(net.minecraft.util.math.shapes.IBooleanFunction) LootParameters(net.minecraft.loot.LootParameters) BlockPos(net.minecraft.util.math.BlockPos) Maps(com.google.common.collect.Maps) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ParticleTypes(net.minecraft.particles.ParticleTypes) List(java.util.List) Stream(java.util.stream.Stream) IAgriRakeItem(com.infinityraider.agricraft.api.v1.content.items.IAgriRakeItem) InfPropertyConfiguration(com.infinityraider.infinitylib.block.property.InfPropertyConfiguration) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) ItemSeedBag(com.infinityraider.agricraft.content.tools.ItemSeedBag) Fluid(net.minecraft.fluid.Fluid) VoxelShapes(net.minecraft.util.math.shapes.VoxelShapes) ServerWorld(net.minecraft.world.server.ServerWorld) TileEntity(net.minecraft.tileentity.TileEntity) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) IAgriGrowthResponse(com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthResponse)

Aggregations

Fluid (net.minecraft.fluid.Fluid)6 ItemStack (net.minecraft.item.ItemStack)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 AgriCraft (com.infinityraider.agricraft.AgriCraft)2 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)2 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)2 BiFunction (java.util.function.BiFunction)2 ModelResourceLocation (net.minecraft.client.renderer.model.ModelResourceLocation)2 FluidState (net.minecraft.fluid.FluidState)2 IParticleData (net.minecraft.particles.IParticleData)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 AgriCore (com.agricraft.agricore.core.AgriCore)1 AgriPlant (com.agricraft.agricore.plant.AgriPlant)1 AgriSoilCondition (com.agricraft.agricore.plant.AgriSoilCondition)1 TypeHelper (com.agricraft.agricore.util.TypeHelper)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 IAgriClipperItem (com.infinityraider.agricraft.api.v1.content.items.IAgriClipperItem)1