mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
[1.19.x] Fluid API Overhaul (#8695)
This commit is contained in:
1 parent
e386229b66
commit
2a05c7c01d
67 files changed
+3856
-740
No files matched your search
@@ -51,6 +51,7 @@ import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
@@ -139,7 +140,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.NoteBlockEvent;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
@@ -803,30 +804,24 @@ public class ForgeHooks
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static FluidAttributes createVanillaFluidAttributes(Fluid fluid)
|
||||
/**
|
||||
* Returns a vanilla fluid type for the given fluid.
|
||||
*
|
||||
* @param fluid the fluid looking for its type
|
||||
* @return the type of the fluid if vanilla
|
||||
* @throws RuntimeException if the fluid is not a vanilla one
|
||||
*/
|
||||
public static FluidType getVanillaFluidType(Fluid fluid)
|
||||
{
|
||||
if (fluid instanceof EmptyFluid)
|
||||
return net.minecraftforge.fluids.FluidAttributes.builder(null, null)
|
||||
.translationKey("block.minecraft.air")
|
||||
.color(0).density(0).temperature(0).luminosity(0).viscosity(0).build(fluid);
|
||||
if (fluid instanceof WaterFluid)
|
||||
return net.minecraftforge.fluids.FluidAttributes.Water.builder(
|
||||
new ResourceLocation("block/water_still"),
|
||||
new ResourceLocation("block/water_flow"))
|
||||
.overlay(new ResourceLocation("block/water_overlay"))
|
||||
.translationKey("block.minecraft.water")
|
||||
.color(0xFF3F76E4)
|
||||
.sound(SoundEvents.BUCKET_FILL, SoundEvents.BUCKET_EMPTY)
|
||||
.build(fluid);
|
||||
if (fluid instanceof LavaFluid)
|
||||
return net.minecraftforge.fluids.FluidAttributes.builder(
|
||||
new ResourceLocation("block/lava_still"),
|
||||
new ResourceLocation("block/lava_flow"))
|
||||
.translationKey("block.minecraft.lava")
|
||||
.luminosity(15).density(3000).viscosity(6000).temperature(1300)
|
||||
.sound(SoundEvents.BUCKET_FILL_LAVA, SoundEvents.BUCKET_EMPTY_LAVA)
|
||||
.build(fluid);
|
||||
throw new RuntimeException("Mod fluids must override createAttributes.");
|
||||
if (fluid == Fluids.EMPTY)
|
||||
return ForgeMod.EMPTY_TYPE.get();
|
||||
if (fluid == Fluids.WATER || fluid == Fluids.FLOWING_WATER)
|
||||
return ForgeMod.WATER_TYPE.get();
|
||||
if (fluid == Fluids.LAVA || fluid == Fluids.FLOWING_LAVA)
|
||||
return ForgeMod.LAVA_TYPE.get();
|
||||
if (ForgeMod.MILK.filter(milk -> milk == fluid).isPresent() || ForgeMod.FLOWING_MILK.filter(milk -> milk == fluid).isPresent())
|
||||
return ForgeMod.MILK_TYPE.get();
|
||||
throw new RuntimeException("Mod fluids must override getFluidType.");
|
||||
}
|
||||
|
||||
public static String getDefaultWorldPreset()
|
||||
|
||||
@@ -5,19 +5,30 @@
|
||||
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BiomeColors;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
|
||||
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.RangedAttribute;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.pathfinder.BlockPathTypes;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.IFluidTypeRenderProperties;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
|
||||
import net.minecraftforge.common.crafting.PartialNBTIngredient;
|
||||
@@ -35,7 +46,7 @@ import net.minecraftforge.common.world.NoneBiomeModifier;
|
||||
import net.minecraftforge.common.world.NoneStructureModifier;
|
||||
import net.minecraftforge.common.world.StructureModifier;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import net.minecraftforge.fluids.ForgeFlowingFluid;
|
||||
import net.minecraftforge.fml.*;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
@@ -82,8 +93,10 @@ import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod("forge")
|
||||
public class ForgeMod
|
||||
@@ -133,13 +146,153 @@ public class ForgeMod
|
||||
* Noop biome modifier. Can be used in a biome modifier json with "type": "forge:none".
|
||||
*/
|
||||
public static final RegistryObject<Codec<NoneBiomeModifier>> NONE_BIOME_MODIFIER_TYPE = BIOME_MODIFIER_SERIALIZERS.register("none", () -> Codec.unit(NoneBiomeModifier.INSTANCE));
|
||||
|
||||
/**
|
||||
* Noop structure modifier. Can be used in a structure modifier json with "type": "forge:none".
|
||||
*/
|
||||
public static final RegistryObject<Codec<NoneStructureModifier>> NONE_STRUCTURE_MODIFIER_TYPE = STRUCTURE_MODIFIER_SERIALIZERS.register("none", () -> Codec.unit(NoneStructureModifier.INSTANCE));
|
||||
|
||||
private static final DeferredRegister<FluidType> VANILLA_FLUID_TYPES = DeferredRegister.create(ForgeRegistries.Keys.FLUID_TYPES, "minecraft");
|
||||
|
||||
public static final RegistryObject<FluidType> EMPTY_TYPE = VANILLA_FLUID_TYPES.register("empty", () ->
|
||||
new FluidType(FluidType.Properties.create()
|
||||
.descriptionId("block.minecraft.air")
|
||||
.motionScale(1D)
|
||||
.canPushEntity(false)
|
||||
.canSwim(false)
|
||||
.canDrown(false)
|
||||
.fallDistanceModifier(1F)
|
||||
.pathType(null)
|
||||
.adjacentPathType(null)
|
||||
.density(0)
|
||||
.temperature(0)
|
||||
.viscosity(0))
|
||||
{
|
||||
@Override
|
||||
public void setItemMovement(ItemEntity entity)
|
||||
{
|
||||
if (!entity.isNoGravity()) entity.setDeltaMovement(entity.getDeltaMovement().add(0.0D, -0.04D, 0.0D));
|
||||
}
|
||||
});
|
||||
public static final RegistryObject<FluidType> WATER_TYPE = VANILLA_FLUID_TYPES.register("water", () ->
|
||||
new FluidType(FluidType.Properties.create()
|
||||
.descriptionId("block.minecraft.water")
|
||||
.fallDistanceModifier(0F)
|
||||
.canExtinguish(true)
|
||||
.canConvertToSource(true)
|
||||
.supportsBoating(true)
|
||||
.sound(SoundActions.BUCKET_FILL, SoundEvents.BUCKET_FILL)
|
||||
.sound(SoundActions.BUCKET_EMPTY, SoundEvents.BUCKET_EMPTY)
|
||||
.sound(SoundActions.FLUID_VAPORIZE, SoundEvents.FIRE_EXTINGUISH)
|
||||
.canHydrate(true))
|
||||
{
|
||||
@Override
|
||||
public @Nullable BlockPathTypes getBlockPathType(FluidState state, BlockGetter level, BlockPos pos, @Nullable Mob mob, boolean canFluidLog)
|
||||
{
|
||||
return canFluidLog ? super.getBlockPathType(state, level, pos, mob, true) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeClient(Consumer<IFluidTypeRenderProperties> consumer)
|
||||
{
|
||||
consumer.accept(new IFluidTypeRenderProperties()
|
||||
{
|
||||
private static final ResourceLocation UNDERWATER_LOCATION = new ResourceLocation("textures/misc/underwater.png"),
|
||||
WATER_STILL = new ResourceLocation("block/water_still"),
|
||||
WATER_FLOW = new ResourceLocation("block/water_flow"),
|
||||
WATER_OVERLAY = new ResourceLocation("block/water_overlay");
|
||||
|
||||
@Override
|
||||
public ResourceLocation getStillTexture()
|
||||
{
|
||||
return WATER_STILL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getFlowingTexture()
|
||||
{
|
||||
return WATER_FLOW;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getOverlayTexture()
|
||||
{
|
||||
return WATER_OVERLAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getRenderOverlayTexture(Minecraft mc)
|
||||
{
|
||||
return UNDERWATER_LOCATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorTint()
|
||||
{
|
||||
return 0xFF3F76E4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorTint(FluidState state, BlockAndTintGetter getter, BlockPos pos)
|
||||
{
|
||||
return BiomeColors.getAverageWaterColor(getter, pos) | 0xFF000000;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
public static final RegistryObject<FluidType> LAVA_TYPE = VANILLA_FLUID_TYPES.register("lava", () ->
|
||||
new FluidType(FluidType.Properties.create()
|
||||
.descriptionId("block.minecraft.lava")
|
||||
.canSwim(false)
|
||||
.canDrown(false)
|
||||
.pathType(BlockPathTypes.LAVA)
|
||||
.adjacentPathType(null)
|
||||
.sound(SoundActions.BUCKET_FILL, SoundEvents.BUCKET_FILL_LAVA)
|
||||
.sound(SoundActions.BUCKET_EMPTY, SoundEvents.BUCKET_EMPTY_LAVA)
|
||||
.lightLevel(15)
|
||||
.density(3000)
|
||||
.viscosity(6000)
|
||||
.temperature(1300))
|
||||
{
|
||||
@Override
|
||||
public double motionScale(Entity entity)
|
||||
{
|
||||
return entity.level.dimensionType().ultraWarm() ? 0.007D : 0.0023333333333333335D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemMovement(ItemEntity entity)
|
||||
{
|
||||
Vec3 vec3 = entity.getDeltaMovement();
|
||||
entity.setDeltaMovement(vec3.x * (double)0.95F, vec3.y + (double)(vec3.y < (double)0.06F ? 5.0E-4F : 0.0F), vec3.z * (double)0.95F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeClient(Consumer<IFluidTypeRenderProperties> consumer)
|
||||
{
|
||||
consumer.accept(new IFluidTypeRenderProperties()
|
||||
{
|
||||
private static final ResourceLocation LAVA_STILL = new ResourceLocation("block/lava_still"),
|
||||
LAVA_FLOW = new ResourceLocation("block/lava_flow");
|
||||
|
||||
@Override
|
||||
public ResourceLocation getStillTexture()
|
||||
{
|
||||
return LAVA_STILL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getFlowingTexture()
|
||||
{
|
||||
return LAVA_FLOW;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
private static boolean enableMilkFluid = false;
|
||||
public static final RegistryObject<FluidType> MILK_TYPE = RegistryObject.createOptional(new ResourceLocation("milk"), ForgeRegistries.Keys.FLUID_TYPES.location(), "minecraft");
|
||||
public static final RegistryObject<Fluid> MILK = RegistryObject.create(new ResourceLocation("milk"), ForgeRegistries.FLUIDS);
|
||||
public static final RegistryObject<Fluid> FLOWING_MILK = RegistryObject.create(new ResourceLocation("flowing_milk"), ForgeRegistries.FLUIDS);
|
||||
|
||||
@@ -185,6 +338,7 @@ public class ForgeMod
|
||||
COMMAND_ARGUMENT_TYPES.register(modEventBus);
|
||||
BIOME_MODIFIER_SERIALIZERS.register(modEventBus);
|
||||
STRUCTURE_MODIFIER_SERIALIZERS.register(modEventBus);
|
||||
VANILLA_FLUID_TYPES.register(modEventBus);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::serverStopping);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::missingSoundMapping);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ForgeConfig.clientSpec);
|
||||
@@ -274,14 +428,42 @@ public class ForgeMod
|
||||
// done in an event instead of deferred to only enable if a mod requests it
|
||||
public void registerFluids(RegisterEvent event)
|
||||
{
|
||||
if (enableMilkFluid && event.getRegistryKey().equals(ForgeRegistries.Keys.FLUIDS))
|
||||
if (enableMilkFluid)
|
||||
{
|
||||
// set up attributes
|
||||
FluidAttributes.Builder attributesBuilder = FluidAttributes.builder(new ResourceLocation("forge", "block/milk_still"), new ResourceLocation("forge", "block/milk_flowing")).density(1024).viscosity(1024);
|
||||
ForgeFlowingFluid.Properties properties = new ForgeFlowingFluid.Properties(MILK, FLOWING_MILK, attributesBuilder).bucket(() -> Items.MILK_BUCKET);
|
||||
// register fluid type
|
||||
event.register(ForgeRegistries.Keys.FLUID_TYPES, helper -> helper.register(MILK_TYPE.getId(), new FluidType(FluidType.Properties.create().density(1024).viscosity(1024))
|
||||
{
|
||||
@Override
|
||||
public void initializeClient(Consumer<IFluidTypeRenderProperties> consumer)
|
||||
{
|
||||
consumer.accept(new IFluidTypeRenderProperties()
|
||||
{
|
||||
private static final ResourceLocation MILK_STILL = new ResourceLocation("forge", "block/milk_still"),
|
||||
MILK_FLOW = new ResourceLocation("forge", "block/milk_flowing");
|
||||
|
||||
@Override
|
||||
public ResourceLocation getStillTexture()
|
||||
{
|
||||
return MILK_STILL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getFlowingTexture()
|
||||
{
|
||||
return MILK_FLOW;
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
// register fluids
|
||||
event.register(ForgeRegistries.Keys.FLUIDS, MILK.getId(), () -> new ForgeFlowingFluid.Source(properties));
|
||||
event.register(ForgeRegistries.Keys.FLUIDS, FLOWING_MILK.getId(), () -> new ForgeFlowingFluid.Flowing(properties));
|
||||
event.register(ForgeRegistries.Keys.FLUIDS, helper -> {
|
||||
// set up properties
|
||||
ForgeFlowingFluid.Properties properties = new ForgeFlowingFluid.Properties(MILK_TYPE, MILK, FLOWING_MILK).bucket(() -> Items.MILK_BUCKET);
|
||||
|
||||
helper.register(MILK.getId(), new ForgeFlowingFluid.Source(properties));
|
||||
helper.register(FLOWING_MILK.getId(), new ForgeFlowingFluid.Flowing(properties));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Defines an action which produces a sound.
|
||||
*/
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public final class SoundAction
|
||||
{
|
||||
private static final Map<String, SoundAction> ACTIONS = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Gets or creates a new {@code SoundAction} for the given name.
|
||||
*
|
||||
* @param name the name of the action
|
||||
* @return the existing {@code SoundAction}, or a new one if not present
|
||||
*/
|
||||
public static SoundAction get(String name)
|
||||
{
|
||||
return ACTIONS.computeIfAbsent(name, SoundAction::new);
|
||||
}
|
||||
|
||||
private final String name;
|
||||
|
||||
private SoundAction(final String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the action.
|
||||
*
|
||||
* @return the name of the action
|
||||
*/
|
||||
public String name() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SoundAction[" + this.name + "]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.minecraftforge.common;
|
||||
|
||||
/**
|
||||
* A utility holding common sound actions.
|
||||
*/
|
||||
public final class SoundActions
|
||||
{
|
||||
private SoundActions()
|
||||
{
|
||||
throw new AssertionError("SoundActions should not be instantiated.");
|
||||
}
|
||||
|
||||
/**
|
||||
* When a bucket is being filled by a fluid.
|
||||
*/
|
||||
public static final SoundAction BUCKET_FILL = SoundAction.get("bucket_fill");
|
||||
|
||||
/**
|
||||
* When a bucket is emptying a fluid.
|
||||
*/
|
||||
public static final SoundAction BUCKET_EMPTY = SoundAction.get("bucket_empty");
|
||||
|
||||
/**
|
||||
* When the fluid is being vaporized.
|
||||
*/
|
||||
public static final SoundAction FLUID_VAPORIZE = SoundAction.get("fluid_vaporize");
|
||||
}
|
||||
@@ -405,7 +405,14 @@ public class Tags
|
||||
{
|
||||
private static void init() {}
|
||||
|
||||
/**
|
||||
* Holds all fluids related to milk.
|
||||
*/
|
||||
public static final TagKey<Fluid> MILK = tag("milk");
|
||||
/**
|
||||
* Holds all fluids that are gaseous at room temperature.
|
||||
*/
|
||||
public static final TagKey<Fluid> GASEOUS = tag("gaseous");
|
||||
|
||||
private static TagKey<Fluid> tag(String name)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@ import net.minecraft.world.level.pathfinder.BlockPathTypes;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.pathfinder.WalkNodeEvaluator;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
@@ -480,16 +481,43 @@ public interface IForgeBlock
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@code PathNodeType} for this block. Return {@code null} for vanilla behavior.
|
||||
* Gets the path type of this block when an entity is pathfinding. When
|
||||
* {@code null}, uses vanilla behavior.
|
||||
*
|
||||
* @return the PathNodeType
|
||||
* @param state the state of the block
|
||||
* @param level the level which contains this block
|
||||
* @param pos the position of the block
|
||||
* @param mob the mob currently pathfinding, may be {@code null}
|
||||
* @return the path type of this block
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPathTypes getAiPathNodeType(BlockState state, BlockGetter level, BlockPos pos, @Nullable Mob entity)
|
||||
default BlockPathTypes getBlockPathType(BlockState state, BlockGetter level, BlockPos pos, @Nullable Mob mob)
|
||||
{
|
||||
return state.getBlock() == Blocks.LAVA ? BlockPathTypes.LAVA : state.isBurning(level, pos) ? BlockPathTypes.DAMAGE_FIRE : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path type of the adjacent block to a pathfinding entity.
|
||||
* Path types with a negative malus are not traversable for the entity.
|
||||
* Pathfinding entities will favor paths consisting of a lower malus.
|
||||
* When {@code null}, uses vanilla behavior.
|
||||
*
|
||||
* @param state the state of the block
|
||||
* @param level the level which contains this block
|
||||
* @param pos the position of the block
|
||||
* @param mob the mob currently pathfinding, may be {@code null}
|
||||
* @param originalType the path type of the source the entity is on
|
||||
* @return the path type of this block
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPathTypes getAdjacentBlockPathType(BlockState state, BlockGetter level, BlockPos pos, @Nullable Mob mob, BlockPathTypes originalType)
|
||||
{
|
||||
if (state.is(Blocks.CACTUS)) return BlockPathTypes.DANGER_CACTUS;
|
||||
else if (state.is(Blocks.SWEET_BERRY_BUSH)) return BlockPathTypes.DANGER_OTHER;
|
||||
else if (WalkNodeEvaluator.isBurningBlock(state)) return BlockPathTypes.DANGER_FIRE;
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state The state
|
||||
* @return true if the block is sticky block which used for pull or push adjacent blocks (use by piston)
|
||||
@@ -816,4 +844,26 @@ public interface IForgeBlock
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the block can be hydrated by a fluid.
|
||||
*
|
||||
* <p>Hydration is an arbitrary word which depends on the block.
|
||||
* <ul>
|
||||
* <li>A farmland has moisture</li>
|
||||
* <li>A sponge can soak up the liquid</li>
|
||||
* <li>A coral can live</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param state the state of the block being hydrated
|
||||
* @param getter the getter which can get the block
|
||||
* @param pos the position of the block being hydrated
|
||||
* @param fluid the state of the fluid
|
||||
* @param fluidPos the position of the fluid
|
||||
* @return {@code true} if the block can be hydrated, {@code false} otherwise
|
||||
*/
|
||||
default boolean canBeHydrated(BlockState state, BlockGetter getter, BlockPos pos, FluidState fluid, BlockPos fluidPos)
|
||||
{
|
||||
return fluid.canHydrate(getter, fluidPos, state, pos);
|
||||
}
|
||||
}
|
||||
@@ -541,25 +541,36 @@ public interface IForgeBlockState
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@code BlockPathTypes} for this block. Return {@code null} for vanilla behavior.
|
||||
* Gets the path type of this block when an entity is pathfinding. When
|
||||
* {@code null}, uses vanilla behavior.
|
||||
*
|
||||
* @return the PathNodeType
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPathTypes getBlockPathType(BlockGetter level, BlockPos pos)
|
||||
{
|
||||
return getBlockPathType(level, pos, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@code PathNodeType} for this block. Return {@code null} for vanilla behavior.
|
||||
*
|
||||
* @return the PathNodeType
|
||||
* @param level the level which contains this block
|
||||
* @param pos the position of the block
|
||||
* @param mob the mob currently pathfinding, may be {@code null}
|
||||
* @return the path type of this block
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPathTypes getBlockPathType(BlockGetter level, BlockPos pos, @Nullable Mob mob)
|
||||
{
|
||||
return self().getBlock().getAiPathNodeType(self(), level, pos, mob);
|
||||
return self().getBlock().getBlockPathType(self(), level, pos, mob);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path type of the adjacent block to a pathfinding entity.
|
||||
* Path types with a negative malus are not traversable for the entity.
|
||||
* Pathfinding entities will favor paths consisting of a lower malus.
|
||||
* When {@code null}, uses vanilla behavior.
|
||||
*
|
||||
* @param level the level which contains this block
|
||||
* @param pos the position of the block
|
||||
* @param mob the mob currently pathfinding, may be {@code null}
|
||||
* @param originalType the path type of the source the entity is on
|
||||
* @return the path type of this block
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPathTypes getAdjacentBlockPathType(BlockGetter level, BlockPos pos, @Nullable Mob mob, BlockPathTypes originalType)
|
||||
{
|
||||
return self().getBlock().getAdjacentBlockPathType(self(), level, pos, mob, originalType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -676,4 +687,25 @@ public interface IForgeBlockState
|
||||
{
|
||||
return self().getBlock().supportsExternalFaceHiding(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the block can be hydrated by a fluid.
|
||||
*
|
||||
* <p>Hydration is an arbitrary word which depends on the block.
|
||||
* <ul>
|
||||
* <li>A farmland has moisture</li>
|
||||
* <li>A sponge can soak up the liquid</li>
|
||||
* <li>A coral can live</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param getter the getter which can get the block
|
||||
* @param pos the position of the block being hydrated
|
||||
* @param fluid the state of the fluid
|
||||
* @param fluidPos the position of the fluid
|
||||
* @return {@code true} if the block can be hydrated, {@code false} otherwise
|
||||
*/
|
||||
default boolean canBeHydrated(BlockGetter getter, BlockPos pos, FluidState fluid, BlockPos fluidPos)
|
||||
{
|
||||
return self().getBlock().canBeHydrated(self(), getter, pos, fluid, fluidPos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
|
||||
public interface IForgeBoat
|
||||
{
|
||||
private Boat self()
|
||||
{
|
||||
return (Boat) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the boat can be used on the fluid.
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @return {@code true} if the boat can be used, {@code false} otherwise
|
||||
*/
|
||||
default boolean canBoatInFluid(FluidState state)
|
||||
{
|
||||
return state.supportsBoating(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the boat can be used on the fluid.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return {@code true} if the boat can be used, {@code false} otherwise
|
||||
*/
|
||||
default boolean canBoatInFluid(FluidType type)
|
||||
{
|
||||
return type.supportsBoating(self());
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
|
||||
@@ -19,11 +21,14 @@ import net.minecraft.world.item.SpawnEggItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.common.ForgeSpawnEggItem;
|
||||
import net.minecraftforge.common.SoundAction;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.entity.PartEntity;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IForgeEntity extends ICapabilitySerializable<CompoundTag>
|
||||
@@ -101,14 +106,16 @@ public interface IForgeEntity extends ICapabilitySerializable<CompoundTag>
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this entity can continue to be ridden while it is underwater.
|
||||
* Returns whether the entity can ride in this vehicle under the fluid.
|
||||
*
|
||||
* @param rider The entity that is riding this entity
|
||||
* @return {@code true} if the entity can continue to ride underwater. {@code false} otherwise.
|
||||
* @param type the type of the fluid
|
||||
* @param rider the entity riding the vehicle
|
||||
* @return {@code true} if the vehicle can be ridden in under this fluid,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
default boolean canBeRiddenInWater(Entity rider)
|
||||
default boolean canBeRiddenUnderFluidType(FluidType type, Entity rider)
|
||||
{
|
||||
return self().rideableUnderWater();
|
||||
return type.canRideVehicleUnder(self(), rider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,4 +219,195 @@ public interface IForgeEntity extends ICapabilitySerializable<CompoundTag>
|
||||
}
|
||||
return vanillaStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of the fluid type in relation to the bounding box of
|
||||
* the entity. If the entity is not in the fluid type, then {@code 0}
|
||||
* is returned.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return the height of the fluid compared to the entity
|
||||
*/
|
||||
double getFluidTypeHeight(FluidType type);
|
||||
|
||||
/**
|
||||
* Returns the fluid type which is the highest on the bounding box of
|
||||
* the entity.
|
||||
*
|
||||
* @return the fluid type which is the highest on the bounding box of
|
||||
* the entity
|
||||
*/
|
||||
FluidType getMaxHeightFluidType();
|
||||
|
||||
/**
|
||||
* Returns whether the entity is within the fluid type of the state.
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @return {@code true} if the entity is within the fluid type of the
|
||||
* state, {@code false} otherwise
|
||||
*/
|
||||
default boolean isInFluidType(FluidState state)
|
||||
{
|
||||
return this.isInFluidType(state.getFluidType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entity is within the fluid type.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return {@code true} if the entity is within the fluid type,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
default boolean isInFluidType(FluidType type)
|
||||
{
|
||||
return this.getFluidTypeHeight(type) > 0.0D;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether any fluid type the entity is currently in matches
|
||||
* the specified condition.
|
||||
*
|
||||
* @param predicate a test taking in the fluid type and its height
|
||||
* @return {@code true} if a fluid type meets the condition, {@code false}
|
||||
* otherwise
|
||||
*/
|
||||
default boolean isInFluidType(BiPredicate<FluidType, Double> predicate)
|
||||
{
|
||||
return isInFluidType(predicate, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the fluid type the entity is currently in matches
|
||||
* the specified condition.
|
||||
*
|
||||
* @param predicate a test taking in the fluid type and its height
|
||||
* @param forAllTypes {@code true} if all fluid types should match the
|
||||
* condition instead of at least one
|
||||
* @return {@code true} if a fluid type meets the condition, {@code false}
|
||||
* otherwise
|
||||
*/
|
||||
boolean isInFluidType(BiPredicate<FluidType, Double> predicate, boolean forAllTypes);
|
||||
|
||||
/**
|
||||
* Returns whether the entity is in a fluid.
|
||||
*
|
||||
* @return {@code true} if the entity is in a fluid, {@code false} otherwise
|
||||
*/
|
||||
boolean isInFluidType();
|
||||
|
||||
/**
|
||||
* Returns the fluid that is on the entity's eyes.
|
||||
*
|
||||
* @return the fluid that is on the entity's eyes
|
||||
*/
|
||||
FluidType getEyeInFluidType();
|
||||
|
||||
/**
|
||||
* Returns whether the fluid is on the entity's eyes.
|
||||
*
|
||||
* @return {@code true} if the fluid is on the entity's eyes, {@code false} otherwise
|
||||
*/
|
||||
default boolean isEyeInFluidType(FluidType type)
|
||||
{
|
||||
return type == this.getEyeInFluidType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entity can start swimming in the fluid.
|
||||
*
|
||||
* @return {@code true} if the entity can start swimming, {@code false} otherwise
|
||||
*/
|
||||
default boolean canStartSwimming()
|
||||
{
|
||||
return !this.getEyeInFluidType().isAir() && this.canSwimInFluidType(this.getEyeInFluidType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how much the velocity of the fluid should be scaled by
|
||||
* when applied to an entity.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return a scalar to multiply to the fluid velocity
|
||||
*/
|
||||
default double getFluidMotionScale(FluidType type)
|
||||
{
|
||||
return type.motionScale(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the fluid can push an entity.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return {@code true} if the entity can be pushed by the fluid, {@code false} otherwise
|
||||
*/
|
||||
default boolean isPushedByFluid(FluidType type)
|
||||
{
|
||||
return self().isPushedByFluid() && type.canPushEntity(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entity can swim in the fluid.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return {@code true} if the entity can swim in the fluid, {@code false} otherwise
|
||||
*/
|
||||
default boolean canSwimInFluidType(FluidType type)
|
||||
{
|
||||
return type.canSwim(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entity can be extinguished by this fluid.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return {@code true} if the entity can be extinguished, {@code false} otherwise
|
||||
*/
|
||||
default boolean canFluidExtinguish(FluidType type)
|
||||
{
|
||||
return type.canExtinguish(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how much the fluid should scale the damage done to a falling
|
||||
* entity when hitting the ground per tick.
|
||||
*
|
||||
* <p>Implementation: If the entity is in many fluids, the smallest modifier
|
||||
* is applied.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return a scalar to multiply to the fall damage
|
||||
*/
|
||||
default float getFluidFallDistanceModifier(FluidType type)
|
||||
{
|
||||
return type.getFallDistanceModifier(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entity can be hydrated by this fluid.
|
||||
*
|
||||
* <p>Hydration is an arbitrary word which depends on the entity.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return {@code true} if the entity can be hydrated, {@code false}
|
||||
* otherwise
|
||||
*/
|
||||
default boolean canHydrateInFluidType(FluidType type)
|
||||
{
|
||||
return type.canHydrate(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sound to play when a certain action is performed by the
|
||||
* entity in the fluid. If no sound is present, then the sound will be
|
||||
* {@code null}.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @param action the action being performed
|
||||
* @return the sound to play when performing the action
|
||||
*/
|
||||
@Nullable
|
||||
default SoundEvent getSoundFromFluidType(FluidType type, SoundAction action)
|
||||
{
|
||||
return type.getSound(self(), action);
|
||||
}
|
||||
}
|
||||
@@ -5,74 +5,36 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraft.world.level.pathfinder.BlockPathTypes;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IForgeFluid
|
||||
{
|
||||
/**
|
||||
* Called when the entity is inside this block, may be used to determined if the entity can breathing,
|
||||
* display material overlays, or if the entity can swim inside a block.
|
||||
*
|
||||
* @param level that is being tested.
|
||||
* @param pos position thats being tested.
|
||||
* @param entity that is being tested.
|
||||
* @param yToTest, primarily for testingHead, which sends the the eye level of the entity, other wise it sends a y that can be tested vs liquid height.
|
||||
* @param tag Fluid category
|
||||
* @param testingHead when true, its testing the entities head for vision, breathing ect... otherwise its testing the body, for swimming and movement adjustment.
|
||||
*/
|
||||
default boolean isEntityInside(FluidState state, LevelReader level, BlockPos pos, Entity entity, double yToTest, HolderSet<Fluid> tag, boolean testingHead)
|
||||
private Fluid self()
|
||||
{
|
||||
return state.is(tag) && yToTest < (double)(pos.getY() + state.getHeight(level, pos) + 0.11111111F);
|
||||
return (Fluid) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when boats or fishing hooks are inside the block to check if they are inside
|
||||
* the material requested.
|
||||
* Returns the explosion resistance of the fluid.
|
||||
*
|
||||
* @param level level that is being tested.
|
||||
* @param pos block thats being tested.
|
||||
* @param boundingBox box to test, generally the bounds of an entity that are besting tested.
|
||||
* @param materialIn to check for.
|
||||
* @return null for default behavior, true if the box is within the material, false if it was not.
|
||||
*/
|
||||
@Nullable
|
||||
default Boolean isAABBInsideMaterial(FluidState state, LevelReader level, BlockPos pos, AABB boundingBox, Material materialIn)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when entities are moving to check if they are inside a liquid
|
||||
*
|
||||
* @param level level that is being tested.
|
||||
* @param pos block thats being tested.
|
||||
* @param boundingBox box to test, generally the bounds of an entity that are besting tested.
|
||||
* @return null for default behavior, true if the box is within the material, false if it was not.
|
||||
*/
|
||||
@Nullable
|
||||
default Boolean isAABBInsideLiquid(FluidState state, LevelReader level, BlockPos pos, AABB boundingBox)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Location sensitive version of getExplosionResistance
|
||||
*
|
||||
* @param level The current level
|
||||
* @param pos Block position in level
|
||||
* @param explosion The explosion
|
||||
* @return The amount of the explosion absorbed.
|
||||
* @param state the state of the fluid
|
||||
* @param level the level the fluid is in
|
||||
* @param pos the position of the fluid
|
||||
* @param explosion the explosion the fluid is absorbing
|
||||
* @return the amount of the explosion the fluid can absorb
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
default float getExplosionResistance(FluidState state, BlockGetter level, BlockPos pos, Explosion explosion)
|
||||
@@ -81,17 +43,125 @@ public interface IForgeFluid
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries if this fluid should render in a given layer.
|
||||
* A custom {@link IBakedModel} can use {@link net.minecraftforge.client.MinecraftForgeClient#getRenderType()} to alter the model based on layer.
|
||||
* Returns the type of this fluid.
|
||||
*
|
||||
* <p>Important: This MUST be overridden on your fluid, otherwise an
|
||||
* error will be thrown.
|
||||
*
|
||||
* @return the type of this fluid
|
||||
*/
|
||||
/* TODO: reimplement
|
||||
default boolean canRenderInLayer(IFluidState state, BlockRenderLayer layer)
|
||||
{
|
||||
return this.getFluid().getRenderLayer() == layer;
|
||||
}*/
|
||||
FluidType getFluidType();
|
||||
|
||||
/**
|
||||
* Retrieves the non-vanilla fluid attributes, including localized name.
|
||||
* Performs how an entity moves when within the fluid. If using custom
|
||||
* movement logic, the method should return {@code true}. Otherwise, the
|
||||
* movement logic will default to water.
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @param entity the entity moving within the fluid
|
||||
* @param movementVector the velocity of how the entity wants to move
|
||||
* @param gravity the gravity to apply to the entity
|
||||
* @return {@code true} if custom movement logic is performed, {@code false} otherwise
|
||||
*/
|
||||
FluidAttributes getAttributes();
|
||||
default boolean move(FluidState state, LivingEntity entity, Vec3 movementVector, double gravity)
|
||||
{
|
||||
return getFluidType().move(state, entity, movementVector, gravity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the fluid can create a source.
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @param reader the reader that can get the fluid
|
||||
* @param pos the location of the fluid
|
||||
* @return {@code true} if the fluid can create a source, {@code false} otherwise
|
||||
*/
|
||||
default boolean canConvertToSource(FluidState state, LevelReader reader, BlockPos pos)
|
||||
{
|
||||
return getFluidType().canConvertToSource(state, reader, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the boat can be used on the fluid.
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @param boat the boat trying to be used on the fluid
|
||||
* @return {@code true} if the boat can be used, {@code false} otherwise
|
||||
*/
|
||||
default boolean supportsBoating(FluidState state, Boat boat)
|
||||
{
|
||||
return getFluidType().supportsBoating(state, boat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path type of this fluid when an entity is pathfinding. When
|
||||
* {@code null}, uses vanilla behavior.
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @param level the level which contains this fluid
|
||||
* @param pos the position of the fluid
|
||||
* @param mob the mob currently pathfinding, may be {@code null}
|
||||
* @param canFluidLog {@code true} if the path is being applied for fluids that can log blocks,
|
||||
* should be checked against if the fluid can log a block
|
||||
* @return the path type of this fluid
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPathTypes getBlockPathType(FluidState state, BlockGetter level, BlockPos pos, @org.jetbrains.annotations.Nullable Mob mob, boolean canFluidLog)
|
||||
{
|
||||
return getFluidType().getBlockPathType(state, level, pos, mob, canFluidLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path type of the adjacent fluid to a pathfinding entity.
|
||||
* Path types with a negative malus are not traversable for the entity.
|
||||
* Pathfinding entities will favor paths consisting of a lower malus.
|
||||
* When {@code null}, uses vanilla behavior.
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @param level the level which contains this fluid
|
||||
* @param pos the position of the fluid
|
||||
* @param mob the mob currently pathfinding, may be {@code null}
|
||||
* @param originalType the path type of the source the entity is on
|
||||
* @return the path type of this fluid
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPathTypes getAdjacentBlockPathType(FluidState state, BlockGetter level, BlockPos pos, @org.jetbrains.annotations.Nullable Mob mob, BlockPathTypes originalType)
|
||||
{
|
||||
return getFluidType().getAdjacentBlockPathType(state, level, pos, mob, originalType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the block can be hydrated by a fluid.
|
||||
*
|
||||
* <p>Hydration is an arbitrary word which depends on the block.
|
||||
* <ul>
|
||||
* <li>A farmland has moisture</li>
|
||||
* <li>A sponge can soak up the liquid</li>
|
||||
* <li>A coral can live</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @param getter the getter which can get the fluid
|
||||
* @param pos the position of the fluid
|
||||
* @param source the state of the block being hydrated
|
||||
* @param sourcePos the position of the block being hydrated
|
||||
* @return {@code true} if the block can be hydrated, {@code false} otherwise
|
||||
*/
|
||||
default boolean canHydrate(FluidState state, BlockGetter getter, BlockPos pos, BlockState source, BlockPos sourcePos)
|
||||
{
|
||||
return getFluidType().canHydrate(state, getter, pos, source, sourcePos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the block can be extinguished by this fluid.
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @param getter the getter which can get the fluid
|
||||
* @param pos the position of the fluid
|
||||
* @return {@code true} if the block can be extinguished, {@code false} otherwise
|
||||
*/
|
||||
default boolean canExtinguish(FluidState state, BlockGetter getter, BlockPos pos)
|
||||
{
|
||||
return getFluidType().canExtinguish(state, getter, pos);
|
||||
}
|
||||
}
|
||||
@@ -5,50 +5,153 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.pathfinder.BlockPathTypes;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IForgeFluidState
|
||||
{
|
||||
private FluidState self()
|
||||
{
|
||||
return (FluidState)this;
|
||||
return (FluidState) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the entity is inside this block, may be used to determined if the entity can breathing,
|
||||
* display material overlays, or if the entity can swim inside a block.
|
||||
* Returns the explosion resistance of the fluid.
|
||||
*
|
||||
* @param level that is being tested.
|
||||
* @param pos position thats being tested.
|
||||
* @param entity that is being tested.
|
||||
* @param yToTest, primarily for testingHead, which sends the the eye level of the entity, other wise it sends a y that can be tested vs liquid height.
|
||||
* @param tag to test for.
|
||||
* @param testingHead when true, its testing the entities head for vision, breathing ect... otherwise its testing the body, for swimming and movement adjustment.
|
||||
*/
|
||||
default boolean isEntityInside(LevelReader level, BlockPos pos, Entity entity, double yToTest, HolderSet<Fluid> tag, boolean testingHead)
|
||||
{
|
||||
// return ifluidstate.isTagged(p_213290_1_) && d0 < (double)((float)blockpos.getY() + ifluidstate.getActualHeight(this.level, blockpos) + 0.11111111F);
|
||||
return self().getType().isEntityInside(self(), level, pos, entity, yToTest, tag, testingHead);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location sensitive version of getExplosionResistance
|
||||
*
|
||||
* @param level The current level
|
||||
* @param pos Block position in level
|
||||
* @param explosion The explosion
|
||||
* @return The amount of the explosion absorbed.
|
||||
* @param level the level the fluid is in
|
||||
* @param pos the position of the fluid
|
||||
* @param explosion the explosion the fluid is absorbing
|
||||
* @return the amount of the explosion the fluid can absorb
|
||||
*/
|
||||
default float getExplosionResistance(BlockGetter level, BlockPos pos, Explosion explosion)
|
||||
{
|
||||
return self().getType().getExplosionResistance(self(), level, pos, explosion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of this fluid.
|
||||
*
|
||||
* @return the type of this fluid
|
||||
*/
|
||||
default FluidType getFluidType()
|
||||
{
|
||||
return self().getType().getFluidType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs how an entity moves when within the fluid. If using custom
|
||||
* movement logic, the method should return {@code true}. Otherwise, the
|
||||
* movement logic will default to water.
|
||||
*
|
||||
* @param entity the entity moving within the fluid
|
||||
* @param movementVector the velocity of how the entity wants to move
|
||||
* @param gravity the gravity to apply to the entity
|
||||
* @return {@code true} if custom movement logic is performed, {@code false} otherwise
|
||||
*/
|
||||
default boolean move(LivingEntity entity, Vec3 movementVector, double gravity)
|
||||
{
|
||||
return self().getType().move(self(), entity, movementVector, gravity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the fluid can create a source.
|
||||
*
|
||||
* @param reader the reader that can get the fluid
|
||||
* @param pos the location of the fluid
|
||||
* @return {@code true} if the fluid can create a source, {@code false} otherwise
|
||||
*/
|
||||
default boolean canConvertToSource(LevelReader reader, BlockPos pos)
|
||||
{
|
||||
return self().getType().canConvertToSource(self(), reader, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the boat can be used on the fluid.
|
||||
*
|
||||
* @param boat the boat trying to be used on the fluid
|
||||
* @return {@code true} if the boat can be used, {@code false} otherwise
|
||||
*/
|
||||
default boolean supportsBoating(Boat boat)
|
||||
{
|
||||
return self().getType().supportsBoating(self(), boat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path type of this fluid when an entity is pathfinding. When
|
||||
* {@code null}, uses vanilla behavior.
|
||||
*
|
||||
* @param level the level which contains this fluid
|
||||
* @param pos the position of the fluid
|
||||
* @param mob the mob currently pathfinding, may be {@code null}
|
||||
* @param canFluidLog {@code true} if the path is being applied for fluids that can log blocks,
|
||||
* should be checked against if the fluid can log a block
|
||||
* @return the path type of this fluid
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPathTypes getBlockPathType(BlockGetter level, BlockPos pos, @org.jetbrains.annotations.Nullable Mob mob, boolean canFluidLog)
|
||||
{
|
||||
return self().getType().getBlockPathType(self(), level, pos, mob, canFluidLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path type of the adjacent fluid to a pathfinding entity.
|
||||
* Path types with a negative malus are not traversable for the entity.
|
||||
* Pathfinding entities will favor paths consisting of a lower malus.
|
||||
* When {@code null}, uses vanilla behavior.
|
||||
*
|
||||
* @param level the level which contains this fluid
|
||||
* @param pos the position of the fluid
|
||||
* @param mob the mob currently pathfinding, may be {@code null}
|
||||
* @param originalType the path type of the source the entity is on
|
||||
* @return the path type of this fluid
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPathTypes getAdjacentBlockPathType(BlockGetter level, BlockPos pos, @org.jetbrains.annotations.Nullable Mob mob, BlockPathTypes originalType)
|
||||
{
|
||||
return self().getType().getAdjacentBlockPathType(self(), level, pos, mob, originalType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the block can be hydrated by a fluid.
|
||||
*
|
||||
* <p>Hydration is an arbitrary word which depends on the block.
|
||||
* <ul>
|
||||
* <li>A farmland has moisture</li>
|
||||
* <li>A sponge can soak up the liquid</li>
|
||||
* <li>A coral can live</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param getter the getter which can get the fluid
|
||||
* @param pos the position of the fluid
|
||||
* @param source the state of the block being hydrated
|
||||
* @param sourcePos the position of the block being hydrated
|
||||
* @return {@code true} if the block can be hydrated, {@code false} otherwise
|
||||
*/
|
||||
default boolean canHydrate(BlockGetter getter, BlockPos pos, BlockState source, BlockPos sourcePos)
|
||||
{
|
||||
return self().getType().canHydrate(self(), getter, pos, source, sourcePos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the block can be extinguished by this fluid.
|
||||
*
|
||||
* @param getter the getter which can get the fluid
|
||||
* @param pos the position of the fluid
|
||||
* @return {@code true} if the block can be extinguished, {@code false} otherwise
|
||||
*/
|
||||
default boolean canExtinguish(BlockGetter getter, BlockPos pos)
|
||||
{
|
||||
return self().getType().canExtinguish(self(), getter, pos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
|
||||
public interface IForgeLivingEntity extends IForgeEntity
|
||||
{
|
||||
default LivingEntity self()
|
||||
{
|
||||
return (LivingEntity) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean canSwimInFluidType(FluidType type)
|
||||
{
|
||||
if (type == ForgeMod.WATER_TYPE.get()) return !self().isSensitiveToWater();
|
||||
else return IForgeEntity.super.canSwimInFluidType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs what to do when an entity attempts to go up or "jump" in a fluid.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
*/
|
||||
default void jumpInFluid(FluidType type)
|
||||
{
|
||||
self().setDeltaMovement(self().getDeltaMovement().add(0.0D, (double)0.04F * self().getAttributeValue(ForgeMod.SWIM_SPEED.get()), 0.0D));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs what to do when an entity attempts to go down or "sink" in a fluid.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
*/
|
||||
default void sinkInFluid(FluidType type)
|
||||
{
|
||||
self().setDeltaMovement(self().getDeltaMovement().add(0.0D, (double)-0.04F * self().getAttributeValue(ForgeMod.SWIM_SPEED.get()), 0.0D));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entity can drown in the fluid.
|
||||
*
|
||||
* @param type the type of the fluid
|
||||
* @return {@code true} if the entity can drown in the fluid, {@code false} otherwise
|
||||
*/
|
||||
default boolean canDrownInFluidType(FluidType type)
|
||||
{
|
||||
if (type == ForgeMod.WATER_TYPE.get()) return !self().canBreatheUnderwater();
|
||||
return type.canDrownIn(self());
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs how an entity moves when within the fluid. If using custom
|
||||
* movement logic, the method should return {@code true}. Otherwise, the
|
||||
* movement logic will default to water.
|
||||
*
|
||||
* @param state the state of the fluid
|
||||
* @param movementVector the velocity of how the entity wants to move
|
||||
* @param gravity the gravity to apply to the entity
|
||||
* @return {@code true} if custom movement logic is performed, {@code false} otherwise
|
||||
*/
|
||||
default boolean moveInFluid(FluidState state, Vec3 movementVector, double gravity)
|
||||
{
|
||||
return state.move(self(), movementVector, gravity);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user