use of net.minecraft.world.entity.decoration.Painting 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;
}
use of net.minecraft.world.entity.decoration.Painting in project SpongeCommon by SpongePowered.
the class EntityActivationRange method initializeEntityActivationState.
/**
* Initialize entity activation state.
*
* @param entity Entity to check
*/
public static void initializeEntityActivationState(final Entity entity) {
final ActivationCapabilityBridge spongeEntity = (ActivationCapabilityBridge) entity;
if (entity.level.isClientSide()) {
return;
}
// types that should always be active
if (entity instanceof Player && !((PlatformEntityBridge) entity).bridge$isFakePlayer() || entity instanceof ThrowableProjectile || entity instanceof EnderDragon || entity instanceof EnderDragonPart || entity instanceof WitherBoss || entity instanceof AbstractHurtingProjectile || entity instanceof LightningBolt || entity instanceof PrimedTnt || entity instanceof Painting || entity instanceof EndCrystal || entity instanceof FireworkRocketEntity || // Always tick falling blocks
entity instanceof FallingBlockEntity) {
return;
}
final InheritableConfigHandle<WorldConfig> configAdapter = SpongeGameConfigs.getForWorld(entity.level);
final EntityActivationRangeCategory config = configAdapter.get().entityActivationRange;
final EntityTypeBridge type = (EntityTypeBridge) entity.getType();
final ResourceLocation key = EntityType.getKey(entity.getType());
final byte activationType = spongeEntity.activation$getActivationType();
final String activationTypeName = EntityActivationRange.activationTypeMappings.getOrDefault(activationType, "misc");
if (!type.bridge$isActivationRangeInitialized()) {
EntityActivationRange.addEntityToConfig(config.autoPopulate, key, activationType, activationTypeName);
type.bridge$setActivationRangeInitialized(true);
}
final EntityActivationRangeCategory.ModSubCategory entityMod = config.mods.get(key.getNamespace());
final int defaultActivationRange = config.globalRanges.get(activationTypeName);
if (entityMod == null) {
// use default activation range
spongeEntity.activation$setActivationRange(defaultActivationRange);
if (defaultActivationRange > 0) {
spongeEntity.activation$setDefaultActivationState(false);
}
} else {
if (!entityMod.enabled) {
spongeEntity.activation$setDefaultActivationState(true);
return;
}
final Integer defaultModActivationRange = entityMod.defaultRanges.get(activationTypeName);
final Integer entityActivationRange = entityMod.entities.get(key.getPath());
if (defaultModActivationRange != null && entityActivationRange == null) {
spongeEntity.activation$setActivationRange(defaultModActivationRange);
if (defaultModActivationRange > 0) {
spongeEntity.activation$setDefaultActivationState(false);
}
} else if (entityActivationRange != null) {
spongeEntity.activation$setActivationRange(entityActivationRange);
if (entityActivationRange > 0) {
spongeEntity.activation$setDefaultActivationState(false);
}
}
}
}
Aggregations