Add NeighborNotiftyEvent.

This commit is contained in:
Me4502 2015-03-01 16:53:32 +10:00
parent ae085bb84d
commit c21e38cd3b
6 changed files with 172 additions and 49 deletions

View File

@ -0,0 +1,11 @@
--- ../src-base/minecraft/net/minecraft/block/BlockRedstoneDiode.java
+++ ../src-work/minecraft/net/minecraft/block/BlockRedstoneDiode.java
@@ -200,6 +200,8 @@
{
EnumFacing enumfacing = (EnumFacing)p_176400_3_.func_177229_b(field_176387_N);
BlockPos blockpos1 = p_176400_2_.func_177972_a(enumfacing.func_176734_d());
+ if(net.minecraftforge.event.ForgeEventFactory.onNeighborNotify(p_176400_1_, p_176400_2_, p_176400_1_.func_180495_p(p_176400_2_), java.util.EnumSet.of(enumfacing.func_176734_d())).isCanceled())
+ return;
p_176400_1_.func_180496_d(blockpos1, this);
p_176400_1_.func_175695_a(blockpos1, this, enumfacing);
}

View File

@ -0,0 +1,22 @@
--- ../src-base/minecraft/net/minecraft/tileentity/TileEntityPiston.java
+++ ../src-work/minecraft/net/minecraft/tileentity/TileEntityPiston.java
@@ -151,7 +151,8 @@
if (this.field_145850_b.func_180495_p(this.field_174879_c).func_177230_c() == Blocks.field_180384_M)
{
this.field_145850_b.func_180501_a(this.field_174879_c, this.field_174932_a, 3);
- this.field_145850_b.func_180496_d(this.field_174879_c, this.field_174932_a.func_177230_c());
+ if(!net.minecraftforge.event.ForgeEventFactory.onNeighborNotify(field_145850_b, field_174879_c, field_145850_b.func_180495_p(field_174879_c), java.util.EnumSet.noneOf(EnumFacing.class)).isCanceled())
+ this.field_145850_b.func_180496_d(this.field_174879_c, this.field_174932_a.func_177230_c());
}
}
}
@@ -169,7 +170,8 @@
if (this.field_145850_b.func_180495_p(this.field_174879_c).func_177230_c() == Blocks.field_180384_M)
{
this.field_145850_b.func_180501_a(this.field_174879_c, this.field_174932_a, 3);
- this.field_145850_b.func_180496_d(this.field_174879_c, this.field_174932_a.func_177230_c());
+ if(!net.minecraftforge.event.ForgeEventFactory.onNeighborNotify(field_145850_b, field_174879_c, field_145850_b.func_180495_p(field_174879_c), java.util.EnumSet.noneOf(EnumFacing.class)).isCanceled())
+ this.field_145850_b.func_180496_d(this.field_174879_c, this.field_174932_a.func_177230_c());
}
}
else

View File

