mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Add methods to Fluid to allow custom vaporization overrides (#2959)
This commit is contained in:
1 parent
883bfe57ab
commit
c776d97691
2 files changed
+57
-16
No files matched your search
@@ -1,14 +1,19 @@
|
||||
package net.minecraftforge.fluids;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldProvider;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
|
||||
@@ -193,6 +198,42 @@ public class Fluid
|
||||
return block != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this fluid should vaporize in dimensions where water vaporizes when placed.
|
||||
* To preserve the intentions of vanilla, fluids that can turn lava into obsidian should vaporize.
|
||||
* This prevents players from making the nether safe with a single bucket.
|
||||
* Based on {@link net.minecraft.item.ItemBucket#tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)}
|
||||
*
|
||||
* @param fluidStack The fluidStack is trying to be placed.
|
||||
* @return true if this fluid should vaporize in dimensions where water vaporizes when placed.
|
||||
*/
|
||||
public boolean doesVaporize(FluidStack fluidStack)
|
||||
{
|
||||
if (block == null)
|
||||
return false;
|
||||
return block.getDefaultState().getMaterial() == Material.WATER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called instead of placing the fluid block if {@link WorldProvider#doesWaterVaporize()} and {@link #doesVaporize(FluidStack)} are true.
|
||||
* Override this to make your explosive liquid blow up instead of the default smoke, etc.
|
||||
* Based on {@link net.minecraft.item.ItemBucket#tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)}
|
||||
*
|
||||
* @param player Player who tried to place the fluid. May be null for blocks like dispensers.
|
||||
* @param worldIn World to vaporize the fluid in.
|
||||
* @param pos The position in the world the fluid block was going to be placed.
|
||||
* @param fluidStack The fluidStack that was going to be placed.
|
||||
*/
|
||||
public void vaporize(@Nullable EntityPlayer player, World worldIn, BlockPos pos, FluidStack fluidStack)
|
||||
{
|
||||
worldIn.playSound(player, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);
|
||||
|
||||
for (int l = 0; l < 8; ++l)
|
||||
{
|
||||
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double) pos.getX() + Math.random(), (double) pos.getY() + Math.random(), (double) pos.getZ() + Math.random(), 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the localized name of this fluid.
|
||||
*/
|
||||
|
||||
@@ -414,15 +414,21 @@ public class FluidUtil
|
||||
*
|
||||
* Modeled after {@link net.minecraft.item.ItemBucket#tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)}
|
||||
*
|
||||
* @param player Player who places the fluid. May be null for blocks like dispensers.
|
||||
* @param worldIn World to place the fluid in
|
||||
* @param fluid The fluid to place.
|
||||
* @param pos The position in the world to place the fluid block
|
||||
* @param player Player who places the fluid. May be null for blocks like dispensers.
|
||||
* @param worldIn World to place the fluid in
|
||||
* @param fluidStack The fluidStack to place.
|
||||
* @param pos The position in the world to place the fluid block
|
||||
* @return true if successful
|
||||
*/
|
||||
public static boolean tryPlaceFluid(@Nullable EntityPlayer player, World worldIn, FluidStack fluid, BlockPos pos)
|
||||
public static boolean tryPlaceFluid(@Nullable EntityPlayer player, World worldIn, FluidStack fluidStack, BlockPos pos)
|
||||
{
|
||||
if (worldIn == null || fluid == null || fluid.getFluid() == null || pos == null)
|
||||
if (worldIn == null || fluidStack == null || pos == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Fluid fluid = fluidStack.getFluid();
|
||||
if (fluid == null || !fluid.canBePlacedInWorld())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -437,16 +443,9 @@ public class FluidUtil
|
||||
return false; // Non-air, solid, unreplacable block. We can't put fluid here.
|
||||
}
|
||||
|
||||
IBlockState fluidBlockState = fluid.getFluid().getBlock().getDefaultState();
|
||||
|
||||
if (worldIn.provider.doesWaterVaporize() && fluidBlockState.getMaterial() == Material.WATER)
|
||||
if (worldIn.provider.doesWaterVaporize() && fluid.doesVaporize(fluidStack))
|
||||
{
|
||||
worldIn.playSound(player, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);
|
||||
|
||||
for (int l = 0; l < 8; ++l)
|
||||
{
|
||||
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double) pos.getX() + Math.random(), (double) pos.getY() + Math.random(), (double) pos.getZ() + Math.random(), 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
fluid.vaporize(player, worldIn, pos, fluidStack);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -455,9 +454,10 @@ public class FluidUtil
|
||||
worldIn.destroyBlock(pos, true);
|
||||
}
|
||||
|
||||
SoundEvent soundevent = fluid.getFluid().getEmptySound(worldIn, pos);
|
||||
SoundEvent soundevent = fluid.getEmptySound(fluidStack);
|
||||
worldIn.playSound(player, pos, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
|
||||
IBlockState fluidBlockState = fluid.getBlock().getDefaultState();
|
||||
worldIn.setBlockState(pos, fluidBlockState, 11);
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user