mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-07 03:02:11 +01:00
Move flag checking methods to BlockProperties. TypeIdCache is really
only the cache now.
This commit is contained in:
parent
4ee1880a4d
commit
0a777735e7
@ -6,6 +6,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.server.AxisAlignedBB;
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.IBlockAccess;
|
||||
|
||||
@ -917,5 +918,98 @@ public class BlockProperties {
|
||||
else blockFlags[id] |= F_IGN_PASSABLE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param box
|
||||
* @param flags Block flags (@see fr.neatmonster.nocheatplus.utilities.BlockProperties).
|
||||
* @return If any block has the flags.
|
||||
*/
|
||||
public static final boolean hasAnyFlags(final IBlockAccess access, final AxisAlignedBB box, final long flags){
|
||||
return hasAnyFlags(access, box.a, box.b, box.c, box.d, box.e, box.f, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param minX
|
||||
* @param minY
|
||||
* @param minZ
|
||||
* @param maxX
|
||||
* @param maxY
|
||||
* @param maxZ
|
||||
* @param flags Block flags (@see fr.neatmonster.nocheatplus.utilities.BlockProperties).
|
||||
* @return If any block has the flags.
|
||||
*/
|
||||
public static final boolean hasAnyFlags(final IBlockAccess access, final double minX, double minY, final double minZ, final double maxX, final double maxY, final double maxZ, final long flags){
|
||||
return hasAnyFlags(access, Location.locToBlock(minX), Location.locToBlock(minY), Location.locToBlock(minZ), Location.locToBlock(maxX), Location.locToBlock(maxY), Location.locToBlock(maxZ), flags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param minX
|
||||
* @param minY
|
||||
* @param minZ
|
||||
* @param maxX
|
||||
* @param maxY
|
||||
* @param maxZ
|
||||
* @param flags Block flags (@see fr.neatmonster.nocheatplus.utilities.BlockProperties).
|
||||
* @return If any block has the flags.
|
||||
*/
|
||||
public static final boolean hasAnyFlags(final IBlockAccess access,final int minX, int minY, final int minZ, final int maxX, final int maxY, final int maxZ, final long flags){
|
||||
for (int x = minX; x <= maxX; x++){
|
||||
for (int z = minZ; z <= maxZ; z++){
|
||||
for (int y = minY; y <= maxY; y++){
|
||||
if ((BlockProperties.getBLockFlags(access.getTypeId(x, y, z)) & flags) != 0) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the box collide with any block that matches the flags somehow.
|
||||
* @param box
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
public static final boolean collides(final IBlockAccess access, final AxisAlignedBB box, final long flags){
|
||||
return collides(access, box.a, box.b, box.c, box.d, box.e, box.f, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the box collide with any block that matches the flags somehow.
|
||||
* @param minX
|
||||
* @param minY
|
||||
* @param minZ
|
||||
* @param maxX
|
||||
* @param maxY
|
||||
* @param maxZ
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
public static final boolean collides(final IBlockAccess access, final double minX, double minY, final double minZ, final double maxX, final double maxY, final double maxZ, final long flags){
|
||||
for (int x = Location.locToBlock(minX); x <= Location.locToBlock(maxX); x++){
|
||||
for (int z = Location.locToBlock(minZ); z <= Location.locToBlock(maxZ); z++){
|
||||
for (int y = Location.locToBlock(minY); y <= Location.locToBlock(maxY); y++){
|
||||
final int id = access.getTypeId(x, y, z);
|
||||
if ((BlockProperties.getBLockFlags(id) & flags) != 0){
|
||||
// Might collide.
|
||||
final Block block = Block.byId[id];
|
||||
block.updateShape(access, x, y, z);
|
||||
if (minX > block.maxX + x || maxX < block.minX + x) continue;
|
||||
else if (minY > block.maxY + y || maxY < block.minY + y) continue;
|
||||
else if (minZ > block.maxZ + z || maxZ < block.minZ + z) continue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final boolean isOnGround(final IBlockAccess access, final double minX, double minY, final double minZ, final double maxX, final double maxY, final double maxZ){
|
||||
return collides(access, minX, minY, minZ, maxX, maxY, maxZ, F_SOLID);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -184,12 +184,7 @@ public class PlayerLocation {
|
||||
if (inLava == null) {
|
||||
AxisAlignedBB boundingBoxLava = boundingBox.clone();
|
||||
boundingBoxLava = boundingBoxLava.grow(-0.10000000149011612D, -0.40000000596046448D, -0.10000000149011612D);
|
||||
if (idCache != null){
|
||||
inLava = idCache.collides(boundingBoxLava, BlockProperties.F_LAVA);
|
||||
}
|
||||
else{
|
||||
inLava = worldServer.a(boundingBoxLava, net.minecraft.server.Material.LAVA);
|
||||
}
|
||||
inLava = BlockProperties.collides(getBlockAccess(), boundingBoxLava, BlockProperties.F_LAVA);
|
||||
}
|
||||
return inLava;
|
||||
}
|
||||
@ -204,12 +199,7 @@ public class PlayerLocation {
|
||||
AxisAlignedBB boundingBoxWater = boundingBox.clone();
|
||||
boundingBoxWater = boundingBoxWater.grow(0.0D, -0.40000000596046448D, 0.0D);
|
||||
boundingBoxWater = boundingBoxWater.shrink(0.001D, 0.001D, 0.001D);
|
||||
if (idCache !=null){
|
||||
inWater = idCache.collides(boundingBoxWater, BlockProperties.F_WATER);
|
||||
}
|
||||
else{
|
||||
inWater = worldServer.a(boundingBoxWater, net.minecraft.server.Material.WATER, entity);
|
||||
}
|
||||
inWater = BlockProperties.collides(getBlockAccess(), boundingBoxWater, BlockProperties.F_WATER);
|
||||
}
|
||||
return inWater;
|
||||
}
|
||||
@ -254,41 +244,33 @@ public class PlayerLocation {
|
||||
*/
|
||||
public boolean isOnGround() {
|
||||
if (onGround == null) {
|
||||
if (idCache != null){
|
||||
onGround = idCache.collides(boundingBox.a, boundingBox.b - yOnGround, boundingBox.c, boundingBox.d, boundingBox.e, boundingBox.f, BlockProperties.F_SOLID);
|
||||
if (!onGround){
|
||||
// TODO: Probably check other ids too before doing this ?
|
||||
// TODO: clean this up, use other checking method.
|
||||
double d0 = 0.25D;
|
||||
AxisAlignedBB axisalignedbb = boundingBox.clone();
|
||||
axisalignedbb = axisalignedbb.d(0D, -getyOnGround(), 0D);
|
||||
@SuppressWarnings("rawtypes")
|
||||
List list = worldServer.getEntities(entity, axisalignedbb.grow(d0, d0, d0));
|
||||
@SuppressWarnings("rawtypes")
|
||||
Iterator iterator = list.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Entity entity1 = (Entity) iterator.next();
|
||||
final EntityType type = entity.getBukkitEntity().getType();
|
||||
if (type != EntityType.BOAT && type != EntityType.MINECART) continue;
|
||||
AxisAlignedBB axisalignedbb1 = entity1.E();
|
||||
if (axisalignedbb1 != null && axisalignedbb1.a(axisalignedbb)) {
|
||||
onGround = true;
|
||||
return true;
|
||||
}
|
||||
axisalignedbb1 = entity.g(entity1);
|
||||
if (axisalignedbb1 != null && axisalignedbb1.a(axisalignedbb)) {
|
||||
onGround = true;
|
||||
return true;
|
||||
}
|
||||
onGround = BlockProperties.isOnGround(getBlockAccess(), boundingBox.a, boundingBox.b - yOnGround, boundingBox.c, boundingBox.d, boundingBox.e, boundingBox.f);
|
||||
if (!onGround){
|
||||
// TODO: Probably check other ids too before doing this ?
|
||||
// TODO: clean this up, use other checking method, detach it to blockproperties ?
|
||||
double d0 = 0.25D;
|
||||
AxisAlignedBB axisalignedbb = boundingBox.clone();
|
||||
axisalignedbb = axisalignedbb.d(0D, -getyOnGround(), 0D);
|
||||
@SuppressWarnings("rawtypes")
|
||||
List list = worldServer.getEntities(entity, axisalignedbb.grow(d0, d0, d0));
|
||||
@SuppressWarnings("rawtypes")
|
||||
Iterator iterator = list.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Entity entity1 = (Entity) iterator.next();
|
||||
final EntityType type = entity.getBukkitEntity().getType();
|
||||
if (type != EntityType.BOAT && type != EntityType.MINECART) continue;
|
||||
AxisAlignedBB axisalignedbb1 = entity1.E();
|
||||
if (axisalignedbb1 != null && axisalignedbb1.a(axisalignedbb)) {
|
||||
onGround = true;
|
||||
return true;
|
||||
}
|
||||
axisalignedbb1 = entity.g(entity1);
|
||||
if (axisalignedbb1 != null && axisalignedbb1.a(axisalignedbb)) {
|
||||
onGround = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
AxisAlignedBB boundingBoxGround = boundingBox.clone();
|
||||
boundingBoxGround = boundingBoxGround.d(0D, -getyOnGround(), 0D);
|
||||
onGround = worldServer.getCubes(entity, boundingBoxGround).size() > 0;
|
||||
}
|
||||
// TODO: Check for entities (boats etc.)
|
||||
}
|
||||
return onGround;
|
||||
}
|
||||
|
@ -3,13 +3,10 @@ package fr.neatmonster.nocheatplus.utilities;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.server.AxisAlignedBB;
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.IBlockAccess;
|
||||
import net.minecraft.server.Material;
|
||||
import net.minecraft.server.TileEntity;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
|
||||
@ -136,95 +133,6 @@ public class TypeIdCache implements IBlockAccess{
|
||||
dataMap.put(pos, nData);
|
||||
return nData;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param box
|
||||
* @param flags Block flags (@see fr.neatmonster.nocheatplus.utilities.BlockProperties).
|
||||
* @return If any block has the flags.
|
||||
*/
|
||||
public final boolean hasAnyFlags(final AxisAlignedBB box, final long flags){
|
||||
return hasAnyFlags(box.a, box.b, box.c, box.d, box.e, box.f, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param minX
|
||||
* @param minY
|
||||
* @param minZ
|
||||
* @param maxX
|
||||
* @param maxY
|
||||
* @param maxZ
|
||||
* @param flags Block flags (@see fr.neatmonster.nocheatplus.utilities.BlockProperties).
|
||||
* @return If any block has the flags.
|
||||
*/
|
||||
public final boolean hasAnyFlags(final double minX, double minY, final double minZ, final double maxX, final double maxY, final double maxZ, final long flags){
|
||||
return hasAnyFlags(Location.locToBlock(minX), Location.locToBlock(minY), Location.locToBlock(minZ), Location.locToBlock(maxX), Location.locToBlock(maxY), Location.locToBlock(maxZ), flags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param minX
|
||||
* @param minY
|
||||
* @param minZ
|
||||
* @param maxX
|
||||
* @param maxY
|
||||
* @param maxZ
|
||||
* @param flags Block flags (@see fr.neatmonster.nocheatplus.utilities.BlockProperties).
|
||||
* @return If any block has the flags.
|
||||
*/
|
||||
public final boolean hasAnyFlags(final int minX, int minY, final int minZ, final int maxX, final int maxY, final int maxZ, final long flags){
|
||||
for (int x = minX; x <= maxX; x++){
|
||||
for (int z = minZ; z <= maxZ; z++){
|
||||
for (int y = minY; y <= maxY; y++){
|
||||
if ((BlockProperties.getBLockFlags(getTypeId(x, y, z)) & flags) != 0) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the box collide with any block that matches the flags somehow.
|
||||
* @param box
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
public final boolean collides(final AxisAlignedBB box, final long flags){
|
||||
return collides(box.a, box.b, box.c, box.d, box.e, box.f, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the box collide with any block that matches the flags somehow.
|
||||
* @param minX
|
||||
* @param minY
|
||||
* @param minZ
|
||||
* @param maxX
|
||||
* @param maxY
|
||||
* @param maxZ
|
||||
* @param flags
|
||||
* @return
|
||||
*/
|
||||
public final boolean collides(final double minX, double minY, final double minZ, final double maxX, final double maxY, final double maxZ, final long flags){
|
||||
for (int x = Location.locToBlock(minX); x <= Location.locToBlock(maxX); x++){
|
||||
for (int z = Location.locToBlock(minZ); z <= Location.locToBlock(maxZ); z++){
|
||||
for (int y = Location.locToBlock(minY); y <= Location.locToBlock(maxY); y++){
|
||||
final int id = getTypeId(x, y, z);
|
||||
if ((BlockProperties.getBLockFlags(id) & flags) != 0){
|
||||
// Might collide.
|
||||
final Block block = Block.byId[id];
|
||||
block.updateShape(this, x, y, z);
|
||||
if (minX > block.maxX + x || maxX < block.minX + x) continue;
|
||||
else if (minY > block.maxY + y || maxY < block.minY + y) continue;
|
||||
else if (minZ > block.maxZ + z || maxZ < block.minZ + z) continue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Optimized.
|
||||
|
Loading…
Reference in New Issue
Block a user