Add collisionExtendsVertically hook to allow modded blocks that extend collision into the block above similar to fences. (#6092)

This commit is contained in:
Wire Segal 2019-09-03 17:50:27 -04:00 committed by LexManos
parent 68524ddde9
commit c09fe57031
4 changed files with 31 additions and 2 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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);
}
}