NoCheatPlus/NCPCompatNonFree/NCPCompatCBDev/src/main/java/fr/neatmonster/nocheatplus/compat/cbdev/BlockCacheCBDev.java

133 lines
5.0 KiB
Java
Raw Normal View History

/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.neatmonster.nocheatplus.compat.cbdev;
import java.util.Iterator;
import java.util.List;
2017-12-18 01:14:23 +01:00
import org.bukkit.Material;
2016-06-13 17:20:14 +02:00
import org.bukkit.World;
2018-01-07 16:35:44 +01:00
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
2016-06-13 17:20:14 +02:00
import org.bukkit.entity.Entity;
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
2018-01-07 16:35:44 +01:00
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.EntityBoat;
import net.minecraft.server.v1_12_R1.EntityShulker;
2017-12-18 01:14:23 +01:00
public class BlockCacheCBDev extends BlockCache {
2014-08-04 18:38:45 +02:00
2018-01-07 16:35:44 +01:00
protected net.minecraft.server.v1_12_R1.World world;
protected World bukkitWorld;
2014-08-04 18:38:45 +02:00
public BlockCacheCBDev(World world) {
setAccess(world);
}
@Override
public BlockCache setAccess(World world) {
2014-08-04 18:38:45 +02:00
if (world != null) {
this.maxBlockY = world.getMaxHeight() - 1;
this.world = ((CraftWorld) world).getHandle();
this.bukkitWorld = world;
2014-08-04 18:38:45 +02:00
} else {
this.world = null;
this.bukkitWorld = null;
2014-08-04 18:38:45 +02:00
}
return this;
2014-08-04 18:38:45 +02:00
}
@Override
2017-12-18 01:14:23 +01:00
public Material fetchTypeId(final int x, final int y, final int z) {
return bukkitWorld.getBlockAt(x, y, z).getType();
2014-08-04 18:38:45 +02:00
}
@SuppressWarnings("deprecation")
2014-08-04 18:38:45 +02:00
@Override
public int fetchData(final int x, final int y, final int z) {
return bukkitWorld.getBlockAt(x, y, z).getData();
2014-08-04 18:38:45 +02:00
}
@Override
public double[] fetchBounds(final int x, final int y, final int z){
final Material id = getType(x, y, z);
2017-12-18 01:14:23 +01:00
@SuppressWarnings("deprecation")
2018-01-07 16:35:44 +01:00
final net.minecraft.server.v1_12_R1.Block block = net.minecraft.server.v1_12_R1.Block.getById(id.getId());
2014-08-04 18:38:45 +02:00
if (block == null) {
// TODO: Convention for null blocks -> full ?
2014-08-04 18:38:45 +02:00
return null;
}
final BlockPosition pos = new BlockPosition(x, y, z);
// TODO: Deprecation warning below (reason / substitute?).
2016-06-01 21:30:50 +02:00
@SuppressWarnings("deprecation")
final AxisAlignedBB bb = block.b(world.getType(pos), world, pos);
if (bb == null) {
return new double[] {0.0, 0.0, 0.0, 1.0, 1.0, 1.0}; // Special case.
//return null;
}
2014-08-04 18:38:45 +02:00
// minX, minY, minZ, maxX, maxY, maxZ
return new double[]{bb.a, bb.b, bb.c, bb.d, bb.e, bb.f};
2014-08-04 18:38:45 +02:00
}
@Override
public boolean standsOnEntity(final Entity entity, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ){
try{
// TODO: Find some simplification!
2018-01-07 16:35:44 +01:00
final net.minecraft.server.v1_12_R1.Entity mcEntity = ((CraftEntity) entity).getHandle();
2014-08-04 18:38:45 +02:00
final AxisAlignedBB box = new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ);
2014-08-04 18:38:45 +02:00
@SuppressWarnings("rawtypes")
final List list = world.getEntities(mcEntity, box);
@SuppressWarnings("rawtypes")
final Iterator iterator = list.iterator();
while (iterator.hasNext()) {
2018-01-07 16:35:44 +01:00
final net.minecraft.server.v1_12_R1.Entity other = (net.minecraft.server.v1_12_R1.Entity) iterator.next();
if (mcEntity == other || !(other instanceof EntityBoat) && !(other instanceof EntityShulker)) { // && !(other instanceof EntityMinecart)) continue;
2014-08-04 18:38:45 +02:00
continue;
}
if (minY >= other.locY && minY - other.locY <= 0.7){
return true;
}
// Still check this for some reason.
final AxisAlignedBB otherBox = other.getBoundingBox();
2014-08-04 18:38:45 +02:00
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 {
return true;
}
}
}
catch (Throwable t){
// Ignore exceptions (Context: DisguiseCraft).
}
return false;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.utilities.BlockCache#cleanup()
*/
@Override
public void cleanup() {
super.cleanup();
world = null;
bukkitWorld = null;
}
}