From c09fe570316274d89d503148c873ba3479c3d5f4 Mon Sep 17 00:00:00 2001 From: Wire Segal <6596492+yrsegal@users.noreply.github.com> Date: Tue, 3 Sep 2019 17:50:27 -0400 Subject: [PATCH] Add collisionExtendsVertically hook to allow modded blocks that extend collision into the block above similar to fences. (#6092) --- .../minecraft/net/minecraft/entity/Entity.java.patch | 7 ++++++- .../entity/player/ServerPlayerEntity.java.patch | 7 ++++++- .../minecraftforge/common/extensions/IForgeBlock.java | 10 ++++++++++ .../common/extensions/IForgeBlockState.java | 9 +++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/patches/minecraft/net/minecraft/entity/Entity.java.patch b/patches/minecraft/net/minecraft/entity/Entity.java.patch index a8cc2adc6..2406f7f48 100644 --- a/patches/minecraft/net/minecraft/entity/Entity.java.patch +++ b/patches/minecraft/net/minecraft/entity/Entity.java.patch @@ -64,7 +64,7 @@ float f = this.field_213325_aI.field_220315_a / 2.0F; float f1 = this.field_213325_aI.field_220316_b; this.func_174826_a(new AxisAlignedBB(p_70107_1_ - (double)f, p_70107_3_, p_70107_5_ - (double)f, p_70107_1_ + (double)f, p_70107_3_ + (double)f1, p_70107_5_ + (double)f)); -@@ -496,7 +508,7 @@ +@@ -496,11 +508,11 @@ int k = MathHelper.func_76128_c(this.field_70161_v); BlockPos blockpos = new BlockPos(i, j, k); BlockState blockstate = this.field_70170_p.func_180495_p(blockpos); @@ -73,6 +73,11 @@ BlockPos blockpos1 = blockpos.func_177977_b(); BlockState blockstate1 = this.field_70170_p.func_180495_p(blockpos1); Block block = blockstate1.func_177230_c(); +- if (block.func_203417_a(BlockTags.field_219748_G) || block.func_203417_a(BlockTags.field_219757_z) || block instanceof FenceGateBlock) { ++ if (blockstate.collisionExtendsVertically(this.field_70170_p, blockpos, this)) { + blockstate = blockstate1; + blockpos = blockpos1; + } @@ -535,7 +547,7 @@ this.field_70140_Q = (float)((double)this.field_70140_Q + (double)MathHelper.func_76133_a(func_213296_b(vec3d)) * 0.6D); diff --git a/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch b/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch index 7d2b04287..c6565c5e5 100644 --- a/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch +++ b/patches/minecraft/net/minecraft/entity/player/ServerPlayerEntity.java.patch @@ -64,7 +64,7 @@ return this; } } -@@ -776,7 +778,7 @@ +@@ -776,11 +778,11 @@ BlockPos blockpos = new BlockPos(i, j, k); if (this.field_70170_p.func_175667_e(blockpos)) { BlockState blockstate = this.field_70170_p.func_180495_p(blockpos); @@ -73,6 +73,11 @@ BlockPos blockpos1 = blockpos.func_177977_b(); BlockState blockstate1 = this.field_70170_p.func_180495_p(blockpos1); Block block = blockstate1.func_177230_c(); +- if (block.func_203417_a(BlockTags.field_219748_G) || block.func_203417_a(BlockTags.field_219757_z) || block instanceof FenceGateBlock) { ++ if (blockstate.collisionExtendsVertically(this.field_70170_p, blockpos, this)) { + blockpos = blockpos1; + blockstate = blockstate1; + } @@ -819,6 +821,7 @@ this.field_71135_a.func_147359_a(new SOpenWindowPacket(container.field_75152_c, container.func_216957_a(), p_213829_1_.func_145748_c_())); container.func_75132_a(this); diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java b/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java index 3d0eee135..85d90fb37 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java @@ -29,6 +29,7 @@ import javax.annotation.Nullable; import net.minecraft.block.Block; import net.minecraft.block.BedBlock; import net.minecraft.block.FarmlandBlock; +import net.minecraft.block.FenceGateBlock; import net.minecraft.block.FireBlock; import net.minecraft.block.HorizontalBlock; import net.minecraft.block.IBeaconBeamColorProvider; @@ -1024,4 +1025,13 @@ public interface IForgeBlock world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3); getBlock().onExplosionDestroy(world, pos, explosion); } + + /** + * Determines if this block's collision box should be treated as though it can extend above its block space. + * Use this to replicate fence and wall behavior. + */ + default boolean collisionExtendsVertically(BlockState state, IBlockReader world, BlockPos pos, Entity collidingEntity) + { + return getBlock().isIn(BlockTags.FENCES) || getBlock().isIn(BlockTags.WALLS) || getBlock() instanceof FenceGateBlock; + } } diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeBlockState.java b/src/main/java/net/minecraftforge/common/extensions/IForgeBlockState.java index 80337d423..5741a7738 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeBlockState.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeBlockState.java @@ -867,4 +867,13 @@ public interface IForgeBlockState { getBlockState().getBlock().onBlockExploded(getBlockState(), world, pos, explosion); } + + /** + * Determines if this block's collision box should be treated as though it can extend above its block space. + * This can be used to replicate fence and wall behavior. + */ + default boolean collisionExtendsVertically(IBlockReader world, BlockPos pos, Entity collidingEntity) + { + return getBlockState().getBlock().collisionExtendsVertically(getBlockState(), world, pos, collidingEntity); + } }