From 2f802b6d719bbea3dbe7112e4a473eff6c7fe55e Mon Sep 17 00:00:00 2001 From: iChun Date: Fri, 18 Nov 2016 20:25:25 +0000 Subject: [PATCH] Add GetCollisionBoxesEvent. Allows manipulation of the collision boxes for moving entities and entities stuck in walls. (#3397) --- .../net/minecraft/entity/Entity.java.patch | 9 +++ .../net/minecraft/world/World.java.patch | 9 +++ .../event/world/GetCollisionBoxesEvent.java | 73 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/main/java/net/minecraftforge/event/world/GetCollisionBoxesEvent.java diff --git a/patches/minecraft/net/minecraft/entity/Entity.java.patch b/patches/minecraft/net/minecraft/entity/Entity.java.patch index f15eb5bd9f..b964350f84 100644 --- a/patches/minecraft/net/minecraft/entity/Entity.java.patch +++ b/patches/minecraft/net/minecraft/entity/Entity.java.patch @@ -109,6 +109,15 @@ this.field_184239_as = null; entity.func_184225_p(this); } +@@ -2182,7 +2201,7 @@ + double d1 = p_145771_3_ - (double)blockpos.func_177956_o(); + double d2 = p_145771_5_ - (double)blockpos.func_177952_p(); + List list = this.field_70170_p.func_147461_a(this.func_174813_aQ()); +- ++ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.GetCollisionBoxesEvent(this.field_70170_p, this, this.func_174813_aQ(), list)); + if (list.isEmpty()) + { + return false; @@ -2336,6 +2355,7 @@ { if (!this.field_70170_p.field_72995_K && !this.field_70128_L) diff --git a/patches/minecraft/net/minecraft/world/World.java.patch b/patches/minecraft/net/minecraft/world/World.java.patch index 143a29d01b..c9577bf01c 100644 --- a/patches/minecraft/net/minecraft/world/World.java.patch +++ b/patches/minecraft/net/minecraft/world/World.java.patch @@ -206,6 +206,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_); +@@ -1221,7 +1284,7 @@ + } + } + } +- ++ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.GetCollisionBoxesEvent(this, p_184144_1_, p_184144_2_, list)); + return list; + } + @@ -1296,7 +1359,6 @@ return list; } 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 0000000000..8b861693ec --- /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 after {@link Entity#pushOutOfBlocks(double, double, double)} calls {@link World#getCollisionBoxes(AxisAlignedBB)} + * and before returning the list in {@link World#getCollisionBoxes(Entity, AxisAlignedBB)}
+ *
+ * {@link #entity} contains the entity calling {@link Entity#pushOutOfBlocks(double, double, double)} or the entity passed in the {@link World#getCollisionBoxes(Entity, AxisAlignedBB)}. Can 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; + } +}