use of net.minecraft.world.entity.projectile.ThrownEnderpearl in project SpongeCommon by SpongePowered.
the class LevelMixin method bridge$createEntity.
@Override
@SuppressWarnings("unchecked")
public <E extends org.spongepowered.api.entity.Entity> E bridge$createEntity(final EntityType<E> type, final Vector3d position, final boolean naturally) throws IllegalArgumentException, IllegalStateException {
if (type == net.minecraft.world.entity.EntityType.PLAYER) {
// Unable to construct these
throw new IllegalArgumentException("A Player cannot be created by the API!");
}
net.minecraft.world.entity.Entity entity = null;
final double x = position.x();
final double y = position.y();
final double z = position.z();
final net.minecraft.world.level.Level thisWorld = (net.minecraft.world.level.Level) (Object) this;
// Not all entities have a single World parameter as their constructor
if (type == net.minecraft.world.entity.EntityType.LIGHTNING_BOLT) {
entity = net.minecraft.world.entity.EntityType.LIGHTNING_BOLT.create(thisWorld);
entity.moveTo(x, y, z);
((LightningBolt) entity).setVisualOnly(false);
}
// TODO - archetypes should solve the problem of calling the correct constructor
if (type == net.minecraft.world.entity.EntityType.ENDER_PEARL) {
final ArmorStand tempEntity = new ArmorStand(thisWorld, x, y, z);
tempEntity.setPos(tempEntity.getX(), tempEntity.getY() - tempEntity.getEyeHeight(), tempEntity.getZ());
entity = new ThrownEnderpearl(thisWorld, tempEntity);
((EnderPearl) entity).offer(Keys.SHOOTER, UnknownProjectileSource.UNKNOWN);
}
// set them is to use the more specialised constructor).
if (type == net.minecraft.world.entity.EntityType.FALLING_BLOCK) {
entity = new FallingBlockEntity(thisWorld, x, y, z, Blocks.SAND.defaultBlockState());
}
if (type == net.minecraft.world.entity.EntityType.ITEM) {
entity = new ItemEntity(thisWorld, x, y, z, new ItemStack(Blocks.STONE));
}
if (entity == null) {
final ResourceKey key = (ResourceKey) (Object) Registry.ENTITY_TYPE.getKey((net.minecraft.world.entity.EntityType<?>) type);
try {
entity = ((net.minecraft.world.entity.EntityType) type).create(thisWorld);
entity.moveTo(x, y, z);
} catch (final Exception e) {
throw new RuntimeException("There was an issue attempting to construct " + key, e);
}
}
if (entity instanceof HangingEntity) {
if (!((HangingEntity) entity).survives()) {
throw new IllegalArgumentException("Hanging entity does not survive at the given position: " + position);
}
}
if (naturally && entity instanceof Mob) {
// Adding the default equipment
final DifficultyInstance difficulty = this.shadow$getCurrentDifficultyAt(new BlockPos(x, y, z));
((MobAccessor) entity).invoker$populateDefaultEquipmentSlots(difficulty);
}
if (entity instanceof Painting) {
// This is default when art is null when reading from NBT, could
// choose a random art instead?
((Painting) entity).motive = Motive.KEBAB;
}
return (E) entity;
}
Aggregations