Rewrite spawn meta for all living entities on 1.10 and up

This commit is contained in:
Dan Mulloy 2017-07-18 12:33:07 -04:00
parent 5d39f7145d
commit 212858743f
2 changed files with 57 additions and 39 deletions

View File

@ -1,9 +1,16 @@
package mineplex.core.disguise.disguises;
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.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import com.mineplex.MetaWrapper;
import com.mineplex.ProtocolVersion;
import net.minecraft.server.v1_8_R3.*;
import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject;
import org.bukkit.entity.EntityType;
public abstract class DisguiseCreature extends DisguiseInsentient
{
@ -70,4 +77,46 @@ public abstract class DisguiseCreature extends DisguiseInsentient
return packet;
}
@Override
public Packet modifySpawnPacket(int protocol, Packet packet)
{
if (protocol >= ProtocolVersion.v1_10_PRE)
{
PacketPlayOutSpawnEntityLiving newSpawn = (PacketPlayOutSpawnEntityLiving) getSpawnPacket();
newSpawn.m = processSpawnMeta(protocol, DataWatcher.c());
return newSpawn;
}
return packet;
}
private List<WatchableObject> processSpawnMeta(int protocol, List<WatchableObject> list)
{
List<MetaWrapper> newMeta = new ArrayList<>();
for (WatchableObject meta : list)
{
MetaWrapper wrapper = new MetaWrapper(meta);
if (wrapper.getIndex() >= 5) // 1.10
{
wrapper.setIndex(wrapper.getIndex() + 1);
}
if (protocol < ProtocolVersion.v1_11)
{
newMeta.add(wrapper);
continue;
}
if (getEntity() instanceof EntityArmorStand && wrapper.getIndex() >= 12)
{
// Armor stand meta conflicts with a lot of entities on 1.11+
continue;
}
newMeta.add(wrapper);
}
return newMeta.stream().map(MetaWrapper::toWatchableObject).collect(Collectors.toList());
}
}

View File

@ -71,15 +71,13 @@ public class DisguiseGuardian extends DisguiseCreature
@Override
public Packet modifySpawnPacket(int protocol, Packet packet)
{
if (protocol >= ProtocolVersion.v1_11)
PacketPlayOutSpawnEntityLiving newSpawn = (PacketPlayOutSpawnEntityLiving) super.modifySpawnPacket(protocol, packet);
if (protocol >= ProtocolVersion.v1_11 && isElder())
{
PacketPlayOutSpawnEntityLiving newSpawn = (PacketPlayOutSpawnEntityLiving) getSpawnPacket();
if (isElder()) newSpawn.b = 4;
newSpawn.m = processSpawnMeta(DataWatcher.c());
return newSpawn;
newSpawn.b = 4;
}
return packet;
return newSpawn;
}
@Override
@ -113,33 +111,4 @@ public class DisguiseGuardian extends DisguiseCreature
return newMeta.stream().map(MetaWrapper::toWatchableObject).collect(Collectors.toList());
}
private List<WatchableObject> processSpawnMeta(List<WatchableObject> list)
{
List<MetaWrapper> newMeta = new ArrayList<>();
for (WatchableObject meta : list)
{
MetaWrapper wrapper = new MetaWrapper(meta);
if (wrapper.getIndex() >= 5) // 1.10
{
wrapper.setIndex(wrapper.getIndex() + 1);
}
if (getEntity() instanceof EntityArmorStand && (wrapper.getIndex() == 12 || wrapper.getIndex() == 13))
{
continue;
}
if (wrapper.getIndex() < 12) // Skip higher ones in 1.11
{
newMeta.add(wrapper);
} else if (wrapper.getIndex() == 12)
{
byte value = (byte) wrapper.getValue();
newMeta.add(new MetaWrapper(12, DataType.BOOLEAN, (value & 0x02) != 0));
}
}
return newMeta.stream().map(MetaWrapper::toWatchableObject).collect(Collectors.toList());
}
}