net.minecraft.fluid.Fluid Java Examples

The following examples show how to use net.minecraft.fluid.Fluid. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MCDataInput.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Reads a {@link FluidStack} from the stream.
 *
 * @return The {@link FluidStack}.
 */
default FluidStack readFluidStack() {
    if (!readBoolean()) {
        return FluidStack.EMPTY;
    } else {
        Fluid fluid = readRegistryIdUnsafe(ForgeRegistries.FLUIDS);
        int amount = readVarInt();
        CompoundNBT tag = readCompoundNBT();
        if (fluid == Fluids.EMPTY) {
            return FluidStack.EMPTY;
        }
        return new FluidStack(fluid, amount, tag);
    }
}
 
Example #2
Source File: FluidLoggableBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public Collection<Identifier> getValues() {
    if (VALUES.isEmpty()) {
        for (Fluid f : Registry.FLUID) {
            VALUES.add(Registry.FLUID.getId(f));
        }
        VALUES.add(new Identifier("empty"));
    }
    return VALUES;
}
 
Example #3
Source File: TinyPumpkinBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public Fluid tryDrainFluid(IWorld world, BlockPos pos, BlockState state) {
	if (state.contains(Properties.WATERLOGGED)) {
		return Waterloggable.super.tryDrainFluid(world, pos, state);
	} else {
		return Fluids.EMPTY;
	}
}
 
Example #4
Source File: MixinLivingEntity.java    From multiconnect with MIT License 5 votes vote down vote up
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getFluidHeight(Lnet/minecraft/tag/Tag;)D"))
private double redirectFluidHeight(LivingEntity entity, Tag<Fluid> tag) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2 && tag == FluidTags.WATER) {
        // If you're in water, you're in water, even if you're almost at the surface
        if (entity.getFluidHeight(tag) > 0)
            return 1;
    }
    return entity.getFluidHeight(tag);
}
 
Example #5
Source File: ChunkSerializerMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "deserialize", at = @At(value = "NEW", target = "net/minecraft/world/chunk/WorldChunk"))
private static WorldChunk newWorldChunk(
		World newWorld, ChunkPos newChunkPos, Biome[] newBiomes, UpgradeData newUpgradeData, TickScheduler<Block> newTickScheduler, TickScheduler<Fluid> newTickScheduler2, long newL, @Nullable ChunkSection[] newChunkSections, @Nullable Consumer<WorldChunk> newConsumer,
		ServerWorld serverWorld, StructureManager structureManager, PointOfInterestStorage pointOfInterestStorage, ChunkPos chunkPos, CompoundTag compoundTag) {
	WorldChunk chunk = new WorldChunk(newWorld, newChunkPos, newBiomes, newUpgradeData, newTickScheduler, newTickScheduler2, newL, newChunkSections, newConsumer);
	CompoundTag level = compoundTag.getCompound("Level");

	if (level.contains("ForgeCaps")) {
		((CapabilityProviderHolder) chunk).deserializeCaps(level.getCompound("ForgeCaps"));
	}

	return chunk;
}
 
Example #6
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean canFillWithFluid(BlockView blockView_1, BlockPos blockPos_1, BlockState blockState_1, Fluid fluid_1) {
    return ((org.sandboxpowered.sandbox.api.state.BlockState) blockState_1).getComponent(
            WrappingUtil.convert(blockView_1),
            (Position) blockPos_1,
            Components.FLUID_COMPONENT
    ).map(container ->
            container.insert(FluidStack.of(WrappingUtil.convert(fluid_1), 1000), true).isEmpty()
    ).orElse(false);
}
 
Example #7
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Fluid tryDrainFluid(IWorld iWorld_1, BlockPos blockPos_1, BlockState blockState_1) {
    return WrappingUtil.convert(
            ((org.sandboxpowered.sandbox.api.state.BlockState) blockState_1).getComponent(
                    WrappingUtil.convert(iWorld_1),
                    (Position) blockPos_1,
                    Components.FLUID_COMPONENT
            ).map(container ->
                    container.extract(1000).getFluid()
            ).orElse(Fluids.EMPTY)
    );
}
 
