/** * Make a clone of a {@link BaseEntity}. * * @param other the object to clone */ public BaseEntity(BaseEntity other) { checkNotNull(other); this.type = other.getType(); setNbtData(other.getNbtData()); }
@Override public BaseEntity getState() { return new BaseEntity(entity); }
@Nullable @Override public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { try { Entity createdEntity = adapter.createEntity(BukkitAdapter.adapt(getWorld(), location), entity); if (createdEntity != null) { return new BukkitEntity(createdEntity); } else { return null; } } catch (Exception e) { logger.warning("Corrupt entity found when creating: " + entity.getType().getId()); if (entity.getNbtData() != null) { logger.warning(entity.getNbtData().toString()); } e.printStackTrace(); return null; } } else { return null; } }
CompoundTag tag = state.getNbtData(); return new BaseEntity(state.getType(), builder.build());
@Nullable @Override public Entity createEntity(Location location, BaseEntity entity) { World world = getWorld(); EntityType entityType = Sponge.getRegistry().getType(EntityType.class, entity.getType().getId()).get(); Vector3d pos = new Vector3d(location.getX(), location.getY(), location.getZ()); org.spongepowered.api.entity.Entity newEnt = world.createEntity(entityType, pos); if (entity.hasNbtData()) { applyEntityData(newEnt, entity); } // Overwrite any data set by the NBT application Vector3 dir = location.getDirection(); newEnt.setLocationAndRotation( new org.spongepowered.api.world.Location<>(getWorld(), pos), new Vector3d(dir.getX(), dir.getY(), dir.getZ()) ); if (world.spawnEntity(newEnt)) { return new SpongeEntity(newEnt); } return null; }
/** * Create a new base entity. * * @param type the entity type * @param nbtData NBT data */ public BaseEntity(EntityType type, CompoundTag nbtData) { this(type); setNbtData(nbtData); }
@Nullable @Override public Entity createEntity(Location location, BaseEntity entity) { World world = getWorld(); net.minecraft.entity.Entity createdEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entity.getType().getId()), world); if (createdEntity != null) { CompoundTag nativeTag = entity.getNbtData(); if (nativeTag != null) { NBTTagCompound tag = NBTConverter.toNative(entity.getNbtData()); for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { tag.removeTag(name); } createdEntity.readFromNBT(tag); } createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); world.spawnEntity(createdEntity); return new ForgeEntity(createdEntity); } else { return null; } }
/** * Create a new instance. * * @param location the location * @param entity the entity (which will be copied) */ StoredEntity(Location location, BaseEntity entity) { checkNotNull(location); checkNotNull(entity); this.location = location; this.entity = new BaseEntity(entity); }
@Override public BaseEntity getState() { net.minecraft.entity.Entity entity = entityRef.get(); if (entity != null) { String id = EntityList.getEntityString(entity); if (id != null) { NBTTagCompound tag = new NBTTagCompound(); entity.writeToNBT(tag); return new BaseEntity(EntityTypes.get(id), NBTConverter.fromNative(tag)); } else { return null; } } else { return null; } }
EntityType entityType = EntityTypes.get(id.toLowerCase()); if (entityType != null) { BaseEntity state = new BaseEntity(entityType, compound); clipboard.createEntity(location, state); } else {