Treat magma cubes as slimes and slimes as creatures for disguises

Fixes crashes in 1.12
This commit is contained in:
Dan Mulloy 2017-07-23 16:14:29 -04:00
parent a4e9fb04d8
commit 99ca371204
3 changed files with 25 additions and 150 deletions

View File

@ -25,9 +25,9 @@ public abstract class DisguiseCreature extends DisguiseInsentient
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
packet.a = getEntity().getId();
packet.b = (byte) getDisguiseType().getTypeId();
packet.c = (int) MathHelper.floor(getEntity().locX*32D);
packet.d = (int) MathHelper.floor(getEntity().locY * 32.0D);
packet.e = (int) MathHelper.floor(getEntity().locZ*32D);
packet.c = MathHelper.floor(getEntity().locX * 32.0D);
packet.d = MathHelper.floor(getEntity().locY * 32.0D);
packet.e = MathHelper.floor(getEntity().locZ * 32.0D);
packet.i = (byte) ((int) (getEntity().yaw * 256.0F / 360.0F));
packet.j = (byte) ((int) (getEntity().pitch * 256.0F / 360.0F));
packet.k = (byte) ((int) (getEntity().yaw * 256.0F / 360.0F));

View File

@ -1,95 +1,15 @@
package mineplex.core.disguise.disguises;
import net.minecraft.server.v1_8_R3.EntitySlime;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
public class DisguiseMagmaCube extends DisguiseInsentient
/**
* Magma cubes are essentially identical to slimes for disguise purposes
*/
public class DisguiseMagmaCube extends DisguiseSlime
{
public DisguiseMagmaCube(org.bukkit.entity.Entity entity)
public DisguiseMagmaCube(Entity entity)
{
super(EntityType.MAGMA_CUBE, entity);
DataWatcher.a(16, new Byte((byte) 1), EntitySlime.META_SIZE, 1);
}
public void SetSize(int i)
{
DataWatcher.watch(16, new Byte((byte) i), EntitySlime.META_SIZE, i);
}
public int GetSize()
{
return DataWatcher.getByte(16);
}
public Packet getSpawnPacket()
{
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
packet.a = getEntity().getId();
packet.b = (byte) 62;
packet.c = (int) MathHelper.floor(getEntity().locX * 32D);
packet.d = (int) MathHelper.floor(getEntity().locY * 32.0D);
packet.e = (int) MathHelper.floor(getEntity().locZ * 32D);
packet.i = (byte) ((int) (getEntity().yaw * 256.0F / 360.0F));
packet.j = (byte) ((int) (getEntity().pitch * 256.0F / 360.0F));
packet.k = (byte) ((int) (getEntity().yaw * 256.0F / 360.0F));
packet.uuid = getEntity().getUniqueID();
double var2 = 3.9D;
double var4 = 0;
double var6 = 0;
double var8 = 0;
if (var4 < -var2)
{
var4 = -var2;
}
if (var6 < -var2)
{
var6 = -var2;
}
if (var8 < -var2)
{
var8 = -var2;
}
if (var4 > var2)
{
var4 = var2;
}
if (var6 > var2)
{
var6 = var2;
}
if (var8 > var2)
{
var8 = var2;
}
packet.f = (int) (var4 * 8000.0D);
packet.g = (int) (var6 * 8000.0D);
packet.h = (int) (var8 * 8000.0D);
packet.l = DataWatcher;
packet.m = DataWatcher.b();
return packet;
}
protected String getHurtSound()
{
return "mob.slime." + (GetSize() > 1 ? "big" : "small");
}
protected float getVolume()
{
return 0.4F * (float) GetSize();
}
}

View File

@ -4,14 +4,26 @@ import net.minecraft.server.v1_8_R3.EntitySlime;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
public class DisguiseSlime extends DisguiseInsentient
/**
* Slimes have an odd type hierarchy, but they're essentially creatures as far as disguises are concerned.
*/
public class DisguiseSlime extends DisguiseCreature
{
public DisguiseSlime(org.bukkit.entity.Entity entity)
public DisguiseSlime(Entity entity)
{
super(EntityType.SLIME, entity);
this(EntityType.SLIME, entity);
}
/**
* For magma cubes
*/
protected DisguiseSlime(EntityType type, Entity entity)
{
super(type, entity);
DataWatcher.a(16, new Byte((byte) 1), EntitySlime.META_SIZE, 1);
}
@ -25,63 +37,6 @@ public class DisguiseSlime extends DisguiseInsentient
return DataWatcher.getByte(16);
}
public Packet getSpawnPacket()
{
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
packet.a = getEntity().getId();
packet.b = (byte) 55;
packet.c = (int) MathHelper.floor(getEntity().locX * 32D);
packet.d = (int) MathHelper.floor(getEntity().locY * 32.0D);
packet.e = (int) MathHelper.floor(getEntity().locZ * 32D);
packet.i = (byte) ((int) (getEntity().yaw * 256.0F / 360.0F));
packet.j = (byte) ((int) (getEntity().pitch * 256.0F / 360.0F));
packet.k = (byte) ((int) (getEntity().yaw * 256.0F / 360.0F));
packet.uuid = getEntity().getUniqueID();
double var2 = 3.9D;
double var4 = 0;
double var6 = 0;
double var8 = 0;
if (var4 < -var2)
{
var4 = -var2;
}
if (var6 < -var2)
{
var6 = -var2;
}
if (var8 < -var2)
{
var8 = -var2;
}
if (var4 > var2)
{
var4 = var2;
}
if (var6 > var2)
{
var6 = var2;
}
if (var8 > var2)
{
var8 = var2;
}
packet.f = (int) (var4 * 8000.0D);
packet.g = (int) (var6 * 8000.0D);
packet.h = (int) (var8 * 8000.0D);
packet.l = DataWatcher;
packet.m = DataWatcher.b();
return packet;
}
protected String getHurtSound()
{
return "mob.slime." + (GetSize() > 1 ? "big" : "small");