Add a way to get and set the bounding box of disguises
This commit is contained in:
parent
06cb677446
commit
686b25d59b
@ -25,6 +25,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import org.bukkit.entity.Ageable;
|
import org.bukkit.entity.Ageable;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Zombie;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||||
@ -207,6 +208,17 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
sound.setDamageSoundVolume((Float) soundStrength);
|
sound.setDamageSoundVolume((Float) soundStrength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the bounding box
|
||||||
|
|
||||||
|
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||||
|
if (bukkitEntity instanceof Ageable) {
|
||||||
|
((Ageable) bukkitEntity).setBaby();
|
||||||
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||||
|
} else if (bukkitEntity instanceof Zombie) {
|
||||||
|
((Zombie) bukkitEntity).setBaby(true);
|
||||||
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.print("[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name()
|
System.out.print("[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name()
|
||||||
+ "!");
|
+ "!");
|
||||||
|
@ -46,6 +46,8 @@ public class DisguiseValues {
|
|||||||
private int enumEntitySize;
|
private int enumEntitySize;
|
||||||
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
|
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
|
||||||
private Class nmsEntityClass;
|
private Class nmsEntityClass;
|
||||||
|
private FakeBoundingBox adultBox;
|
||||||
|
private FakeBoundingBox babyBox;
|
||||||
|
|
||||||
public DisguiseValues(DisguiseType type, Class classType, int entitySize) {
|
public DisguiseValues(DisguiseType type, Class classType, int entitySize) {
|
||||||
values.put(type, this);
|
values.put(type, this);
|
||||||
@ -53,6 +55,22 @@ public class DisguiseValues {
|
|||||||
nmsEntityClass = classType;
|
nmsEntityClass = classType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FakeBoundingBox getBabyBox() {
|
||||||
|
return babyBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdultBox(FakeBoundingBox newBox) {
|
||||||
|
adultBox = newBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBabyBox(FakeBoundingBox newBox) {
|
||||||
|
babyBox = newBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeBoundingBox getAdultBox() {
|
||||||
|
return adultBox;
|
||||||
|
}
|
||||||
|
|
||||||
public int getEntitySize(double paramDouble) {
|
public int getEntitySize(double paramDouble) {
|
||||||
double d = paramDouble - (((int) Math.floor(paramDouble)) + 0.5D);
|
double d = paramDouble - (((int) Math.floor(paramDouble)) + 0.5D);
|
||||||
|
|
||||||
|
26
src/me/libraryaddict/disguise/utilities/FakeBoundingBox.java
Normal file
26
src/me/libraryaddict/disguise/utilities/FakeBoundingBox.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package me.libraryaddict.disguise.utilities;
|
||||||
|
|
||||||
|
public class FakeBoundingBox {
|
||||||
|
private double xMod;
|
||||||
|
private double yMod;
|
||||||
|
private double zMod;
|
||||||
|
|
||||||
|
public FakeBoundingBox(double xMod, double yMod, double zMod) {
|
||||||
|
this.xMod = xMod;
|
||||||
|
this.yMod = yMod;
|
||||||
|
this.zMod = zMod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getX() {
|
||||||
|
return xMod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getY() {
|
||||||
|
return yMod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getZ() {
|
||||||
|
return zMod;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -55,6 +55,82 @@ public class ReflectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FakeBoundingBox getBoundingBox(Entity entity) {
|
||||||
|
try {
|
||||||
|
Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity));
|
||||||
|
double x = 0, y = 0, z = 0;
|
||||||
|
int stage = 0;
|
||||||
|
for (Field field : boundingBox.getClass().getFields()) {
|
||||||
|
if (field.getType().getSimpleName().equals("Double")) {
|
||||||
|
stage++;
|
||||||
|
switch (stage) {
|
||||||
|
case 1:
|
||||||
|
x -= field.getDouble(boundingBox);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
y -= field.getDouble(boundingBox);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
z -= field.getDouble(boundingBox);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
x += field.getDouble(boundingBox);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
y += field.getDouble(boundingBox);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
z += field.getDouble(boundingBox);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Error while setting the bounding box, more doubles than I thought??");
|
||||||
|
}
|
||||||
|
return new FakeBoundingBox(x, y, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setBoundingBox(Entity entity, double newX, double newY, double newZ) {
|
||||||
|
try {
|
||||||
|
Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity));
|
||||||
|
double x = 0, y = 0, z = 0;
|
||||||
|
int stage = 0;
|
||||||
|
for (Field field : boundingBox.getClass().getFields()) {
|
||||||
|
if (field.getType().getSimpleName().equals("Double")) {
|
||||||
|
stage++;
|
||||||
|
switch (stage) {
|
||||||
|
case 1:
|
||||||
|
x = field.getDouble(boundingBox);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
y = field.getDouble(boundingBox);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
z = field.getDouble(boundingBox);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
field.setDouble(boundingBox, x);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
field.setDouble(boundingBox, y);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
field.setDouble(boundingBox, z);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Error while setting the bounding box, more doubles than I thought??");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Object createEntityInstance(String entityName) {
|
public static Object createEntityInstance(String entityName) {
|
||||||
try {
|
try {
|
||||||
Class entityClass = getNmsClass("Entity" + entityName);
|
Class entityClass = getNmsClass("Entity" + entityName);
|
||||||
|
Loading…
Reference in New Issue
Block a user