Skip to content

Commit

Permalink
Fixed boat not taking care of block-liquid hooks (#5086)
Browse files Browse the repository at this point in the history
  • Loading branch information
CreativeMD authored and tterrag1098 committed Apr 11, 2019
1 parent 1752e57 commit 6162f43
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
14 changes: 14 additions & 0 deletions patches/minecraft/net/minecraft/block/Block.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,20 @@
+ {
+ return null;
+ }
+
+ /**
+ * Called when entities are swimming in the given liquid and returns the relative height (used by {@link net.minecraft.entity.item.EntityBoat})
+ *
+ * @param world world that is being tested.
+ * @param pos block thats being tested.
+ * @param state state at world/pos
+ * @param material liquid thats being tested.
+ * @return relative height of the given liquid (material), a value between 0 and 1
+ */
+ public float getBlockLiquidHeight(World world, BlockPos pos, IBlockState state, Material material)
+ {
+ return 0;
+ }
+
+ /**
+ * Queries if this block should render in a given layer.
Expand Down
12 changes: 11 additions & 1 deletion patches/minecraft/net/minecraft/block/BlockLiquid.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
this.func_180688_d(p_176365_1_, p_176365_2_);
return true;
}
@@ -452,4 +452,29 @@
@@ -448,8 +448,39 @@
return (float)p_190972_2_.func_177956_o() + func_190973_f(p_190972_0_, p_190972_1_, p_190972_2_);
}

+ @Override
+ public float getBlockLiquidHeight(World world, BlockPos pos, IBlockState state, Material material)
+ {
+ return BlockLiquid.func_190973_f(state, world, pos);
+ }
+
public BlockFaceShape func_193383_a(IBlockAccess p_193383_1_, IBlockState p_193383_2_, BlockPos p_193383_3_, EnumFacing p_193383_4_)
{
return BlockFaceShape.UNDEFINED;
}
Expand Down
52 changes: 50 additions & 2 deletions patches/minecraft/net/minecraft/entity/item/EntityBoat.java.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
--- ../src-base/minecraft/net/minecraft/entity/item/EntityBoat.java
+++ ../src-work/minecraft/net/minecraft/entity/item/EntityBoat.java
@@ -508,7 +508,7 @@
@@ -449,6 +449,12 @@
blockpos$pooledmutableblockpos.func_181079_c(l1, k1, i2);
IBlockState iblockstate = this.field_70170_p.func_180495_p(blockpos$pooledmutableblockpos);

+ Boolean result = iblockstate.func_177230_c().isAABBInsideMaterial(field_70170_p, blockpos$pooledmutableblockpos, new AxisAlignedBB(blockpos$pooledmutableblockpos), Material.field_151586_h);
+ if (result != null) {
+ if (!result) continue;
+ f = Math.max(f, iblockstate.func_177230_c().getBlockLiquidHeight(field_70170_p, blockpos$pooledmutableblockpos, iblockstate, Material.field_151586_h) + blockpos$pooledmutableblockpos.func_177956_o());
+ }
+
if (iblockstate.func_185904_a() == Material.field_151586_h)
{
f = Math.max(f, BlockLiquid.func_190973_f(iblockstate, this.field_70170_p, blockpos$pooledmutableblockpos));
@@ -508,7 +514,7 @@

if (!list.isEmpty())
{
Expand All @@ -9,7 +22,42 @@
++k1;
}

@@ -980,4 +980,20 @@
@@ -551,6 +557,15 @@
blockpos$pooledmutableblockpos.func_181079_c(k1, l1, i2);
IBlockState iblockstate = this.field_70170_p.func_180495_p(blockpos$pooledmutableblockpos);

+ Boolean result = iblockstate.func_177230_c().isAABBInsideMaterial(field_70170_p, blockpos$pooledmutableblockpos, axisalignedbb, Material.field_151586_h);
+ if (result != null) {
+ if (!result) continue;
+
+ float f = iblockstate.func_177230_c().getBlockLiquidHeight(field_70170_p, blockpos$pooledmutableblockpos, iblockstate, Material.field_151586_h) + blockpos$pooledmutableblockpos.func_177956_o();
+ this.field_184465_aD = Math.max((double)f, this.field_184465_aD);
+ flag |= axisalignedbb.field_72338_b < (double)f;
+ }
+
if (iblockstate.func_185904_a() == Material.field_151586_h)
{
float f = BlockLiquid.func_190972_g(iblockstate, this.field_70170_p, blockpos$pooledmutableblockpos);
@@ -594,6 +609,18 @@
blockpos$pooledmutableblockpos.func_181079_c(k1, l1, i2);
IBlockState iblockstate = this.field_70170_p.func_180495_p(blockpos$pooledmutableblockpos);

+ Boolean result = iblockstate.func_177230_c().isAABBInsideMaterial(field_70170_p, blockpos$pooledmutableblockpos, axisalignedbb, Material.field_151586_h);
+ if (result != null) {
+ if (!result) continue;
+
+ if(iblockstate.func_177230_c().getBlockLiquidHeight(field_70170_p, blockpos$pooledmutableblockpos, iblockstate, Material.field_151586_h) > 0)
+ {
+ blockpos$pooledmutableblockpos.func_185344_t();
+ return EntityBoat.Status.UNDER_FLOWING_WATER;
+ } else
+ continue;
+ }
+
if (iblockstate.func_185904_a() == Material.field_151586_h && d0 < (double)BlockLiquid.func_190972_g(iblockstate, this.field_70170_p, blockpos$pooledmutableblockpos))
{
if (((Integer)iblockstate.func_177229_b(BlockLiquid.field_176367_b)).intValue() != 0)
@@ -980,4 +1007,20 @@
return values()[0];
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/minecraftforge/fluids/BlockFluidBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,11 @@ private boolean isWithinFluid(IBlockAccess world, BlockPos pos, Vec3d vec)
return filled < 0 ? vec.y > pos.getY() + filled + 1
: vec.y < pos.getY() + filled;
}

@Override
public float getBlockLiquidHeight(World world, BlockPos pos, IBlockState state, Material material)
{
float filled = getFilledPercentage(world, pos);
return Math.max(filled, 0);
}
}

0 comments on commit 6162f43

Please sign in to comment.