@ -162,7 +162,29 @@
}
}
}
@@ -782,7 +832,7 @@
@@ -408,6 +458,9 @@
public void func_175685_c(BlockPos p_175685_1_, Block p_175685_2_)
{
+ if(net.minecraftforge.event.ForgeEventFactory.onNeighborNotify(this, p_175685_1_, this.func_180495_p(p_175685_1_), java.util.EnumSet.allOf(EnumFacing.class)).isCanceled())
+ return;
+
this.func_180496_d(p_175685_1_.func_177976_e(), p_175685_2_);
this.func_180496_d(p_175685_1_.func_177974_f(), p_175685_2_);
this.func_180496_d(p_175685_1_.func_177977_b(), p_175685_2_);
@@ -418,6 +471,11 @@
public void func_175695_a(BlockPos p_175695_1_, Block p_175695_2_, EnumFacing p_175695_3_)
{
+ java.util.EnumSet<EnumFacing> directions = java.util.EnumSet.allOf(EnumFacing.class);
+ directions.remove(p_175695_3_);
+ if(net.minecraftforge.event.ForgeEventFactory.onNeighborNotify(this, p_175695_1_, this.func_180495_p(p_175695_1_), directions).isCanceled())
+ return;
+
if (p_175695_3_ != EnumFacing.WEST)
{
this.func_180496_d(p_175695_1_.func_177976_e(), p_175695_2_);
@@ -782,7 +840,7 @@
public boolean func_72935_r()
{
@ -171,7 +193,7 @@
}
public MovingObjectPosition func_72933_a(Vec3 p_72933_1_, Vec3 p_72933_2_)
@@ -978,6 +1028,8 @@
@@ -978,6 +1036,8 @@
public void func_72956_a(Entity p_72956_1_, String p_72956_2_, float p_72956_3_, float p_72956_4_)
{
@ -180,7 +202,7 @@
for (int i = 0; i < this.field_73021_x.size(); ++i)
{
((IWorldAccess)this.field_73021_x.get(i)).func_72704_a(p_72956_2_, p_72956_1_.field_70165_t, p_72956_1_.field_70163_u, p_72956_1_.field_70161_v, p_72956_3_, p_72956_4_);
@@ -986,6 +1038,8 @@
@@ -986,6 +1046,8 @@
public void func_85173_a(EntityPlayer p_85173_1_, String p_85173_2_, float p_85173_3_, float p_85173_4_)
{
@ -189,7 +211,7 @@
for (int i = 0; i < this.field_73021_x.size(); ++i)
{
((IWorldAccess)this.field_73021_x.get(i)).func_85102_a(p_85173_1_, p_85173_2_, p_85173_1_.field_70165_t, p_85173_1_.field_70163_u, p_85173_1_.field_70161_v, p_85173_3_, p_85173_4_);
@@ -1037,6 +1091,9 @@
@@ -1037,6 +1099,9 @@
public boolean func_72838_d(Entity p_72838_1_)
{
@ -199,7 +221,7 @@
int i = MathHelper.func_76128_c(p_72838_1_.field_70165_t / 16.0D);
int j = MathHelper.func_76128_c(p_72838_1_.field_70161_v / 16.0D);
boolean flag = p_72838_1_.field_98038_p;
@@ -1059,6 +1116,8 @@
@@ -1059,6 +1124,8 @@
this.func_72854_c();
}
@ -208,7 +230,7 @@
this.func_72964_e(i, j).func_76612_a(p_72838_1_);
this.field_72996_f.add(p_72838_1_);
this.func_72923_a(p_72838_1_);
@@ -1271,17 +1330,29 @@
@@ -1271,17 +1338,29 @@
public int func_72967_a(float p_72967_1_)
{
@ -241,7 +263,7 @@
public void func_72848_b(IWorldAccess p_72848_1_)
{
this.field_73021_x.remove(p_72848_1_);
@@ -1290,6 +1361,12 @@
@@ -1290,6 +1369,12 @@
@SideOnly(Side.CLIENT)
public float func_72971_b(float p_72971_1_)
{
@ -254,7 +276,7 @@
float f1 = this.func_72826_c(p_72971_1_);
float f2 = 1.0F - (MathHelper.func_76134_b(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.2F);
f2 = MathHelper.func_76131_a(f2, 0.0F, 1.0F);
@@ -1302,6 +1379,12 @@
@@ -1302,6 +1387,12 @@
@SideOnly(Side.CLIENT)
public Vec3 func_72833_a(Entity p_72833_1_, float p_72833_2_)
{
@ -267,7 +289,7 @@
float f1 = this.func_72826_c(p_72833_2_);
float f2 = MathHelper.func_76134_b(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.5F;
f2 = MathHelper.func_76131_a(f2, 0.0F, 1.0F);
@@ -1309,9 +1392,7 @@
@@ -1309,9 +1400,7 @@
int j = MathHelper.func_76128_c(p_72833_1_.field_70163_u);
int k = MathHelper.func_76128_c(p_72833_1_.field_70161_v);
BlockPos blockpos = new BlockPos(i, j, k);
@ -278,7 +300,7 @@
float f4 = (float)(l >> 16 & 255) / 255.0F;
float f5 = (float)(l >> 8 & 255) / 255.0F;
float f6 = (float)(l & 255) / 255.0F;
@@ -1373,6 +1454,11 @@
@@ -1373,6 +1462,11 @@
public float func_130001_d()
{
@ -290,7 +312,7 @@
return WorldProvider.field_111203_a[this.field_73011_w.func_76559_b(this.field_72986_A.func_76073_f())];
}
@@ -1385,6 +1471,12 @@
@@ -1385,6 +1479,12 @@
@SideOnly(Side.CLIENT)
public Vec3 func_72824_f(float p_72824_1_)
{
@ -303,7 +325,7 @@
float f1 = this.func_72826_c(p_72824_1_);
float f2 = MathHelper.func_76134_b(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.5F;
f2 = MathHelper.func_76131_a(f2, 0.0F, 1.0F);
@@ -1442,9 +1534,9 @@
@@ -1442,9 +1542,9 @@
for (blockpos1 = new BlockPos(p_175672_1_.func_177958_n(), chunk.func_76625_h() + 16, p_175672_1_.func_177952_p()); blockpos1.func_177956_o() >= 0; blockpos1 = blockpos2)
{
blockpos2 = blockpos1.func_177977_b();
@ -315,7 +337,7 @@
{
break;
}
@@ -1456,6 +1548,12 @@
@@ -1456,6 +1556,12 @@
@SideOnly(Side.CLIENT)
public float func_72880_h(float p_72880_1_)
{
@ -328,7 +350,7 @@
float f1 = this.func_72826_c(p_72880_1_);
float f2 = 1.0F - (MathHelper.func_76134_b(f1 * (float)Math.PI * 2.0F) * 2.0F + 0.25F);
f2 = MathHelper.func_76131_a(f2, 0.0F, 1.0F);
@@ -1500,7 +1598,15 @@
@@ -1500,7 +1606,15 @@
entity.func_85029_a(crashreportcategory);
}
@ -345,7 +367,7 @@
}
if (entity.field_70128_L)
@@ -1562,7 +1668,16 @@
@@ -1562,7 +1676,16 @@
crashreport = CrashReport.func_85055_a(throwable1, "Ticking entity");
crashreportcategory = crashreport.func_85058_a("Entity being ticked");
entity.func_85029_a(crashreportcategory);
@ -363,7 +385,7 @@
}
}
@@ -1609,7 +1724,16 @@
@@ -1609,7 +1732,16 @@
CrashReport crashreport1 = CrashReport.func_85055_a(throwable, "Ticking block entity");
CrashReportCategory crashreportcategory1 = crashreport1.func_85058_a("Block entity being ticked");
tileentity.func_145828_a(crashreportcategory1);
@ -381,7 +403,7 @@
}
}
}
@@ -1628,6 +1752,10 @@
@@ -1628,6 +1760,10 @@
if (!this.field_147483_b.isEmpty())
{
@ -392,7 +414,7 @@
this.field_175730_i.removeAll(this.field_147483_b);
this.field_147482_g.removeAll(this.field_147483_b);
this.field_147483_b.clear();
@@ -1668,7 +1796,8 @@
@@ -1668,7 +1804,8 @@
public boolean func_175700_a(TileEntity p_175700_1_)
{
@ -402,7 +424,7 @@
if (flag && p_175700_1_ instanceof IUpdatePlayerListBox)
{
@@ -1710,9 +1839,12 @@
@@ -1710,9 +1847,12 @@
{
int i = MathHelper.func_76128_c(p_72866_1_.field_70165_t);
int j = MathHelper.func_76128_c(p_72866_1_.field_70161_v);
@ -417,7 +439,7 @@
{
p_72866_1_.field_70142_S = p_72866_1_.field_70165_t;
p_72866_1_.field_70137_T = p_72866_1_.field_70163_u;
@@ -1839,7 +1971,7 @@
@@ -1839,7 +1979,7 @@
{
Block block = this.func_180495_p(new BlockPos(k1, l1, i2)).func_177230_c();
@ -426,7 +448,7 @@
{
return true;
}
@@ -1901,6 +2033,10 @@
@@ -1901,6 +2041,10 @@
{
return true;
}
@ -437,7 +459,7 @@
}
}
}
@@ -2039,6 +2175,7 @@
@@ -2039,6 +2183,7 @@
public Explosion func_72885_a(Entity p_72885_1_, double p_72885_2_, double p_72885_4_, double p_72885_6_, float p_72885_8_, boolean p_72885_9_, boolean p_72885_10_)
{
Explosion explosion = new Explosion(this, p_72885_1_, p_72885_2_, p_72885_4_, p_72885_6_, p_72885_8_, p_72885_9_, p_72885_10_);
@ -445,7 +467,7 @@
explosion.func_77278_a();
explosion.func_77279_a(true);
return explosion;
@@ -2185,19 +2322,28 @@
@@ -2185,19 +2330,28 @@
else
{
this.func_175700_a(p_175690_2_);
@ -475,7 +497,7 @@
}
else
{
@@ -2210,6 +2356,7 @@
@@ -2210,6 +2364,7 @@
this.func_175726_f(p_175713_1_).func_177425_e(p_175713_1_);
}
@ -483,7 +505,7 @@
}
public void func_147457_a(TileEntity p_147457_1_)
@@ -2228,7 +2375,7 @@
@@ -2228,7 +2383,7 @@
{
IBlockState iblockstate = p_175683_0_.func_180495_p(p_175683_1_);
Block block = iblockstate.func_177230_c();
@ -492,7 +514,7 @@
}
public boolean func_175677_d(BlockPos p_175677_1_, boolean p_175677_2_)
@@ -2248,7 +2395,7 @@
@@ -2248,7 +2403,7 @@
else
{
Block block = this.func_180495_p(p_175677_1_).func_177230_c();
@ -501,7 +523,7 @@
}
}
}
@@ -2265,8 +2412,7 @@
@@ -2265,8 +2420,7 @@
public void func_72891_a(boolean p_72891_1_, boolean p_72891_2_)
{
@ -511,7 +533,7 @@
}
public void func_72835_b()
@@ -2276,6 +2422,11 @@
@@ -2276,6 +2430,11 @@
protected void func_72947_a()
{
@ -523,7 +545,7 @@
if (this.field_72986_A.func_76059_o())
{
this.field_73004_o = 1.0F;
@@ -2289,6 +2440,11 @@
@@ -2289,6 +2448,11 @@
protected void func_72979_l()
{
@ -535,7 +557,7 @@
if (!this.field_73011_w.func_177495_o())
{
if (!this.field_72995_K)
@@ -2383,6 +2539,7 @@
@@ -2383,6 +2547,7 @@
{
this.field_72993_I.clear();
this.field_72984_F.func_76320_a("buildList");
@ -543,7 +565,7 @@
int i;
EntityPlayer entityplayer;
int j;
@@ -2445,7 +2602,7 @@
@@ -2445,7 +2610,7 @@
l += p_147467_1_;
i1 += p_147467_2_;
@ -552,7 +574,7 @@
{
EntityPlayer entityplayer = this.func_72977_a((double)l + 0.5D, (double)j1 + 0.5D, (double)i1 + 0.5D, 8.0D);
@@ -2485,6 +2642,11 @@
@@ -2485,6 +2650,11 @@
public boolean func_175670_e(BlockPos p_175670_1_, boolean p_175670_2_)
{
@ -564,7 +586,7 @@
BiomeGenBase biomegenbase = this.func_180494_b(p_175670_1_);
float f = biomegenbase.func_180626_a(p_175670_1_);
@@ -2526,6 +2688,11 @@
@@ -2526,6 +2696,11 @@
public boolean func_175708_f(BlockPos p_175708_1_, boolean p_175708_2_)
{
@ -576,7 +598,7 @@
BiomeGenBase biomegenbase = this.func_180494_b(p_175708_1_);
float f = biomegenbase.func_180626_a(p_175708_1_);
@@ -2543,7 +2710,7 @@
@@ -2543,7 +2718,7 @@
{
Block block = this.func_180495_p(p_175708_1_).func_177230_c();
@ -585,7 +607,7 @@
{
return true;
}
@@ -2575,10 +2742,11 @@
@@ -2575,10 +2750,11 @@
else
{
Block block = this.func_180495_p(p_175638_1_).func_177230_c();
@ -600,7 +622,7 @@
{
j = 1;
}
@@ -2792,10 +2960,10 @@
@@ -2792,10 +2968,10 @@
public List func_175674_a(Entity p_175674_1_, AxisAlignedBB p_175674_2_, Predicate p_175674_3_)
{
ArrayList arraylist = Lists.newArrayList();
@ -615,7 +637,7 @@
for (int i1 = i; i1 <= j; ++i1)
{
@@ -2854,10 +3022,10 @@
@@ -2854,10 +3030,10 @@
public List func_175647_a(Class p_175647_1_, AxisAlignedBB p_175647_2_, Predicate p_175647_3_)
{
@ -630,7 +652,7 @@
ArrayList arraylist = Lists.newArrayList();
for (int i1 = i; i1 <= j; ++i1)
@@ -2938,13 +3106,16 @@
@@ -2938,13 +3114,16 @@
public void func_175650_b(Collection p_175650_1_)
{
@ -649,7 +671,7 @@
}
}
@@ -2957,7 +3128,9 @@
@@ -2957,7 +3136,9 @@
{
Block block1 = this.func_180495_p(p_175716_2_).func_177230_c();
AxisAlignedBB axisalignedbb = p_175716_3_ ? null : p_175716_1_.func_180640_a(this, p_175716_2_, p_175716_1_.func_176223_P());
@ -660,7 +682,7 @@
}
public int func_175627_a(BlockPos p_175627_1_, EnumFacing p_175627_2_)
@@ -3032,7 +3205,7 @@
@@ -3032,7 +3213,7 @@
{
IBlockState iblockstate = this.func_180495_p(p_175651_1_);
Block block = iblockstate.func_177230_c();
@ -669,7 +691,7 @@
}
public boolean func_175640_z(BlockPos p_175640_1_)
@@ -3160,7 +3333,7 @@
@@ -3160,7 +3341,7 @@
public long func_72905_C()
{
@ -678,7 +700,7 @@
}
public long func_82737_E()
@@ -3170,17 +3343,17 @@
@@ -3170,17 +3351,17 @@
public long func_72820_D()
{
@ -699,7 +721,7 @@
if (!this.func_175723_af().func_177746_a(blockpos))
{
@@ -3192,7 +3365,7 @@
@@ -3192,7 +3373,7 @@
public void func_175652_B(BlockPos p_175652_1_)
{
@ -708,7 +730,7 @@
}
@SideOnly(Side.CLIENT)
@@ -3212,12 +3385,18 @@
@@ -3212,12 +3393,18 @@
if (!this.field_72996_f.contains(p_72897_1_))
{
@ -727,7 +749,7 @@
return true;
}
@@ -3307,8 +3486,7 @@
@@ -3307,8 +3494,7 @@
public boolean func_180502_D(BlockPos p_180502_1_)
{
@ -737,7 +759,7 @@
}
public MapStorage func_175693_T()
@@ -3367,12 +3545,12 @@
@@ -3367,12 +3553,12 @@
public int func_72800_K()
{
@ -752,7 +774,7 @@
}
public Random func_72843_D(int p_72843_1_, int p_72843_2_, int p_72843_3_)
@@ -3429,7 +3607,7 @@
@@ -3429,7 +3615,7 @@
@SideOnly(Side.CLIENT)
public double func_72919_O()
{
@ -761,7 +783,7 @@
}
public void func_175715_c(int p_175715_1_, BlockPos p_175715_2_, int p_175715_3_)
@@ -3461,29 +3639,21 @@
@@ -3461,29 +3647,21 @@
public void func_175666_e(BlockPos p_175666_1_, Block p_175666_2_)
{
@ -798,7 +820,7 @@
}
}
}
@@ -3553,4 +3723,82 @@
@@ -3553,4 +3731,82 @@
short short1 = 128;
return k >= -short1 && k <= short1 && l >= -short1 && l <= short1;
}

View File

@ -2,6 +2,7 @@ package net.minecraftforge.event;
import java.io.File;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -62,6 +63,7 @@ import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent;
import net.minecraftforge.event.world.BlockEvent.MultiPlaceEvent;
import net.minecraftforge.event.world.BlockEvent.PlaceEvent;
import net.minecraftforge.event.world.ExplosionEvent;
@ -89,6 +91,13 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static NeighborNotifyEvent onNeighborNotify(World world, BlockPos pos, IBlockState state, EnumSet<EnumFacing> notifiedSides)
{
NeighborNotifyEvent event = new NeighborNotifyEvent(world, pos, state, notifiedSides);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static boolean doPlayerHarvestCheck(EntityPlayer player, Block block, boolean success)
{

View File

@ -1,6 +1,7 @@
package net.minecraftforge.event.world;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.block.Block;
@ -9,6 +10,7 @@ import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.BlockSnapshot;
@ -177,4 +179,31 @@ public class BlockEvent extends Event
return blockSnapshots;
}
}
/**
* Fired when a physics update occurs on a block. This event acts as
* a way for mods to detect physics updates, in the same way a BUD switch
* does. This event is only called on the server.
*/
@Cancelable
public static class NeighborNotifyEvent extends BlockEvent
{
private final EnumSet<EnumFacing> notifiedSides;
public NeighborNotifyEvent(World world, BlockPos pos, IBlockState state, EnumSet<EnumFacing> notifiedSides)
{
super(world, pos, state);
this.notifiedSides = notifiedSides;
}
/**
* Gets a list of directions from the base block that updates will occur upon.
*
* @return list of notified directions
*/
public EnumSet<EnumFacing> getNotifiedSides()
{
return notifiedSides;
}
}
}

View File

@ -0,0 +1,30 @@
package net.minecraftforge.test;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod(modid="NeighborNotifyEventTest", name="NeighborNotifyEventTest", version="0.0.0")
public class NeighborNotifyEventTest
{
public static final boolean ENABLE = false;
@EventHandler
public void init(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onNeighborNotify(NeighborNotifyEvent event)
{
if(ENABLE) {
System.out.println(event.pos.toString());
event.setCanceled(true);
}
}
}