use of net.minecraft.entity.item.EntityPainting in project SpongeCommon by SpongePowered.
the class MixinWorld method createEntity.
private Entity createEntity(EntityType type, Vector3d position, boolean naturally) throws IllegalArgumentException, IllegalStateException {
checkNotNull(type, "The entity type cannot be null!");
checkNotNull(position, "The position cannot be null!");
Entity entity = null;
Class<? extends Entity> entityClass = type.getEntityClass();
double x = position.getX();
double y = position.getY();
double z = position.getZ();
if (entityClass.isAssignableFrom(EntityPlayerMP.class) || entityClass.isAssignableFrom(MultiPartEntityPart.class)) {
// Unable to construct these
throw new IllegalArgumentException("Cannot construct " + type.getId() + " please look to using entity types correctly!");
}
net.minecraft.world.World world = (net.minecraft.world.World) (Object) this;
// Not all entities have a single World parameter as their constructor
if (entityClass.isAssignableFrom(EntityLightningBolt.class)) {
entity = (Entity) new EntityLightningBolt(world, x, y, z, false);
} else if (entityClass.isAssignableFrom(EntityEnderPearl.class)) {
EntityArmorStand tempEntity = new EntityArmorStand(world, x, y, z);
tempEntity.posY -= tempEntity.getEyeHeight();
entity = (Entity) new EntityEnderPearl(world, tempEntity);
((EnderPearl) entity).setShooter(ProjectileSource.UNKNOWN);
}
// set them is to use the more specialised constructor).
if (entityClass.isAssignableFrom(EntityFallingBlock.class)) {
entity = (Entity) new EntityFallingBlock(world, x, y, z, Blocks.SAND.getDefaultState());
} else if (entityClass.isAssignableFrom(EntityItem.class)) {
entity = (Entity) new EntityItem(world, x, y, z, new ItemStack(Blocks.STONE));
}
if (entity == null) {
try {
entity = ConstructorUtils.invokeConstructor(entityClass, this);
((net.minecraft.entity.Entity) entity).setPosition(x, y, z);
} catch (Exception e) {
throw new RuntimeException("There was an issue attempting to construct " + type.getId(), e);
}
}
if (naturally && entity instanceof EntityLiving) {
// Adding the default equipment
((EntityLiving) entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(x, y, z)), null);
}
if (entity instanceof EntityPainting) {
// This is default when art is null when reading from NBT, could
// choose a random art instead?
((EntityPainting) entity).art = EnumArt.KEBAB;
}
return entity;
}
use of net.minecraft.entity.item.EntityPainting in project SpongeCommon by SpongePowered.
the class EntityUtil method refreshPainting.
public static boolean refreshPainting(EntityPainting painting, EntityPainting.EnumArt art) {
EntityPainting.EnumArt oldArt = painting.art;
painting.art = art;
painting.updateFacingWithBoundingBox(painting.facingDirection);
if (!painting.onValidSurface()) {
painting.art = oldArt;
painting.updateFacingWithBoundingBox(painting.facingDirection);
return false;
}
final EntityTracker paintingTracker = ((WorldServer) painting.world).getEntityTracker();
EntityTrackerEntry paintingEntry = paintingTracker.trackedEntityHashTable.lookup(painting.getEntityId());
List<EntityPlayerMP> playerMPs = new ArrayList<>();
for (EntityPlayerMP player : paintingEntry.trackingPlayers) {
SPacketDestroyEntities packet = new SPacketDestroyEntities(painting.getEntityId());
player.connection.sendPacket(packet);
playerMPs.add(player);
}
for (EntityPlayerMP playerMP : playerMPs) {
SpongeImpl.getGame().getScheduler().createTaskBuilder().delayTicks(SpongeImpl.getGlobalConfig().getConfig().getEntity().getPaintingRespawnDelaly()).execute(() -> {
final SPacketSpawnPainting packet = new SPacketSpawnPainting(painting);
playerMP.connection.sendPacket(packet);
}).submit(SpongeImpl.getPlugin());
}
return true;
}
Aggregations