Example #8
Source File: MixinModelLoader.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Set;addAll(Ljava/util/Collection;)Z"))
public boolean addAll(Set<SpriteIdentifier> set, Collection<SpriteIdentifier> set2) {
    for (Fluid fluid : Registry.FLUID) {
        if (fluid instanceof FluidWrapper) {
            set.add(new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, WrappingUtil.convert(((FluidWrapper) fluid).fluid.getTexturePath(false))));
            set.add(new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, WrappingUtil.convert(((FluidWrapper) fluid).fluid.getTexturePath(true))));
        }
    }
    return set.addAll(set2);
}
 
Example #9
Source File: FluidUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static int getLuminosity(FluidStack stack, double density) {
    if (stack.isEmpty()) {
        return 0;
    }
    Fluid fluid = stack.getFluid();
    FluidAttributes attributes = fluid.getAttributes();
    int light = attributes.getLuminosity(stack);
    if (attributes.isGaseous()) {
        light = (int) (light * density);
    }
    return light;
}
 
Example #10
Source File: FluidLoggableBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
default Fluid tryDrainFluid(WorldAccess world, BlockPos pos, BlockState state) {
    if (!state.get(FLUID).equals(new Identifier("empty"))) {
        world.setBlockState(pos, state.with(FLUID, new Identifier("empty")), 3);
        if (Registry.FLUID.get(state.get(FLUID)).getDefaultState().isStill()) {
            return Registry.FLUID.get(state.get(FLUID));
        }
    }
    return Fluids.EMPTY;
}
 
Example #11
Source File: MixinFluid.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Class<Fluid> getRegistryType() {
	return Fluid.class;
}
 
Example #12
Source File: MixinFluid.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Identifier getRegistryName() {
	Fluid fluid = (Fluid) (Object) this;

	return Identifiers.getOrFallback(Registry.FLUID, fluid, registryName);
}
 
Example #13
Source File: MixinFluid.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public IForgeRegistryEntry<Fluid> setRegistryName(Identifier name) {
	this.registryName = name;

	return this;
}
 
Example #14
Source File: MixinEntity.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "updateMovementInFluid", at = @At("HEAD"), cancellable = true)
private void modifyFluidMovementBoundingBox(Tag<Fluid> fluidTag, double d, CallbackInfoReturnable<Boolean> ci) {
    if (ConnectionInfo.protocolVersion > Protocols.V1_12_2)
        return;

    Box box = getBoundingBox().expand(0, -0.4, 0).contract(0.001);
    int minX = MathHelper.floor(box.minX);
    int maxX = MathHelper.ceil(box.maxX);
    int minY = MathHelper.floor(box.minY);
    int maxY = MathHelper.ceil(box.maxY);
    int minZ = MathHelper.floor(box.minZ);
    int maxZ = MathHelper.ceil(box.maxZ);

    if (!world.isRegionLoaded(minX, minY, minZ, maxX, maxY, maxZ))
        ci.setReturnValue(false);

    double waterHeight = 0;
    boolean foundFluid = false;
    Vec3d pushVec = Vec3d.ZERO;

    BlockPos.Mutable mutable = new BlockPos.Mutable();

    for (int x = minX; x < maxX; x++) {
        for (int y = minY - 1; y < maxY; y++) {
            for (int z = minZ; z < maxZ; z++) {
                mutable.set(x, y, z);
                FluidState state = world.getFluidState(mutable);
                if (state.isIn(fluidTag)) {
                    double height = y + state.getHeight(world, mutable);
                    if (height >= box.minY - 0.4)
                        waterHeight = Math.max(height - box.minY + 0.4, waterHeight);
                    if (y >= minY && maxY >= height) {
                        foundFluid = true;
                        pushVec = pushVec.add(state.getVelocity(world, mutable));
                    }
                }
            }
        }
    }

    if (pushVec.length() > 0) {
        pushVec = pushVec.normalize().multiply(0.014);
        setVelocity(getVelocity().add(pushVec));
    }

    this.fluidHeight.put(fluidTag, waterHeight);
    ci.setReturnValue(foundFluid);
}
 
