Search in sources :

Example 1 with FallingBlockEntity

use of net.minecraft.world.entity.item.FallingBlockEntity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method setFallingBlockType.

@Override
public void setFallingBlockType(FallingBlock entity, BlockData block) {
    BlockState state = ((CraftBlockData) block).getState();
    FallingBlockEntity nmsEntity = ((CraftFallingBlock) entity).getHandle();
    try {
        FALLINGBLOCK_TYPE_SETTER.invoke(nmsEntity, state);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CraftBlockData(org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData) BlockState(net.minecraft.world.level.block.state.BlockState)

Example 2 with FallingBlockEntity

use of net.minecraft.world.entity.item.FallingBlockEntity 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;
}
Also used : DifficultyInstance(net.minecraft.world.DifficultyInstance) ThrownEnderpearl(net.minecraft.world.entity.projectile.ThrownEnderpearl) LightningBolt(net.minecraft.world.entity.LightningBolt) ArmorStand(net.minecraft.world.entity.decoration.ArmorStand) BlockPos(net.minecraft.core.BlockPos) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) Mob(net.minecraft.world.entity.Mob) ItemEntity(net.minecraft.world.entity.item.ItemEntity) EnderPearl(org.spongepowered.api.entity.projectile.EnderPearl) ResourceKey(org.spongepowered.api.ResourceKey) Painting(net.minecraft.world.entity.decoration.Painting) MobAccessor(org.spongepowered.common.accessor.world.entity.MobAccessor) Level(net.minecraft.world.level.Level) Level(net.minecraft.world.level.Level) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with FallingBlockEntity

use of net.minecraft.world.entity.item.FallingBlockEntity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method setFallingBlockType.

@Override
public void setFallingBlockType(FallingBlock entity, BlockData block) {
    BlockState state = ((CraftBlockData) block).getState();
    FallingBlockEntity nmsEntity = ((CraftFallingBlock) entity).getHandle();
    try {
        FALLINGBLOCK_TYPE_SETTER.invoke(nmsEntity, state);
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CraftBlockData(org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData) BlockState(net.minecraft.world.level.block.state.BlockState)

Example 4 with FallingBlockEntity

use of net.minecraft.world.entity.item.FallingBlockEntity 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);
            }
        }
    }
}
Also used : PrimedTnt(net.minecraft.world.entity.item.PrimedTnt) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) Player(net.minecraft.world.entity.player.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) WorldConfig(org.spongepowered.common.config.inheritable.WorldConfig) EntityTypeBridge(org.spongepowered.common.bridge.world.entity.EntityTypeBridge) EndCrystal(net.minecraft.world.entity.boss.enderdragon.EndCrystal) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Painting(net.minecraft.world.entity.decoration.Painting) LightningBolt(net.minecraft.world.entity.LightningBolt) EnderDragon(net.minecraft.world.entity.boss.enderdragon.EnderDragon) ActivationCapabilityBridge(org.spongepowered.common.bridge.activation.ActivationCapabilityBridge) WitherBoss(net.minecraft.world.entity.boss.wither.WitherBoss) EnderDragonPart(net.minecraft.world.entity.boss.EnderDragonPart) AbstractHurtingProjectile(net.minecraft.world.entity.projectile.AbstractHurtingProjectile) ResourceLocation(net.minecraft.resources.ResourceLocation) ThrowableProjectile(net.minecraft.world.entity.projectile.ThrowableProjectile) EntityActivationRangeCategory(org.spongepowered.common.config.inheritable.EntityActivationRangeCategory)

Aggregations

FallingBlockEntity (net.minecraft.world.entity.item.FallingBlockEntity)4 LightningBolt (net.minecraft.world.entity.LightningBolt)2 Painting (net.minecraft.world.entity.decoration.Painting)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 BlockPos (net.minecraft.core.BlockPos)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 DifficultyInstance (net.minecraft.world.DifficultyInstance)1 Mob (net.minecraft.world.entity.Mob)1 EnderDragonPart (net.minecraft.world.entity.boss.EnderDragonPart)1 EndCrystal (net.minecraft.world.entity.boss.enderdragon.EndCrystal)1 EnderDragon (net.minecraft.world.entity.boss.enderdragon.EnderDragon)1 WitherBoss (net.minecraft.world.entity.boss.wither.WitherBoss)1 ArmorStand (net.minecraft.world.entity.decoration.ArmorStand)1 HangingEntity (net.minecraft.world.entity.decoration.HangingEntity)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 PrimedTnt (net.minecraft.world.entity.item.PrimedTnt)1 Player (net.minecraft.world.entity.player.Player)1 AbstractHurtingProjectile (net.minecraft.world.entity.projectile.AbstractHurtingProjectile)1 FireworkRocketEntity (net.minecraft.world.entity.projectile.FireworkRocketEntity)1