From 1fa0c0c54885c024bf850cf457695b89f97b2e81 Mon Sep 17 00:00:00 2001 From: iChun Date: Fri, 18 Nov 2016 20:24:55 +0000 Subject: [PATCH] Add GetCollisionBoxesEvent. Allows manipulation of the collision boxes of blocks for entities. MC1.11 edition. (#3405) --- .../net/minecraft/world/World.java.patch | 18 +++++ .../event/world/GetCollisionBoxesEvent.java | 73 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/main/java/net/minecraftforge/event/world/GetCollisionBoxesEvent.java diff --git a/patches/minecraft/net/minecraft/world/World.java.patch b/patches/minecraft/net/minecraft/world/World.java.patch index 458591f36..1653b5980 100644 --- a/patches/minecraft/net/minecraft/world/World.java.patch +++ b/patches/minecraft/net/minecraft/world/World.java.patch @@ -204,6 +204,15 @@ 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_); +@@ -1290,7 +1353,7 @@ + } + } + } +- ++ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.GetCollisionBoxesEvent(this, p_184144_1_, p_184144_2_, list)); + return list; + } + @@ -1319,7 +1382,6 @@ return p_175673_2_.field_70165_t > d0 && p_175673_2_.field_70165_t < d2 && p_175673_2_.field_70161_v > d1 && p_175673_2_.field_70161_v < d3; } @@ -212,6 +221,15 @@ public void func_72848_b(IWorldEventListener p_72848_1_) { this.field_73021_x.remove(p_72848_1_); +@@ -1360,7 +1422,7 @@ + + IBlockState iblockstate = this.func_180495_p(blockpos$pooledmutableblockpos); + iblockstate.func_185908_a(this, blockpos$pooledmutableblockpos, p_184143_1_, list, (Entity)null); +- ++ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.GetCollisionBoxesEvent(this, null, p_184143_1_, list)); + if (!list.isEmpty()) + { + boolean flag = true; @@ -1382,19 +1444,38 @@ public int func_72967_a(float p_72967_1_) diff --git a/src/main/java/net/minecraftforge/event/world/GetCollisionBoxesEvent.java b/src/main/java/net/minecraftforge/event/world/GetCollisionBoxesEvent.java new file mode 100644 index 000000000..5b0c596a2 --- /dev/null +++ b/src/main/java/net/minecraftforge/event/world/GetCollisionBoxesEvent.java @@ -0,0 +1,73 @@ +/* + * Minecraft Forge + * Copyright (c) 2016. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.event.world; + +import net.minecraft.entity.Entity; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.Cancelable; + +import javax.annotation.Nullable; +import java.util.List; + +/** + * This event is fired during {@link World#collidesWithAnyBlock(AxisAlignedBB)} + * and before returning the list in {@link World#getCollisionBoxes(Entity, AxisAlignedBB)}
+ *
+ * {@link #entity} contains the entity passed in the {@link World#getCollisionBoxes(Entity, AxisAlignedBB)}. Can be null. Calls from {@link World#collidesWithAnyBlock(AxisAlignedBB)} will be null.
+ * {@link #aabb} contains the AxisAlignedBB passed in the method.
+ * {@link #collisionBoxesList} contains the list of detected collision boxes intersecting with {@link #aabb}. The list can be modified.
+ *
+ * This event is not {@link Cancelable}.
+ *
+ * This event does not have a result. {@link HasResult}
+ *
+ * This event is fired on the {@link MinecraftForge#EVENT_BUS}.
+ **/ +public class GetCollisionBoxesEvent extends WorldEvent +{ + private final Entity entity; + private final AxisAlignedBB aabb; + private final List collisionBoxesList; + + public GetCollisionBoxesEvent(World world, @Nullable Entity entity, AxisAlignedBB aabb, List collisionBoxesList) + { + super(world); + this.entity = entity; + this.aabb = aabb; + this.collisionBoxesList = collisionBoxesList; + } + + public Entity getEntity() + { + return entity; + } + + public AxisAlignedBB getAabb() + { + return aabb; + } + + public List getCollisionBoxesList() + { + return collisionBoxesList; + } +}