Skip to content

Instantly share code, notes, and snippets.

@grondag
Last active July 24, 2019 19:45
Show Gist options
  • Save grondag/f6db2c0d64cf6c2f5834f46bec14262c to your computer and use it in GitHub Desktop.
Save grondag/f6db2c0d64cf6c2f5834f46bec14262c to your computer and use it in GitHub Desktop.
Fluid API Sketch: FluidVolume
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.api.fluid.v1.fluid;
/**
* The fluid analog of ItemStack
*/
public interface FluidVolume extends ImmutableFluidVolume {
/**
* TODO: should this be mutable or fixed at instantiation?
*/
void setMaxBuckets(long buckets);
/**
* Sets volume exactly. Must be less than {@link #getMaxBuckets()} or
* an exception will be thrown.
*/
void setVolume(long volume, long units);
/**
* Removes up to the given number of units and returns that number.
*/
long drain(long volume, long units, boolean simiulate);
default long drain(long volume, long units) {
return drain(volume, units, false);
}
/**
* True if the given number of units is removed.
* Otherwise no effect and returns false.
*/
boolean drainExactly(long volume, long units, boolean simiulate);
default boolean drainExactly(long volume, long units) {
return drainExactly(volume, units);
}
/**
* Adds up to the given number of units and returns that number.
*/
long fill(long volume, long units, boolean simiulate);
default long fill(long volume, long units) {
return fill(volume, units, false);
}
/**
* True if the given number of units is added.
* Otherwise no effect and returns false.
*/
boolean fillExactly(long volume, long units, boolean simiulate);
default boolean fillExactly(long volume, long units) {
return fillExactly(volume, units);
}
FluidVolume copy();
}
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.api.fluid.v1.fluid;
import net.minecraft.fluid.Fluid;
public interface ImmutableFluidVolume {
// Common unit denominators
int BUCKET = 1;
int KILOLITER = 1;
int LITER = 1000;
int BLOCK = 1;
int SLAB = 2;
int BOTTLE = 3;
int QUARTER = 4;
int INGOT = 9;
int NUGGET = 81;
Fluid fluid();
/**
* Returns current amount in stack scaled so that that 1.0 = one of the given units.
* May be approximate due to floating point error. Intended primarily for user display.
*/
double volumeForDisplay(long units);
/**
* Returns the number of units that is less than or equal to contents.
* Make contain more than this if contents are not evenly divisible .
*/
long getVolume(long units);
/**
* True if tank is absolutely empty.
*/
boolean isEmpty();
/**
* True if filled volume is less than the given unit.
*/
boolean isEmpty(long units);
/**
* Max fill volume measured in BUCKETS.
* (Max can't be a fractional unit. That way lies madness.)
*/
long getMaxBuckets();
/**
* Returns self if already immutable.
*/
ImmutableFluidVolume toImmutable();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment