Add some safe guards for MC API access.

This commit is contained in:
asofold 2012-11-16 17:37:31 +01:00
parent 9ad981d22a
commit 61ab8c124a
2 changed files with 31 additions and 18 deletions

View File

@ -884,12 +884,20 @@ public class BlockProperties {
/**
* Hiding the API access here.<br>
* TODO: Find description of this and use block properties from here, as well as a speaking method name.
* TODO: Find description of this and use block properties from here, as well as a speaking method name.<br>
* Assumption: This is something like "can stand on this type of block".
* @param id
* @return
*/
public static final boolean i(final int id) {
return Block.i(id);
// TODO: Replace by independent method.
try{
return Block.i(id);
}
catch(Throwable t){
// Minecraft default value.
return true;
}
}
public static final long getBLockFlags(final int id){

View File

@ -331,24 +331,29 @@ public class PlayerLocation {
final double d0 = 0; //0.001D;
onGround = BlockProperties.isOnGround(getBlockAccess(), minX - d0, minY - yOnGround, minZ - d0, maxX + d0, minY + 0.25, maxZ + d0);
if (!onGround) {
// TODO: Probably check other ids too before doing this ?
final double d1 = 0.25D;
final AxisAlignedBB box = useBox.b(minX - d1, minY - getyOnGround() - d1, minZ - d1, maxX + d1, minY + 0.25 + d1, maxZ + d1);
@SuppressWarnings("rawtypes")
final List list = worldServer.getEntities(entityPlayer, box);
@SuppressWarnings("rawtypes")
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
final Entity entity = (Entity) iterator.next();
final EntityType type = entity.getBukkitEntity().getType();
if (type != EntityType.BOAT && type != EntityType.MINECART) continue;
final AxisAlignedBB otherBox = entity.boundingBox;
if (box.a > otherBox.d || box.d < otherBox.a || box.b > otherBox.e || box.e < otherBox.b || box.c > otherBox.f || box.f < otherBox.c) continue;
else {
onGround = true;
break;
try{
// TODO: Probably check other ids too before doing this ?
final double d1 = 0.25D;
final AxisAlignedBB box = useBox.b(minX - d1, minY - getyOnGround() - d1, minZ - d1, maxX + d1, minY + 0.25 + d1, maxZ + d1);
@SuppressWarnings("rawtypes")
final List list = worldServer.getEntities(entityPlayer, box);
@SuppressWarnings("rawtypes")
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
final Entity entity = (Entity) iterator.next();
final EntityType type = entity.getBukkitEntity().getType();
if (type != EntityType.BOAT && type != EntityType.MINECART) continue;
final AxisAlignedBB otherBox = entity.boundingBox;
if (box.a > otherBox.d || box.d < otherBox.a || box.b > otherBox.e || box.e < otherBox.b || box.c > otherBox.f || box.f < otherBox.c) continue;
else {
onGround = true;
break;
}
}
}
catch (Throwable t){
// Ignore exceptions (Context: DisguiseCraft).
}
}
}
return onGround;