mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-14 01:04:24 +00:00
Added Fluid Place Block Event for when fluid changes blocks in world. (#4627)
This commit is contained in:
1 parent
0e4d73230b
commit
1007d3e9c5
7 files changed
+148
-7
No files matched your search
@@ -25,6 +25,7 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockPortal;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -319,6 +320,13 @@ public class ForgeEventFactory
|
||||
return event.getDropChance();
|
||||
}
|
||||
|
||||
public static IBlockState fireFluidPlaceBlockEvent(World world, BlockPos pos, BlockPos liquidPos, IBlockState state)
|
||||
{
|
||||
BlockEvent.FluidPlaceBlockEvent event = new BlockEvent.FluidPlaceBlockEvent(world, pos, liquidPos, state);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getNewState();
|
||||
}
|
||||
|
||||
public static ItemTooltipEvent onItemTooltip(ItemStack itemStack, @Nullable EntityPlayer entityPlayer, List<String> toolTip, ITooltipFlag flags)
|
||||
{
|
||||
ItemTooltipEvent event = new ItemTooltipEvent(itemStack, entityPlayer, toolTip, flags);
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockPortal;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -127,7 +128,7 @@ public class BlockEvent extends Event
|
||||
this.player = player;
|
||||
|
||||
if (state == null || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos) || // Handle empty block or player unable to break block scenario
|
||||
(state.getBlock().canSilkHarvest(world, pos, world.getBlockState(pos), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) // If the block is being silk harvested, the exp dropped is 0
|
||||
(state.getBlock().canSilkHarvest(world, pos, world.getBlockState(pos), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) // If the block is being silk harvested, the exp dropped is 0
|
||||
{
|
||||
this.exp = 0;
|
||||
}
|
||||
@@ -287,6 +288,59 @@ public class BlockEvent extends Event
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a liquid places a block. Use {@link #setNewState(IBlockState)} to change the result of
|
||||
* a cobblestone generator or add variants of obsidian. Alternatively, you could execute
|
||||
* arbitrary code when lava sets blocks on fire, even preventing it.
|
||||
*
|
||||
* {@link #getState()} will return the block that was originally going to be placed.
|
||||
* {@link #getPos()} will return the position of the block to be changed.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class FluidPlaceBlockEvent extends BlockEvent
|
||||
{
|
||||
private final BlockPos liquidPos;
|
||||
private IBlockState newState;
|
||||
private IBlockState origState;
|
||||
|
||||
public FluidPlaceBlockEvent(World world, BlockPos pos, BlockPos liquidPos, IBlockState state)
|
||||
{
|
||||
super(world, pos, state);
|
||||
this.liquidPos = liquidPos;
|
||||
this.newState = state;
|
||||
this.origState = world.getBlockState(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The position of the liquid this event originated from. This may be the same as {@link #getPos()}.
|
||||
*/
|
||||
public BlockPos getLiquidPos()
|
||||
{
|
||||
return liquidPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The block state that will be placed after this event resolves.
|
||||
*/
|
||||
public IBlockState getNewState()
|
||||
{
|
||||
return newState;
|
||||
}
|
||||
|
||||
public void setNewState(IBlockState state)
|
||||
{
|
||||
this.newState = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The state of the block to be changed before the event was fired.
|
||||
*/
|
||||
public IBlockState getOriginalState()
|
||||
{
|
||||
return origState;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a crop block grows. See subevents.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user