mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-07-01 00:54:56 +02:00
Overhauled entity serialization system.
This commit is contained in:
parent
1fe93aa1ab
commit
51b7896f02
|
@ -5,6 +5,8 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.nms.NmsManager;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.utils.Compression;
|
||||
|
@ -30,10 +32,7 @@ import java.io.FileInputStream;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -185,11 +184,22 @@ public final class StructureUtil {
|
|||
}.getType())) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> {
|
||||
try {
|
||||
if (entityDataList.getSerializedNBT() != null) {
|
||||
org.bukkit.Location blockRotationLocation = LocationUtil.rotateLocation(new org.bukkit.Location(location.getWorld(), entityDataList.getX(), entityDataList.getY(), entityDataList.getZ()), type);
|
||||
org.bukkit.Location blockLocation = new org.bukkit.Location(location.getWorld(), location.getX() - Math.abs(Integer.parseInt(storage.getOriginLocation().split(":")[0])),
|
||||
location.getY() - Integer.parseInt(storage.getOriginLocation().split(":")[1]), location.getZ() + Math.abs(Integer.parseInt(storage.getOriginLocation().split(":")[2])));
|
||||
blockLocation.add(blockRotationLocation);
|
||||
NBTEntity nbtEntity = NmsManager.getNbt().newEntity();
|
||||
nbtEntity.deSerialize(entityDataList.getSerializedNBT());
|
||||
nbtEntity.set("UUID", UUID.randomUUID());
|
||||
nbtEntity.spawn(blockLocation);
|
||||
} else {
|
||||
org.bukkit.Location blockRotationLocation = LocationUtil.rotateLocation(new org.bukkit.Location(location.getWorld(), entityDataList.getX(), entityDataList.getY(), entityDataList.getZ()), type);
|
||||
org.bukkit.Location blockLocation = new org.bukkit.Location(location.getWorld(), location.getX() - Math.abs(Integer.parseInt(storage.getOriginLocation().split(":")[0])),
|
||||
location.getY() - Integer.parseInt(storage.getOriginLocation().split(":")[1]), location.getZ() + Math.abs(Integer.parseInt(storage.getOriginLocation().split(":")[2])));
|
||||
blockLocation.add(blockRotationLocation);
|
||||
EntityUtil.convertEntityDataToEntity(entityDataList, blockLocation, type);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SkyBlock.getInstance().getLogger().warning("Unable to convert EntityData to Entity for type {" + entityDataList.getEntityType() + "} in structure {" + structure.getStructureFile() + "}");
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.songoda.skyblock.utils.world.entity;
|
|||
|
||||
public class EntityData {
|
||||
|
||||
private byte[] serializedNBT;
|
||||
|
||||
private String entityType;
|
||||
private String hand;
|
||||
private String helmet;
|
||||
|
@ -71,6 +73,7 @@ public class EntityData {
|
|||
private boolean ai;
|
||||
private boolean baby;
|
||||
|
||||
@Deprecated
|
||||
public EntityData(String entityType, double x, double y, double z, String customName, boolean customNameVisible,
|
||||
int fireTicks, int ticksLived) {
|
||||
this.entityType = entityType;
|
||||
|
@ -88,226 +91,297 @@ public class EntityData {
|
|||
this.ai = true;
|
||||
}
|
||||
|
||||
public EntityData(byte[] serializedNBT, double x, double y, double z) {
|
||||
this.serializedNBT = serializedNBT;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public byte[] getSerializedNBT() {
|
||||
return serializedNBT;
|
||||
}
|
||||
|
||||
public void setSerializedNBT(byte[] serializedNBT) {
|
||||
this.serializedNBT = serializedNBT;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setEntityType(String entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getHand() {
|
||||
return this.hand;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setHand(String hand) {
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getHelmet() {
|
||||
return this.helmet;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setHelmet(String helmet) {
|
||||
this.helmet = helmet;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getChestplate() {
|
||||
return this.chestplate;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setChestplate(String chestplate) {
|
||||
this.chestplate = chestplate;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getLeggings() {
|
||||
return this.leggings;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setLeggings(String leggings) {
|
||||
this.leggings = leggings;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getBoots() {
|
||||
return this.boots;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBoots(String boots) {
|
||||
this.boots = boots;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getBodyPose() {
|
||||
return this.bodyPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBodyPose(String bodyPose) {
|
||||
this.bodyPose = bodyPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getHeadPose() {
|
||||
return this.headPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setHeadPose(String headPose) {
|
||||
this.headPose = headPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getLeftArmPose() {
|
||||
return this.leftArmPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setLeftArmPose(String leftArmPose) {
|
||||
this.leftArmPose = leftArmPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getLeftLegPose() {
|
||||
return this.leftLegPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setLeftLegPose(String leftLegPose) {
|
||||
this.leftLegPose = leftLegPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getRightArmPose() {
|
||||
return this.rightArmPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setRightArmPose(String rightArmPose) {
|
||||
this.rightArmPose = rightArmPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getRightLegPose() {
|
||||
return this.rightLegPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setRightLegPose(String rightLegPose) {
|
||||
this.rightLegPose = rightLegPose;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getOffHand() {
|
||||
return this.offHand;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setOffHand(String offHand) {
|
||||
this.offHand = offHand;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getWoodType() {
|
||||
return this.woodType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setWoodType(String woodType) {
|
||||
this.woodType = woodType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getCarryBlock() {
|
||||
return this.carryBlock;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setCarryBlock(String carryBlock) {
|
||||
this.carryBlock = carryBlock;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getCustomName() {
|
||||
return this.customName;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setCustomName(String customName) {
|
||||
this.customName = customName;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getHorseColor() {
|
||||
return this.horseColor;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setHorseColor(String horseColor) {
|
||||
this.horseColor = horseColor;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getHorseStyle() {
|
||||
return this.horseStyle;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setHorseStyle(String horseStyle) {
|
||||
this.horseStyle = horseStyle;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getItem() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setItem(String item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getRotate() {
|
||||
return this.rotate;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setRotate(String rotate) {
|
||||
this.rotate = rotate;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getLlamaColor() {
|
||||
return this.llamaColor;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setLlamaColor(String llamaColor) {
|
||||
this.llamaColor = llamaColor;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getOcelotType() {
|
||||
return this.ocelotType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setOcelotType(String ocelotType) {
|
||||
this.ocelotType = ocelotType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getArt() {
|
||||
return this.art;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setArt(String art) {
|
||||
this.art = art;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getParrotVariant() {
|
||||
return this.parrotVariant;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setParrotVariant(String parrotVariant) {
|
||||
this.parrotVariant = parrotVariant;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getRabbitType() {
|
||||
return this.rabbitType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setRabbitType(String rabbitType) {
|
||||
this.rabbitType = rabbitType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getProfession() {
|
||||
return this.profession;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setProfession(String profession) {
|
||||
this.profession = profession;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String[] getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setInventory(String[] inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
@ -336,258 +410,322 @@ public class EntityData {
|
|||
this.z = z;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public float getHandChance() {
|
||||
return this.handChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setHandChance(float handChance) {
|
||||
this.handChance = handChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public float getOffHandChance() {
|
||||
return this.offHandChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setOffHandChange(float offHandChange) {
|
||||
this.offHandChance = offHandChange;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public float getHelmetChance() {
|
||||
return this.helmetChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setHelmetChance(float helmetChance) {
|
||||
this.helmetChance = helmetChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public float getChestplateChance() {
|
||||
return this.chestplateChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setChestplateChance(float chestplateChance) {
|
||||
this.chestplateChance = chestplateChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public float getLeggingsChance() {
|
||||
return this.leggingsChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setLeggingsChance(float leggingsChance) {
|
||||
this.leggingsChance = leggingsChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public float getBootsChance() {
|
||||
return this.bootsChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBootsChance(float bootsChance) {
|
||||
this.bootsChance = bootsChance;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public float getYaw() {
|
||||
return this.yaw;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public float getPitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getFireTicks() {
|
||||
return this.fireTicks;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setFireTicks(int fireTicks) {
|
||||
this.fireTicks = fireTicks;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getTicksLived() {
|
||||
return this.ticksLived;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setTicksLived(int ticksLived) {
|
||||
this.ticksLived = ticksLived;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getLlamaStrength() {
|
||||
return this.llamaStrength;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setLlamaStrength(int llamaStrength) {
|
||||
this.llamaStrength = llamaStrength;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getAngerLevel() {
|
||||
return this.angerLevel;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setAngerLevel(int angerLevel) {
|
||||
this.angerLevel = angerLevel;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getSlimeSize() {
|
||||
return this.slimeSize;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setSlimeSize(int slimeSize) {
|
||||
this.slimeSize = slimeSize;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getAge() {
|
||||
return this.age;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean hasArms() {
|
||||
return this.arms;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setArms(boolean arms) {
|
||||
this.arms = arms;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean hasBasePlate() {
|
||||
return this.basePlate;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBasePlate(boolean basePlate) {
|
||||
this.basePlate = basePlate;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isVisible() {
|
||||
return this.visible;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isSmall() {
|
||||
return this.small;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setSmall(boolean small) {
|
||||
this.small = small;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isMarker() {
|
||||
return this.marker;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setMarker(boolean marker) {
|
||||
this.marker = marker;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isAwake() {
|
||||
return this.awake;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setAwake(boolean awake) {
|
||||
this.awake = awake;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isPowered() {
|
||||
return this.powered;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setPowered(boolean powered) {
|
||||
this.powered = powered;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isCustomNameVisible() {
|
||||
return this.customNameVisible;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setCustomNameVisible(boolean customNameVisible) {
|
||||
this.customNameVisible = customNameVisible;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isCreatedByPlayer() {
|
||||
return this.createdByPlayer;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setCreatedByPlayer(boolean createdByPlayer) {
|
||||
this.createdByPlayer = createdByPlayer;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean hasSaddle() {
|
||||
return this.saddle;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setSaddle(boolean saddle) {
|
||||
this.saddle = saddle;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isAngry() {
|
||||
return this.angry;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setAngry(boolean angry) {
|
||||
this.angry = angry;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isSheared() {
|
||||
return this.sheared;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setSheared(boolean sheared) {
|
||||
this.sheared = sheared;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isDerp() {
|
||||
return this.derp;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setDerp(boolean derp) {
|
||||
this.derp = derp;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isAgeLock() {
|
||||
return this.ageLock;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setAgeLock(boolean ageLock) {
|
||||
this.ageLock = ageLock;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean canBreed() {
|
||||
return this.breed;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBreed(boolean breed) {
|
||||
this.breed = breed;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean hasAI() {
|
||||
return this.ai;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setAI(boolean ai) {
|
||||
this.ai = ai;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isBaby() {
|
||||
return this.baby;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setBaby(boolean baby) {
|
||||
this.baby = baby;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.songoda.skyblock.utils.world.entity;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.nms.NmsManager;
|
||||
import com.songoda.core.nms.nbt.NBTEntity;
|
||||
import com.songoda.skyblock.utils.item.ItemStackUtil;
|
||||
import com.songoda.skyblock.utils.version.NMSUtil;
|
||||
import com.songoda.skyblock.utils.world.block.BlockDegreesType;
|
||||
|
@ -22,241 +24,7 @@ import java.util.List;
|
|||
public final class EntityUtil {
|
||||
|
||||
public static EntityData convertEntityToEntityData(Entity entity, int x, int y, int z) {
|
||||
EntityData entityData = new EntityData(entity.getType().toString(), x, y, z, entity.getCustomName(),
|
||||
entity.isCustomNameVisible(), entity.getFireTicks(), entity.getTicksLived());
|
||||
entityData.setVersion(NMSUtil.getVersionNumber());
|
||||
|
||||
if (entity instanceof ArmorStand) {
|
||||
ArmorStand armorStand = (ArmorStand) entity;
|
||||
entityData.setArms(armorStand.hasArms());
|
||||
|
||||
if (armorStand.getItemInHand() != null && armorStand.getItemInHand().getType() != Material.AIR) {
|
||||
entityData.setHand(ItemStackUtil.serializeItemStack(armorStand.getItemInHand()));
|
||||
}
|
||||
|
||||
if (armorStand.getHelmet() != null && armorStand.getHelmet().getType() != Material.AIR) {
|
||||
entityData.setHelmet(ItemStackUtil.serializeItemStack(armorStand.getHelmet()));
|
||||
}
|
||||
|
||||
if (armorStand.getChestplate() != null && armorStand.getChestplate().getType() != Material.AIR) {
|
||||
entityData.setChestplate(ItemStackUtil.serializeItemStack(armorStand.getChestplate()));
|
||||
}
|
||||
|
||||
if (armorStand.getLeggings() != null && armorStand.getLeggings().getType() != Material.AIR) {
|
||||
entityData.setLeggings(ItemStackUtil.serializeItemStack(armorStand.getLeggings()));
|
||||
}
|
||||
|
||||
if (armorStand.getBoots() != null && armorStand.getBoots().getType() != Material.AIR) {
|
||||
entityData.setBoots(ItemStackUtil.serializeItemStack(armorStand.getBoots()));
|
||||
}
|
||||
|
||||
entityData.setBasePlate(armorStand.hasBasePlate());
|
||||
entityData.setVisible(armorStand.isVisible());
|
||||
entityData.setSmall(armorStand.isSmall());
|
||||
entityData.setMarker(armorStand.isMarker());
|
||||
entityData.setBodyPose(armorStand.getBodyPose().getX() + " " + armorStand.getBodyPose().getY() + " "
|
||||
+ armorStand.getBodyPose().getZ());
|
||||
entityData.setHeadPose(armorStand.getHeadPose().getX() + " " + armorStand.getHeadPose().getY() + " "
|
||||
+ armorStand.getHeadPose().getZ());
|
||||
entityData.setLeftArmPose(armorStand.getLeftArmPose().getX() + " " + armorStand.getLeftArmPose().getY()
|
||||
+ " " + armorStand.getLeftArmPose().getZ());
|
||||
entityData.setLeftLegPose(armorStand.getLeftLegPose().getX() + " " + armorStand.getLeftLegPose().getY()
|
||||
+ " " + armorStand.getLeftLegPose().getZ());
|
||||
entityData.setRightArmPose(armorStand.getRightArmPose().getX() + " " + armorStand.getRightArmPose().getY()
|
||||
+ " " + armorStand.getRightArmPose().getZ());
|
||||
entityData.setRightLegPose(armorStand.getRightLegPose().getX() + " " + armorStand.getRightLegPose().getY()
|
||||
+ " " + armorStand.getRightLegPose().getZ());
|
||||
|
||||
return entityData;
|
||||
}
|
||||
|
||||
int NMSVersion = NMSUtil.getVersionNumber();
|
||||
|
||||
if (entity instanceof LivingEntity) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
EntityEquipment entityEquipment = livingEntity.getEquipment();
|
||||
|
||||
if (NMSVersion > 8) {
|
||||
if (NMSVersion > 9) {
|
||||
entityData.setAI(livingEntity.hasAI());
|
||||
}
|
||||
|
||||
if (entityEquipment.getItemInMainHand() != null
|
||||
&& entityEquipment.getItemInMainHand().getType() != Material.AIR) {
|
||||
entityData.setHand(ItemStackUtil.serializeItemStack(entityEquipment.getItemInMainHand()));
|
||||
}
|
||||
|
||||
entityData.setHandChance(entityEquipment.getItemInMainHandDropChance());
|
||||
|
||||
if (entityEquipment.getItemInOffHand() != null
|
||||
&& entityEquipment.getItemInOffHand().getType() != Material.AIR) {
|
||||
entityData.setOffHand(ItemStackUtil.serializeItemStack(entityEquipment.getItemInOffHand()));
|
||||
}
|
||||
|
||||
entityData.setOffHandChange(entityEquipment.getItemInOffHandDropChance());
|
||||
} else {
|
||||
if (entityEquipment.getItemInHand() != null
|
||||
&& entityEquipment.getItemInHand().getType() != Material.AIR) {
|
||||
entityData.setHand(ItemStackUtil.serializeItemStack(entityEquipment.getItemInHand()));
|
||||
}
|
||||
|
||||
entityData.setHandChance(entityEquipment.getItemInHandDropChance());
|
||||
}
|
||||
|
||||
if (entityEquipment.getHelmet() != null && entityEquipment.getHelmet().getType() != Material.AIR) {
|
||||
entityData.setHelmet(ItemStackUtil.serializeItemStack(entityEquipment.getHelmet()));
|
||||
}
|
||||
|
||||
if (entityEquipment.getChestplate() != null && entityEquipment.getChestplate().getType() != Material.AIR) {
|
||||
entityData.setChestplate(ItemStackUtil.serializeItemStack(entityEquipment.getChestplate()));
|
||||
}
|
||||
|
||||
if (entityEquipment.getLeggings() != null && entityEquipment.getLeggings().getType() != Material.AIR) {
|
||||
entityData.setLeggings(ItemStackUtil.serializeItemStack(entityEquipment.getLeggings()));
|
||||
}
|
||||
|
||||
if (entityEquipment.getBoots() != null && entityEquipment.getBoots().getType() != Material.AIR) {
|
||||
entityData.setBoots(ItemStackUtil.serializeItemStack(entityEquipment.getBoots()));
|
||||
}
|
||||
|
||||
entityData.setHelmetChance(entityEquipment.getHelmetDropChance());
|
||||
entityData.setChestplateChance(entityEquipment.getChestplateDropChance());
|
||||
entityData.setLeggingsChance(entityEquipment.getLeggingsDropChance());
|
||||
entityData.setBootsChance(entityEquipment.getBootsDropChance());
|
||||
|
||||
if (entity instanceof Bat) {
|
||||
entityData.setAwake(((Bat) entityData).isAwake());
|
||||
} else if (entity instanceof Creeper) {
|
||||
entityData.setPowered(((Creeper) entity).isPowered());
|
||||
} else if (entity instanceof Enderman) {
|
||||
Enderman enderman = ((Enderman) entity);
|
||||
|
||||
if (NMSVersion > 12) {
|
||||
if (enderman.getCarriedBlock() == null) {
|
||||
entityData.setCarryBlock("");
|
||||
} else {
|
||||
entityData.setCarryBlock(enderman.getCarriedBlock().getMaterial().name() + ":0");
|
||||
}
|
||||
} else {
|
||||
MaterialData materialData = enderman.getCarriedMaterial();
|
||||
|
||||
if (materialData == null) {
|
||||
entityData.setCarryBlock("");
|
||||
} else {
|
||||
entityData.setCarryBlock(materialData.getItemType().toString() + ":" + materialData.getData());
|
||||
}
|
||||
}
|
||||
} else if (entity instanceof Horse) {
|
||||
Horse horse = ((Horse) entity);
|
||||
entityData.setHorseColor(horse.getColor().toString());
|
||||
entityData.setHorseStyle(horse.getStyle().toString());
|
||||
|
||||
List<String> items = new ArrayList<>();
|
||||
|
||||
for (ItemStack itemList : horse.getInventory().getContents()) {
|
||||
if (itemList != null && itemList.getType() != Material.AIR) {
|
||||
items.add(ItemStackUtil.serializeItemStack(itemList));
|
||||
}
|
||||
}
|
||||
|
||||
entityData.setInventory(items.toArray(new String[0]));
|
||||
} else if (entity instanceof IronGolem) {
|
||||
entityData.setCreatedByPlayer(((IronGolem) entity).isPlayerCreated());
|
||||
} else if (entity instanceof Ocelot) {
|
||||
entityData.setOcelotType(((Ocelot) entity).getCatType().toString());
|
||||
} else if (entity instanceof Pig) {
|
||||
entityData.setSaddle(((Pig) entity).hasSaddle());
|
||||
} else if (entity instanceof Zombie) {
|
||||
entityData.setBaby(((Zombie) entity).isBaby());
|
||||
} else if (entity instanceof PigZombie) {
|
||||
PigZombie pigZombie = ((PigZombie) entity);
|
||||
entityData.setAngry(pigZombie.isAngry());
|
||||
entityData.setAngerLevel(pigZombie.getAnger());
|
||||
} else if (entity instanceof Rabbit) {
|
||||
entityData.setRabbitType(((Rabbit) entity).getRabbitType().toString());
|
||||
} else if (entity instanceof Sheep) {
|
||||
entityData.setSheared(((Sheep) entity).isSheared());
|
||||
entityData.setColor(((Colorable) entity).getColor().toString());
|
||||
} else if (entity instanceof Slime) {
|
||||
entityData.setSlimeSize(((Slime) entity).getSize());
|
||||
} else if (entity instanceof Snowman) {
|
||||
entityData.setDerp(((Snowman) entity).isDerp());
|
||||
} else if (entity instanceof Villager) {
|
||||
Villager villager = ((Villager) entity);
|
||||
entityData.setProfession(villager.getProfession().toString());
|
||||
|
||||
List<String> items = new ArrayList<>();
|
||||
|
||||
for (ItemStack itemList : villager.getInventory().getContents()) {
|
||||
if (itemList != null && itemList.getType() != Material.AIR) {
|
||||
items.add(ItemStackUtil.serializeItemStack(itemList));
|
||||
}
|
||||
}
|
||||
|
||||
entityData.setInventory(items.toArray(new String[0]));
|
||||
}
|
||||
|
||||
if (NMSVersion > 10) {
|
||||
if (entity instanceof Llama) {
|
||||
Llama llama = ((Llama) entity);
|
||||
entityData.setLlamaColor(llama.getColor().toString());
|
||||
entityData.setLlamaStrength(llama.getStrength());
|
||||
|
||||
List<String> items = new ArrayList<>();
|
||||
|
||||
for (ItemStack itemList : llama.getInventory().getContents()) {
|
||||
if (itemList != null && itemList.getType() != Material.AIR) {
|
||||
items.add(ItemStackUtil.serializeItemStack(itemList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NMSVersion > 11) {
|
||||
if (entity instanceof Parrot) {
|
||||
entityData.setParrotVariant(((Parrot) entity).getVariant().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof Ageable) {
|
||||
Ageable ageable = ((Ageable) entity);
|
||||
entityData.setBreed(ageable.canBreed());
|
||||
entityData.setAge(ageable.getAge());
|
||||
entityData.setAgeLock(ageable.getAgeLock());
|
||||
entityData.setBaby(!ageable.isAdult());
|
||||
} else if (entity instanceof Vehicle) {
|
||||
if (entity instanceof Boat) {
|
||||
entityData.setWoodType(((Boat) entity).getWoodType().toString());
|
||||
} else if (entity instanceof StorageMinecart || entity instanceof HopperMinecart) {
|
||||
List<String> items = new ArrayList<>();
|
||||
|
||||
for (ItemStack itemList : ((InventoryHolder) entity).getInventory().getContents()) {
|
||||
if (itemList != null && itemList.getType() != Material.AIR) {
|
||||
items.add(ItemStackUtil.serializeItemStack(itemList));
|
||||
}
|
||||
}
|
||||
|
||||
entityData.setInventory(items.toArray(new String[0]));
|
||||
}
|
||||
} else if (entity instanceof Hanging) {
|
||||
if (entity instanceof ItemFrame) {
|
||||
ItemFrame itemFrame = ((ItemFrame) entity);
|
||||
ItemStack is = itemFrame.getItem();
|
||||
|
||||
if (is == null) {
|
||||
entityData.setItem("");
|
||||
} else {
|
||||
entityData.setItem(ItemStackUtil.serializeItemStack(is));
|
||||
}
|
||||
|
||||
entityData.setRotate(itemFrame.getRotation().toString());
|
||||
} else if (entity instanceof Painting) {
|
||||
entityData.setArt(((Painting) entity).getArt().toString());
|
||||
}
|
||||
}
|
||||
|
||||
return entityData;
|
||||
return new EntityData(NmsManager.getNbt().of(entity).serialize("Attributes"), x, y, z);
|
||||
}
|
||||
|
||||
public static void convertEntityDataToEntity(EntityData entityData, Location loc, BlockDegreesType type) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user