Water and Lava/ja: Difference between revisions
Content added Content deleted
(Created page with "== 水 ==") |
No edit summary |
||
(9 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
</div> |
|||
水/溶岩の中を動くとき、考慮されるのはスペースを押しているかどうかのみで、地面と接しているかどうかは関係しない。 |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
When moving in water or lava, the game doesn't consider whether the player is on ground or not, only if they are holding space. |
|||
</div> |
|||
液体から出る際 → 0.3の初速で上方にブースト |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
When exiting a liquid -> jump boost with 0.3 initial speed |
|||
</div> |
|||
水の当たり判定: 0.998 x 0.598 x 0.998 (1x0.6x1で各方向0.001ずつ短い) |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
Water collision: 0.998 x 0.598 x 0.998 (1x0.6x1 retracted 0.001 inwards) |
|||
</div> |
|||
溶岩の当たり判定: 0.8 x 0.6 x 0.8(1x0.6x1でY以外各方向0.1ずつ短い) |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
Lava collision: 0.8 x 0.6 x 0.8 (1x0.6x1 retracted 0.1 inward except for Y) |
|||
</div> |
|||
Line 27: | Line 17: | ||
== 水 == |
== 水 == |
||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
</div> |
|||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
</div> |
|||
プレイヤーのmotYは動き始めの最初のtickの後に-0.004になるため、threshold部分が実際には重要になる。 |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
The threshold is actually important, because the player's motY would be -0.004 after the first tick of moving. |
|||
</div> |
|||
1.8では、次tickでの速度は0.04になり、 |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
In 1.8, the player's speed on the second tick is 0.04, |
|||
</div> |
|||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
</div> |
|||
== 溶岩 == |
== 溶岩 == |
||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
</div> |
|||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
</div> |
|||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
</div> |
|||
== ソースコード == |
== ソースコード == |
||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
public boolean handleWaterMovement() |
public boolean handleWaterMovement() |
||
{ |
{ |
||
Line 79: | Line 52: | ||
this.fire = 0; |
this.fire = 0; |
||
} |
} |
||
</div> |
|||
else |
else |
||
Line 86: | Line 58: | ||
} |
} |
||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
} |
} |
||
</div> |
|||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
public boolean handleWater(AxisAlignedBB bb, Material materialIn, Entity entityIn) |
public boolean handleWater(AxisAlignedBB bb, Material materialIn, Entity entityIn) |
||
{ |
{ |
||
Line 102: | Line 71: | ||
int minZ = MathHelper.floor_double(bb.minZ); |
int minZ = MathHelper.floor_double(bb.minZ); |
||
int maxZ = MathHelper.floor_double(bb.maxZ + 1.0D); |
int maxZ = MathHelper.floor_double(bb.maxZ + 1.0D); |
||
</div> |
|||
{ |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
{ |
|||
boolean inWater = false; |
boolean inWater = false; |
||
Vec3 acceleration = new Vec3(0.0D, 0.0D, 0.0D); |
Vec3 acceleration = new Vec3(0.0D, 0.0D, 0.0D); |
||
BlockPos.MutableBlockPos blockpos = new BlockPos.MutableBlockPos(); |
BlockPos.MutableBlockPos blockpos = new BlockPos.MutableBlockPos(); |
||
</div> |
|||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
{ |
{ |
||
for (int y = minY; y < maxY; ++y) |
for (int y = minY; y < maxY; ++y) |
||
Line 121: | Line 86: | ||
IBlockState iblockstate = this.getBlockState(blockpos); |
IBlockState iblockstate = this.getBlockState(blockpos); |
||
Block block = iblockstate.getBlock(); |
Block block = iblockstate.getBlock(); |
||
</div> |
|||
if (block.getMaterial() == materialIn) |
|||
if (block.getMaterial() == materialIn) |
|||
{ |
{ |
||
double level = y + 1 -BlockLiquid.getLiquidHeightPercent(iblockstate.getValue(BlockLiquid.LEVEL)); |
double level = y + 1 -BlockLiquid.getLiquidHeightPercent(iblockstate.getValue(BlockLiquid.LEVEL)); |
||
//liquidHeightPercent(i) |
//liquidHeightPercent(i)は(i + 1) / 9.0Fを返す; |
||
</div> |
|||
if (maxY >= level) |
|||
if (maxY >= level) |
|||
{ |
{ |
||
inWater = true; |
inWater = true; |
||
Line 140: | Line 101: | ||
} |
} |
||
} |
} |
||
</div> |
|||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
{ |
{ |
||
acceleration = acceleration.normalize(); |
acceleration = acceleration.normalize(); |
||
Line 151: | Line 110: | ||
entityIn.motionZ += acceleration.zCoord * mult; |
entityIn.motionZ += acceleration.zCoord * mult; |
||
} |
} |
||
</div> |
|||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
} |
} |
||
} |
} |
||
</div> |
|||
⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
⚫ | |||
public Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion) |
public Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion) |
||
{ |
{ |
||
return motion.add(this.getFlowVector(worldIn, pos)); |
return motion.add(this.getFlowVector(worldIn, pos)); |
||
} |
} |
||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
... |
... |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
</div> |
Latest revision as of 12:40, 6 June 2022
[WIP]
基本
水/溶岩の中を動くとき、考慮されるのはスペースを押しているかどうかのみで、地面と接しているかどうかは関係しない。
液体から出る際 → 0.3の初速で上方にブースト
水の当たり判定: 0.998 x 0.598 x 0.998 (1x0.6x1で各方向0.001ずつ短い)
溶岩の当たり判定: 0.8 x 0.6 x 0.8(1x0.6x1でY以外各方向0.1ずつ短い)
水
ジャンプキーを押している場合: threshold(motY*0.8 - 0.02) + 0.04
それ以外: threshold(motY*0.8 - 0.02)
プレイヤーのmotYは動き始めの最初のtickの後に-0.004になるため、threshold部分が実際には重要になる。
1.8では、次tickでの速度は0.04になり、
TODO: X/Z移動
溶岩
ジャンプキーを押している場合: threshold(motY*0.5 - 0.02) + 0.04
それ以外: threshold(motY*0.5 - 0.02)
TODO: X/Z移動
ソースコード
水流:
/* Entity.javaから */
public boolean handleWaterMovement()
{
if (world.handleWater(this.getEntityBoundingBox().contract(0.001, 0.401, 0.001), Material.water, this))
{
this.fallDistance = 0.0F;
this.inWater = true;
this.fire = 0;
}
else
{
this.inWater = false;
}
return this.inWater;
}
/* World.javaから */
public boolean handleWater(AxisAlignedBB bb, Material materialIn, Entity entityIn)
{
int minX = MathHelper.floor_double(bb.minX);
int maxX = MathHelper.floor_double(bb.maxX + 1.0D);
int minY = MathHelper.floor_double(bb.minY);
int maxY = MathHelper.floor_double(bb.maxY + 1.0D);
int minZ = MathHelper.floor_double(bb.minZ);
int maxZ = MathHelper.floor_double(bb.maxZ + 1.0D);
{
boolean inWater = false;
Vec3 acceleration = new Vec3(0.0D, 0.0D, 0.0D);
BlockPos.MutableBlockPos blockpos = new BlockPos.MutableBlockPos();
for (int x = minX; x < maxX; ++x)
{
for (int y = minY; y < maxY; ++y)
{
for (int z = minZ; z < maxZ; ++z)
{
blockpos.mutate(x, y, z);
IBlockState iblockstate = this.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (block.getMaterial() == materialIn)
{
double level = y + 1 -BlockLiquid.getLiquidHeightPercent(iblockstate.getValue(BlockLiquid.LEVEL));
//liquidHeightPercent(i)は(i + 1) / 9.0Fを返す;
if (maxY >= level)
{
inWater = true;
acceleration = block.modifyAcceleration(this, blockpos, entityIn, acceleration);
}
}
}
}
}
if (acceleration.lengthVector() > 0.0D && entityIn.isPushedByWater())
{
acceleration = acceleration.normalize();
double mult = 0.014D;
entityIn.motionX += acceleration.xCoord * mult;
entityIn.motionY += acceleration.yCoord * mult;
entityIn.motionZ += acceleration.zCoord * mult;
}
return inWater;
}
}
/* BlockLiquid.javaから */
public Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion)
{
return motion.add(this.getFlowVector(worldIn, pos));
}
...