player.isOnGround() is controlled by packets from the player, meaning

players can easily fake being on the ground resulting in infinite double
jumps. player.getFallDisance() is also reset when isOnGround() returns
true, meaning we'll need to manually check if the player is on the
ground.

Outlines two opposite corners of the entities bounding box, scann all
blocks inside, check if any of them are solid and return respectively.
This commit is contained in:
xGamingDudex 2015-08-20 15:42:39 +02:00
parent 9eed03237b
commit 633cbdabe2

View File

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import net.minecraft.server.v1_7_R4.EntityBat;
import net.minecraft.server.v1_7_R4.EntityCreature;
import net.minecraft.server.v1_7_R4.EntityEnderDragon;
@ -26,7 +27,9 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftCreature;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftLivingEntity;
import org.bukkit.entity.Creature;
@ -36,8 +39,6 @@ import org.bukkit.entity.Giant;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftCreature;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
public class UtilEnt
{
@ -495,10 +496,14 @@ public class UtilEnt
public static boolean isGrounded(Entity ent)
{
if (ent instanceof CraftEntity)
return ((CraftEntity)ent).getHandle().onGround;
return UtilBlock.solid(ent.getLocation().getBlock().getRelative(BlockFace.DOWN));
AxisAlignedBB box = ((CraftEntity)ent).getHandle().boundingBox;
Location bottom_corner_1 = new Location(ent.getWorld(), box.a, ent.getLocation().getY()-0.1, box.c);
Location bottom_corner_2 = new Location(ent.getWorld(), box.d, ent.getLocation().getY()-0.1, box.f);
for(Block b : UtilBlock.getInBoundingBox(bottom_corner_1, bottom_corner_2)){
if(UtilBlock.solid(b)) return true;
}
return false;
}
public static void PlayDamageSound(LivingEntity damagee)