Rewrite spawn meta for all living entities on 1.10 and up
This commit is contained in:
parent
7836e0aaaa
commit
2c997935c9
@ -1,9 +1,16 @@
|
|||||||
package mineplex.core.disguise.disguises;
|
package mineplex.core.disguise.disguises;
|
||||||
|
|
||||||
import net.minecraft.server.v1_8_R3.MathHelper;
|
import java.util.ArrayList;
|
||||||
import net.minecraft.server.v1_8_R3.Packet;
|
import java.util.List;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
|
import java.util.stream.Collectors;
|
||||||
import org.bukkit.entity.*;
|
|
||||||
|
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
|
public abstract class DisguiseCreature extends DisguiseInsentient
|
||||||
{
|
{
|
||||||
@ -70,4 +77,46 @@ public abstract class DisguiseCreature extends DisguiseInsentient
|
|||||||
|
|
||||||
return packet;
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,15 +71,13 @@ public class DisguiseGuardian extends DisguiseCreature
|
|||||||
@Override
|
@Override
|
||||||
public Packet modifySpawnPacket(int protocol, Packet packet)
|
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();
|
newSpawn.b = 4;
|
||||||
if (isElder()) newSpawn.b = 4;
|
|
||||||
newSpawn.m = processSpawnMeta(DataWatcher.c());
|
|
||||||
return newSpawn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return packet;
|
return newSpawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -113,33 +111,4 @@ public class DisguiseGuardian extends DisguiseCreature
|
|||||||
|
|
||||||
return newMeta.stream().map(MetaWrapper::toWatchableObject).collect(Collectors.toList());
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user