diff --git a/patches/minecraft/net/minecraft/block/BlockDynamicLiquid.java.patch b/patches/minecraft/net/minecraft/block/BlockDynamicLiquid.java.patch index 00faef8ff..6cb27004c 100644 --- a/patches/minecraft/net/minecraft/block/BlockDynamicLiquid.java.patch +++ b/patches/minecraft/net/minecraft/block/BlockDynamicLiquid.java.patch @@ -17,6 +17,15 @@ { IBlockState iblockstate = p_180650_1_.func_180495_p(p_180650_2_.func_177977_b()); +@@ -118,7 +119,7 @@ + { + if (this.field_149764_J == Material.field_151587_i && p_180650_1_.func_180495_p(p_180650_2_.func_177977_b()).func_185904_a() == Material.field_151586_h) + { +- p_180650_1_.func_175656_a(p_180650_2_.func_177977_b(), Blocks.field_150348_b.func_176223_P()); ++ p_180650_1_.func_175656_a(p_180650_2_.func_177977_b(), net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(p_180650_1_, p_180650_2_.func_177977_b(), p_180650_2_, Blocks.field_150348_b.func_176223_P())); + this.func_180688_d(p_180650_1_, p_180650_2_.func_177977_b()); + return; + } @@ -166,6 +167,7 @@ } else diff --git a/patches/minecraft/net/minecraft/block/BlockFarmland.java.patch b/patches/minecraft/net/minecraft/block/BlockFarmland.java.patch index 56847f071..cabce5427 100644 --- a/patches/minecraft/net/minecraft/block/BlockFarmland.java.patch +++ b/patches/minecraft/net/minecraft/block/BlockFarmland.java.patch @@ -1,6 +1,6 @@ --- ../src-base/minecraft/net/minecraft/block/BlockFarmland.java +++ ../src-work/minecraft/net/minecraft/block/BlockFarmland.java -@@ -72,9 +72,10 @@ +@@ -72,7 +72,7 @@ public void func_180658_a(World p_180658_1_, BlockPos p_180658_2_, Entity p_180658_3_, float p_180658_4_) { @@ -9,9 +9,7 @@ { func_190970_b(p_180658_1_, p_180658_2_); } - - super.func_180658_a(p_180658_1_, p_180658_2_, p_180658_3_, p_180658_4_); -@@ -95,7 +96,7 @@ +@@ -95,7 +95,7 @@ private boolean func_176529_d(World p_176529_1_, BlockPos p_176529_2_) { Block block = p_176529_1_.func_180495_p(p_176529_2_.func_177984_a()).func_177230_c(); diff --git a/patches/minecraft/net/minecraft/block/BlockLiquid.java.patch b/patches/minecraft/net/minecraft/block/BlockLiquid.java.patch index 778caf7c4..f5635a58f 100644 --- a/patches/minecraft/net/minecraft/block/BlockLiquid.java.patch +++ b/patches/minecraft/net/minecraft/block/BlockLiquid.java.patch @@ -1,5 +1,22 @@ --- ../src-base/minecraft/net/minecraft/block/BlockLiquid.java +++ ../src-work/minecraft/net/minecraft/block/BlockLiquid.java +@@ -284,14 +284,14 @@ + + if (integer.intValue() == 0) + { +- p_176365_1_.func_175656_a(p_176365_2_, Blocks.field_150343_Z.func_176223_P()); ++ p_176365_1_.func_175656_a(p_176365_2_, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(p_176365_1_, p_176365_2_, p_176365_2_, Blocks.field_150343_Z.func_176223_P())); + this.func_180688_d(p_176365_1_, p_176365_2_); + return true; + } + + if (integer.intValue() <= 4) + { +- p_176365_1_.func_175656_a(p_176365_2_, Blocks.field_150347_e.func_176223_P()); ++ p_176365_1_.func_175656_a(p_176365_2_, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(p_176365_1_, p_176365_2_, p_176365_2_, Blocks.field_150347_e.func_176223_P())); + this.func_180688_d(p_176365_1_, p_176365_2_); + return true; + } @@ -452,4 +452,29 @@ { return BlockFaceShape.UNDEFINED; diff --git a/patches/minecraft/net/minecraft/block/BlockStaticLiquid.java.patch b/patches/minecraft/net/minecraft/block/BlockStaticLiquid.java.patch index 52938b49f..20d78abae 100644 --- a/patches/minecraft/net/minecraft/block/BlockStaticLiquid.java.patch +++ b/patches/minecraft/net/minecraft/block/BlockStaticLiquid.java.patch @@ -1,6 +1,6 @@ --- ../src-base/minecraft/net/minecraft/block/BlockStaticLiquid.java +++ ../src-work/minecraft/net/minecraft/block/BlockStaticLiquid.java -@@ -52,14 +52,14 @@ +@@ -52,22 +52,22 @@ { blockpos = blockpos.func_177982_a(p_180650_4_.nextInt(3) - 1, 1, p_180650_4_.nextInt(3) - 1); @@ -18,7 +18,8 @@ { if (this.func_176369_e(p_180650_1_, blockpos)) { -@@ -67,7 +67,7 @@ +- p_180650_1_.func_175656_a(blockpos, Blocks.field_150480_ab.func_176223_P()); ++ p_180650_1_.func_175656_a(blockpos, net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(p_180650_1_, blockpos, p_180650_2_, Blocks.field_150480_ab.func_176223_P())); return; } } @@ -27,3 +28,12 @@ { return; } +@@ -86,7 +86,7 @@ + + if (p_180650_1_.func_175623_d(blockpos1.func_177984_a()) && this.func_176368_m(p_180650_1_, blockpos1)) + { +- p_180650_1_.func_175656_a(blockpos1.func_177984_a(), Blocks.field_150480_ab.func_176223_P()); ++ p_180650_1_.func_175656_a(blockpos1.func_177984_a(), net.minecraftforge.event.ForgeEventFactory.fireFluidPlaceBlockEvent(p_180650_1_, blockpos1.func_177984_a(), p_180650_2_, Blocks.field_150480_ab.func_176223_P())); + } + } + } diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index e2e49c0b7..ebd87c00f 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -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 toolTip, ITooltipFlag flags) { ItemTooltipEvent event = new ItemTooltipEvent(itemStack, entityPlayer, toolTip, flags); diff --git a/src/main/java/net/minecraftforge/event/world/BlockEvent.java b/src/main/java/net/minecraftforge/event/world/BlockEvent.java index c0ad8c70c..aeccfc589 100644 --- a/src/main/java/net/minecraftforge/event/world/BlockEvent.java +++ b/src/main/java/net/minecraftforge/event/world/BlockEvent.java @@ -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. * diff --git a/src/test/java/net/minecraftforge/debug/FluidPlaceBlockTest.java b/src/test/java/net/minecraftforge/debug/FluidPlaceBlockTest.java new file mode 100644 index 000000000..95b97e290 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/FluidPlaceBlockTest.java @@ -0,0 +1,45 @@ +package net.minecraftforge.debug; + +import net.minecraft.block.BlockStone; +import net.minecraft.init.Blocks; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeHills; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.BlockEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +/** + * This test will: + * - Cause lava to turn into gold when touched by water. + * - Replace the result of a cobblestone generator with granite. + * - Replace the result of a stone generator with either diamond, or emerald when in a biome where emerald spawns naturally. + * - Prevent lava from setting surrounding blocks on fire. + */ +@Mod(modid = "fluidplaceblocktest", name = "FluidPlaceBlockTest", version = "0.0.0", acceptableRemoteVersions = "*") +public class FluidPlaceBlockTest +{ + private static final boolean ENABLED = false; + + @Mod.EventHandler + public void preinit(FMLPreInitializationEvent event) + { + if (!ENABLED) return; + MinecraftForge.EVENT_BUS.register(FluidPlaceBlockTest.class); + } + + @SubscribeEvent @SuppressWarnings("unused") + public static void onFluidPlaceBlockEvent(BlockEvent.FluidPlaceBlockEvent event) + { + if (event.getState().getBlock() == Blocks.OBSIDIAN) event.setNewState(Blocks.GOLD_BLOCK.getDefaultState()); + if (event.getState().getBlock() == Blocks.COBBLESTONE) event.setNewState(Blocks.STONE.getDefaultState().withProperty(BlockStone.VARIANT, BlockStone.EnumType.GRANITE)); + if (event.getState() == Blocks.STONE.getDefaultState()) + { + Biome biome = event.getWorld().getBiome(event.getPos()); + if (biome instanceof BiomeHills) event.setNewState(Blocks.EMERALD_BLOCK.getDefaultState()); + else event.setNewState(Blocks.DIAMOND_BLOCK.getDefaultState()); + } + if (event.getState().getBlock() == Blocks.FIRE) event.setNewState(event.getOriginalState()); + } +}