Example #15
Source File: Protocol_1_12_2.java    From multiconnect with MIT License 4 votes vote down vote up
@Override
public void addExtraFluidTags(TagRegistry<Fluid> tags) {
    tags.add(FluidTags.WATER, Fluids.WATER, Fluids.FLOWING_WATER);
    tags.add(FluidTags.LAVA, Fluids.LAVA, Fluids.FLOWING_LAVA);
    super.addExtraFluidTags(tags);
}
 
Example #16
Source File: AbstractProtocol.java    From multiconnect with MIT License 4 votes vote down vote up
public void addExtraFluidTags(TagRegistry<Fluid> tags) {
}
 
Example #17
Source File: HallowedTags.java    From the-hallow with MIT License 4 votes vote down vote up
public static Tag<Fluid> register(String name) {
	return TagRegistry.fluid(TheHallow.id(name));
}
 
Example #18
Source File: HallowedFluids.java    From the-hallow with MIT License 4 votes vote down vote up
static <T extends Fluid> T register(String name, T fluid) {
	T b = Registry.register(Registry.FLUID, TheHallow.id(name), fluid);
	return b;
}
 
Example #19
Source File: WitchWaterBubbleColumnBlock.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public Fluid tryDrainFluid(IWorld world, BlockPos pos, BlockState state) {
	world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
	return HallowedFluids.WITCH_WATER;
}
 
Example #20
Source File: TinyPumpkinBlock.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public boolean canFillWithFluid(BlockView blockView, BlockPos pos, BlockState state, Fluid fluid) {
	return state.contains(Properties.WATERLOGGED) && Waterloggable.super.canFillWithFluid(blockView, pos, state, fluid);
}
 
Example #21
Source File: BloodFluid.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
protected void appendProperties(StateManager.Builder<Fluid, FluidState> stateBuilder) {
	super.appendProperties(stateBuilder);
	stateBuilder.add(LEVEL);
}
 
Example #22
Source File: BloodFluid.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public boolean method_15777(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) {
	return direction == Direction.DOWN && !fluid.matches(HallowedTags.Fluids.BLOOD);
}
 
Example #23
Source File: FuelFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public boolean matchesType(Fluid fluid) {
    return fluid == getStill() || fluid == getFlowing();
}
 
Example #24
Source File: FluidLoggableBlock.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
default boolean canFillWithFluid(BlockView view, BlockPos pos, BlockState state, Fluid fluid) {
    return state.get(FLUID).equals(new Identifier("empty"));
}
 
Example #25
Source File: CrudeOilFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public Fluid getFlowing() {
    return GalacticraftFluids.FLOWING_CRUDE_OIL;
}
 
Example #26
Source File: CrudeOilFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public Fluid getStill() {
    return GalacticraftFluids.CRUDE_OIL;
}
 
Example #27
Source File: CrudeOilFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public boolean canBeReplacedWith(FluidState fluidState, BlockView blockView, BlockPos blockPos, Fluid fluid, Direction direction) {
    return direction == Direction.DOWN && !fluid.matchesType(GalacticraftFluids.CRUDE_OIL);
}
 
Example #28
Source File: CrudeOilFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public boolean matchesType(Fluid fluid) {
    return fluid == getStill() || fluid == getFlowing();
}
 
Example #29
Source File: CrudeOilFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
protected void appendProperties(StateManager.Builder<Fluid, FluidState> stateBuilder) {
    super.appendProperties(stateBuilder);
    stateBuilder.add(LEVEL);
}
 
Example #30
Source File: FuelFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Override
public Fluid getFlowing() {
    return GalacticraftFluids.FLOWING_FUEL;
}