Create/src/main/java/com/simibubi/create/AllFluids.java

154 lines
4.6 KiB
Java
Raw Normal View History

package com.simibubi.create;
import static com.simibubi.create.Create.REGISTRATE;
2022-08-01 22:37:39 +02:00
import java.util.function.Consumer;
import javax.annotation.Nullable;
import com.simibubi.create.AllTags.AllFluidTags;
import com.simibubi.create.content.contraptions.fluids.VirtualFluid;
import com.simibubi.create.content.contraptions.fluids.potion.PotionFluid;
2022-08-01 22:37:39 +02:00
import com.simibubi.create.content.contraptions.fluids.potion.PotionFluid.PotionFluidType;
import com.simibubi.create.content.palettes.AllPaletteStoneTypes;
import com.tterrag.registrate.util.entry.FluidEntry;
import net.minecraft.core.BlockPos;
2022-08-01 22:37:39 +02:00
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.BlockAndTintGetter;
2021-11-02 06:18:30 +01:00
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
2022-08-01 22:37:39 +02:00
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidType;
import net.minecraftforge.fluids.ForgeFlowingFluid;
public class AllFluids {
public static final FluidEntry<PotionFluid> POTION =
2022-08-01 22:37:39 +02:00
REGISTRATE.virtualFluid("potion", PotionFluidType::new, PotionFluid::new)
.lang("Potion")
2022-08-01 22:37:39 +02:00
.register();
public static final FluidEntry<VirtualFluid> TEA = REGISTRATE.virtualFluid("tea")
.lang("Builder's Tea")
2022-08-01 22:37:39 +02:00
.tag(AllTags.forgeFluidTag("tea"))
.register();
public static final FluidEntry<ForgeFlowingFluid.Flowing> HONEY =
2022-08-01 22:37:39 +02:00
REGISTRATE.standardFluid("honey", NoColorFluidAttributes::new)
.lang("Honey")
2022-08-01 22:37:39 +02:00
.properties(b -> b.viscosity(2000)
.density(1400))
.fluidProperties(p -> p.levelDecreasePerBlock(2)
.tickRate(25)
.slopeFindDistance(3)
.explosionResistance(100f))
.tag(AllFluidTags.HONEY.tag)
.source(ForgeFlowingFluid.Source::new) // TODO: remove when Registrate fixes FluidBuilder
.bucket()
.tag(AllTags.forgeItemTag("buckets/honey"))
.build()
.register();
public static final FluidEntry<ForgeFlowingFluid.Flowing> CHOCOLATE =
2022-08-01 22:37:39 +02:00
REGISTRATE.standardFluid("chocolate", NoColorFluidAttributes::new)
.lang("Chocolate")
2022-08-01 22:37:39 +02:00
.tag(AllTags.forgeFluidTag("chocolate"))
.properties(b -> b.viscosity(1500)
.density(1400))
.fluidProperties(p -> p.levelDecreasePerBlock(2)
.tickRate(25)
.slopeFindDistance(3)
.explosionResistance(100f))
.register();
// Load this class
public static void register() {}
@Nullable
2020-12-05 11:42:14 +01:00
public static BlockState getLavaInteraction(FluidState fluidState) {
2021-07-15 11:32:03 +02:00
Fluid fluid = fluidState.getType();
if (fluid.isSame(HONEY.get()))
return AllPaletteStoneTypes.LIMESTONE.getBaseBlock()
.get()
.defaultBlockState();
if (fluid.isSame(CHOCOLATE.get()))
return AllPaletteStoneTypes.SCORIA.getBaseBlock()
.get()
.defaultBlockState();
return null;
}
2022-08-01 22:37:39 +02:00
public static abstract class TintedFluidType extends FluidType {
protected static final int NO_TINT = 0xffffffff;
private ResourceLocation stillTexture;
private ResourceLocation flowingTexture;
public TintedFluidType(Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture) {
super(properties);
this.stillTexture = stillTexture;
this.flowingTexture = flowingTexture;
2022-08-01 22:37:39 +02:00
}
@Override
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
consumer.accept(new IClientFluidTypeExtensions() {
@Override
public ResourceLocation getStillTexture() {
return stillTexture;
2022-08-01 22:37:39 +02:00
}
@Override
public ResourceLocation getFlowingTexture() {
return flowingTexture;
2022-08-01 22:37:39 +02:00
}
@Override
public int getTintColor(FluidStack stack) {
return TintedFluidType.this.getTintColor(stack);
2022-08-01 22:37:39 +02:00
}
@Override
public int getTintColor(FluidState state, BlockAndTintGetter getter, BlockPos pos) {
return TintedFluidType.this.getTintColor(state, getter, pos);
2022-08-01 22:37:39 +02:00
}
});
}
protected abstract int getTintColor(FluidStack stack);
protected abstract int getTintColor(FluidState state, BlockAndTintGetter getter, BlockPos pos);
}
/**
* Removing alpha from tint prevents optifine from forcibly applying biome
* colors to modded fluids (Makes translucent fluids disappear)
*/
2022-08-01 22:37:39 +02:00
private static class NoColorFluidAttributes extends TintedFluidType {
2022-08-01 22:37:39 +02:00
public NoColorFluidAttributes(Properties properties, ResourceLocation stillTexture,
ResourceLocation flowingTexture) {
super(properties, stillTexture, flowingTexture);
}
@Override
protected int getTintColor(FluidStack stack) {
return NO_TINT;
}
2022-08-01 22:37:39 +02:00
@Override
public int getTintColor(FluidState state, BlockAndTintGetter world, BlockPos pos) {
return 0x00ffffff;
2022-08-01 22:37:39 +02:00
}
}
2022-08-01 22:37:39 +02:00
}