[BLEEDING] Add dev-support for 1.8/Spigot.

This commit is contained in:
asofold 2014-11-29 01:55:24 +01:00
parent a9f9a3dced
commit a064a9afce
4 changed files with 63 additions and 52 deletions

View File

@ -22,7 +22,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.10-R0.1-SNAPSHOT</version>
<version>1.8-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@ -3,25 +3,25 @@ package fr.neatmonster.nocheatplus.compat.cbdev;
import java.util.Iterator;
import java.util.List;
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import net.minecraft.server.v1_7_R4.Block;
import net.minecraft.server.v1_7_R4.EntityBoat;
import net.minecraft.server.v1_7_R4.IBlockAccess;
import net.minecraft.server.v1_7_R4.TileEntity;
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
import net.minecraft.server.v1_8_R1.BlockPosition;
import net.minecraft.server.v1_8_R1.EntityBoat;
import net.minecraft.server.v1_8_R1.EnumDirection;
import net.minecraft.server.v1_8_R1.IBlockAccess;
import net.minecraft.server.v1_8_R1.IBlockData;
import net.minecraft.server.v1_8_R1.TileEntity;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import org.bukkit.entity.Entity;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
public class BlockCacheCBDev extends BlockCache implements IBlockAccess{
/** Box for one time use, no nesting, no extra storing this(!). */
protected static final AxisAlignedBB useBox = AxisAlignedBB.a(0, 0, 0, 0, 0, 0);
protected net.minecraft.server.v1_7_R4.WorldServer world;
protected net.minecraft.server.v1_8_R1.WorldServer world;
protected World bukkitWorld; // WHACKS
public BlockCacheCBDev(World world) {
setAccess(world);
@ -32,33 +32,37 @@ public class BlockCacheCBDev extends BlockCache implements IBlockAccess{
if (world != null) {
this.maxBlockY = world.getMaxHeight() - 1;
this.world = ((CraftWorld) world).getHandle();
this.bukkitWorld = world;
} else {
this.world = null;
this.bukkitWorld = null;
}
}
@SuppressWarnings("deprecation")
@Override
public int fetchTypeId(final int x, final int y, final int z) {
return world.getTypeId(x, y, z);
return bukkitWorld.getBlockTypeIdAt(x, y, z);
}
@SuppressWarnings("deprecation")
@Override
public int fetchData(final int x, final int y, final int z) {
return world.getData(x, y, z);
return bukkitWorld.getBlockAt(x, y, z).getData();
}
@Override
public double[] fetchBounds(final int x, final int y, final int z){
final int id = getTypeId(x, y, z);
final net.minecraft.server.v1_7_R4.Block block = net.minecraft.server.v1_7_R4.Block.getById(id);
final net.minecraft.server.v1_8_R1.Block block = net.minecraft.server.v1_8_R1.Block.getById(id);
if (block == null) {
// TODO: Convention for null bounds -> full ?
return null;
}
block.updateShape(this, x, y, z);
block.updateShape(this, new BlockPosition(x, y, z));
// minX, minY, minZ, maxX, maxY, maxZ
return new double[]{block.x(), block.z(), block.B(), block.y(), block.A(), block.C()};
return new double[]{block.z(), block.B(), block.D(), block.A(), block.C(), block.E()};
}
@Override
@ -66,15 +70,15 @@ public class BlockCacheCBDev extends BlockCache implements IBlockAccess{
try{
// TODO: Find some simplification!
final net.minecraft.server.v1_7_R4.Entity mcEntity = ((CraftEntity) entity).getHandle();
final net.minecraft.server.v1_8_R1.Entity mcEntity = ((CraftEntity) entity).getHandle();
final AxisAlignedBB box = useBox.b(minX, minY, minZ, maxX, maxY, maxZ);
final AxisAlignedBB box = new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ);
@SuppressWarnings("rawtypes")
final List list = world.getEntities(mcEntity, box);
@SuppressWarnings("rawtypes")
final Iterator iterator = list.iterator();
while (iterator.hasNext()) {
final net.minecraft.server.v1_7_R4.Entity other = (net.minecraft.server.v1_7_R4.Entity) iterator.next();
final net.minecraft.server.v1_8_R1.Entity other = (net.minecraft.server.v1_8_R1.Entity) iterator.next();
if (!(other instanceof EntityBoat)){ // && !(other instanceof EntityMinecart)) continue;
continue;
}
@ -82,7 +86,7 @@ public class BlockCacheCBDev extends BlockCache implements IBlockAccess{
return true;
}
// Still check this for some reason.
final AxisAlignedBB otherBox = other.boundingBox;
final AxisAlignedBB otherBox = other.getBoundingBox();
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;
}
@ -104,21 +108,27 @@ public class BlockCacheCBDev extends BlockCache implements IBlockAccess{
public void cleanup() {
super.cleanup();
world = null;
bukkitWorld = null;
}
@Override
public TileEntity getTileEntity(final int x, final int y, final int z) {
return world.getTileEntity(x, y, z);
public int getBlockPower(BlockPosition pos, EnumDirection dir) {
return world.getBlockPower(pos, dir);
}
@Override
public int getBlockPower(final int arg0, final int arg1, final int arg2, final int arg3) {
return world.getBlockPower(arg0, arg1, arg2, arg3);
public TileEntity getTileEntity(BlockPosition pos) {
return world.getTileEntity(pos);
}
@Override
public Block getType(int x, int y, int z) {
return world.getType(x, y, z);
public IBlockData getType(BlockPosition pos) {
return world.getType(pos);
}
@Override
public boolean isEmpty(BlockPosition pos) {
return world.isEmpty(pos);
}
}

View File

@ -1,19 +1,19 @@
package fr.neatmonster.nocheatplus.compat.cbdev;
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import net.minecraft.server.v1_7_R4.Block;
import net.minecraft.server.v1_7_R4.DamageSource;
import net.minecraft.server.v1_7_R4.EntityComplexPart;
import net.minecraft.server.v1_7_R4.EntityPlayer;
import net.minecraft.server.v1_7_R4.MobEffectList;
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
import net.minecraft.server.v1_8_R1.Block;
import net.minecraft.server.v1_8_R1.DamageSource;
import net.minecraft.server.v1_8_R1.EntityComplexPart;
import net.minecraft.server.v1_8_R1.EntityPlayer;
import net.minecraft.server.v1_8_R1.MobEffectList;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.CommandMap;
import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -30,22 +30,22 @@ public class MCAccessCBDev implements MCAccess{
*/
public MCAccessCBDev() {
getCommandMap();
ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R4.", new String[] {"Entity" , "dead"});
ReflectionUtil.checkMembers("net.minecraft.server.v1_8_R1.", new String[] {"Entity" , "dead"});
// block bounds, original: minX, maxX, minY, maxY, minZ, maxZ
ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R4.Block.class,
new String[]{"x", "y", "z", "A", "B", "C"}, double.class);
ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_8_R1.Block.class,
new String[]{"z", "A", "B", "C", "D", "E"}, double.class);
// TODO: Nail it down further.
}
@Override
public String getMCVersion() {
// 1_7_R4
return "1.7.10";
// 1_8_R1
return "1.8";
}
@Override
public String getServerVersionTag() {
return "CB3100-DEV";
return "Spigot-CB-1.8-DEV";
}
@Override
@ -60,8 +60,9 @@ public class MCAccessCBDev implements MCAccess{
@Override
public double getHeight(final Entity entity) {
final net.minecraft.server.v1_7_R4.Entity mcEntity = ((CraftEntity) entity).getHandle();
final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b));
final net.minecraft.server.v1_8_R1.Entity mcEntity = ((CraftEntity) entity).getHandle();
AxisAlignedBB boundingBox = mcEntity.getBoundingBox();
final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.getHeadHeight(), boundingBox.e - boundingBox.b));
if (entity instanceof LivingEntity) {
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
} else return entityHeight;
@ -101,7 +102,7 @@ public class MCAccessCBDev implements MCAccess{
return AlmostBoolean.NO;
}
// TODO: Does this need a method call for the "real" box? Might be no problem during moving events, though.
final AxisAlignedBB box = entityPlayer.boundingBox;
final AxisAlignedBB box = entityPlayer.getBoundingBox();
if (!entityPlayer.isSleeping()) {
// This can not really test stance but height of bounding box.
final double dY = Math.abs(box.e - box.b);

View File

@ -113,13 +113,13 @@ public class MCAccessFactory {
// TEMP //
// Only add as long as no stable module has been added.
// 1.7.10
// try{
// return new MCAccessCBDev();
// }
// catch(Throwable t) {
// throwables.add(t);
// };
// 1.8 (Spigot)
try{
return new fr.neatmonster.nocheatplus.compat.cbdev.MCAccessCBDev();
}
catch(Throwable t) {
throwables.add(t);
};
// TEMP END //
// 1.7.10