Search in sources :

Example 6 with EntityType

use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.

the class EntityActivationRange method activateChunkEntities.

/**
 * Checks for the activation state of all entities in this chunk.
 *
 * @param chunk Chunk to check for activation
 */
private static void activateChunkEntities(EntityPlayer player, Chunk chunk) {
    for (int i = 0; i < chunk.getEntityLists().length; ++i) {
        for (Object o : chunk.getEntityLists()[i]) {
            Entity entity = (Entity) o;
            EntityType type = ((org.spongepowered.api.entity.Entity) entity).getType();
            long currentTick = SpongeImpl.getServer().getTickCounter();
            if (type == EntityTypes.UNKNOWN) {
                ((IModData_Activation) entity).setActivatedTick(currentTick);
                continue;
            }
            if (currentTick > ((IModData_Activation) entity).getActivatedTick()) {
                if (((IModData_Activation) entity).getDefaultActivationState()) {
                    ((IModData_Activation) entity).setActivatedTick(currentTick);
                    continue;
                }
                IModData_Activation spongeEntity = (IModData_Activation) entity;
                // check if activation cache needs to be updated
                if (spongeEntity.requiresActivationCacheRefresh()) {
                    EntityActivationRange.initializeEntityActivationState(entity);
                    spongeEntity.requiresActivationCacheRefresh(false);
                }
                // check for entity type overrides
                byte activationType = ((IModData_Activation) entity).getActivationType();
                int bbActivationRange = ((IModData_Activation) entity).getActivationRange();
                if (activationType == 5) {
                    growBb(miscBB, player.getEntityBoundingBox(), bbActivationRange, 256, bbActivationRange);
                } else if (activationType == 4) {
                    growBb(ambientBB, player.getEntityBoundingBox(), bbActivationRange, 256, bbActivationRange);
                } else if (activationType == 3) {
                    growBb(aquaticBB, player.getEntityBoundingBox(), bbActivationRange, 256, bbActivationRange);
                } else if (activationType == 2) {
                    growBb(creatureBB, player.getEntityBoundingBox(), bbActivationRange, 256, bbActivationRange);
                } else {
                    growBb(monsterBB, player.getEntityBoundingBox(), bbActivationRange, 256, bbActivationRange);
                }
                switch(((IModData_Activation) entity).getActivationType()) {
                    case 1:
                        if (monsterBB.intersects(entity.getEntityBoundingBox())) {
                            ((IModData_Activation) entity).setActivatedTick(currentTick);
                        }
                        break;
                    case 2:
                        if (creatureBB.intersects(entity.getEntityBoundingBox())) {
                            ((IModData_Activation) entity).setActivatedTick(currentTick);
                        }
                        break;
                    case 3:
                        if (aquaticBB.intersects(entity.getEntityBoundingBox())) {
                            ((IModData_Activation) entity).setActivatedTick(currentTick);
                        }
                        break;
                    case 4:
                        if (ambientBB.intersects(entity.getEntityBoundingBox())) {
                            ((IModData_Activation) entity).setActivatedTick(currentTick);
                        }
                        break;
                    case 5:
                    default:
                        if (miscBB.intersects(entity.getEntityBoundingBox())) {
                            ((IModData_Activation) entity).setActivatedTick(currentTick);
                        }
                }
            }
        }
    }
}
Also used : SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityType(org.spongepowered.api.entity.EntityType) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Entity(net.minecraft.entity.Entity) IModData_Activation(org.spongepowered.common.mixin.plugin.entityactivation.interfaces.IModData_Activation)

Example 7 with EntityType

use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.

the class MixinCommandSummon method onAttemptSpawnEntity.

@Redirect(method = "execute", at = @At(value = "INVOKE", target = ENTITY_LIST_CREATE_FROM_NBT))
private Entity onAttemptSpawnEntity(NBTTagCompound nbt, World world, double x, double y, double z, boolean b, MinecraftServer server, ICommandSender sender, String[] args) {
    if ("Minecart".equals(nbt.getString(NbtDataUtil.ENTITY_TYPE_ID))) {
        nbt.setString(NbtDataUtil.ENTITY_TYPE_ID, EntityMinecart.Type.values()[nbt.getInteger(NbtDataUtil.MINECART_TYPE)].getName());
        nbt.removeTag(NbtDataUtil.MINECART_TYPE);
    }
    Class<? extends Entity> entityClass = SpongeImplHooks.getEntityClass(new ResourceLocation(nbt.getString(NbtDataUtil.ENTITY_TYPE_ID)));
    if (entityClass == null) {
        return null;
    }
    EntityType type = EntityTypeRegistryModule.getInstance().getForClass(entityClass);
    if (type == null) {
        return null;
    }
    Transform<org.spongepowered.api.world.World> transform = new Transform<>(((org.spongepowered.api.world.World) world), new Vector3d(x, y, z));
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PLACEMENT);
        ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(Sponge.getCauseStackManager().getCurrentCause(), type, transform);
        SpongeImpl.postEvent(event);
        return event.isCancelled() ? null : AnvilChunkLoader.readWorldEntityPos(nbt, world, x, y, z, b);
    }
}
Also used : World(net.minecraft.world.World) EntityType(org.spongepowered.api.entity.EntityType) ConstructEntityEvent(org.spongepowered.api.event.entity.ConstructEntityEvent) Vector3d(com.flowpowered.math.vector.Vector3d) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ResourceLocation(net.minecraft.util.ResourceLocation) Transform(org.spongepowered.api.entity.Transform) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 8 with EntityType

use of org.spongepowered.api.entity.EntityType in project Skree by Skelril.

the class CreatureImpact method run.

@Override
public void run(Living owner, Location<World> target) {
    EntityType targetType = getEntityType();
    mobBarrage(target, targetType, count);
    if (targetType == EntityTypes.BAT) {
        notify(owner, Text.of(TextColors.YELLOW, "Your bow releases a batty attack."));
    } else {
        notify(owner, Text.of(TextColors.YELLOW, "Your bow releases a " + targetType.getName().toLowerCase() + " attack."));
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType)

Example 9 with EntityType

use of org.spongepowered.api.entity.EntityType in project modules-extra by CubeEngine.

the class InvasionCommand method invasion.

@Command(desc = "Spawns a mob next to every player on the server")
public void invasion(CommandSource context, String mob) {
    EntityType entityType = em.mob(mob, context.getLocale());
    if (entityType == null) {
        i18n.send(context, MessageType.NEGATIVE, "EntityType {input} not found", mob);
        return;
    }
    Sponge.getCauseStackManager().pushCause(context);
    for (Player player : Sponge.getServer().getOnlinePlayers()) {
        Optional<BlockRayHit<World>> end = BlockRay.from(player).stopFilter(BlockRay.onlyAirFilter()).distanceLimit(module.getConfig().command.invasion.distance).build().end();
        if (end.isPresent()) {
            Location<World> location = end.get().getLocation();
            Entity entity = location.getExtent().createEntity(entityType, location.getPosition());
            location.getExtent().spawnEntity(entity);
        }
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) BlockRayHit(org.spongepowered.api.util.blockray.BlockRayHit) Command(org.cubeengine.butler.parametric.Command)

Example 10 with EntityType

use of org.spongepowered.api.entity.EntityType in project modules-extra by CubeEngine.

the class ThrowCommands method throwCommand.

@Command(name = "throw", desc = "Throw something!")
@Restricted(value = Player.class, msg = "This command can only be used by a player!")
public void throwCommand(Player context, String material, @Optional Integer amount, @Named({ "delay", "d" }) Integer delay, @Flag boolean unsafe) {
    EntityType type = null;
    boolean showNotification = true;
    ThrowTask task = this.thrownItems.remove(context.getUniqueId());
    if (task != null) {
        int aDelay = delay == null ? task.getInterval() : delay;
        if (material == null || (type = entityMatcher.any(material, context.getLocale())) == task.getType() && task.getInterval() == aDelay && task.getPreventDamage() != unsafe && delay == null) {
            task.stop(true);
            return;
        }
        task.stop(showNotification = false);
    }
    amount = amount == null ? -1 : 1;
    if ((amount > this.module.getConfig().command.throwSection.maxAmount || amount < 1) && amount != -1) {
        i18n.send(context, NEGATIVE, "The amount must be a number from 1 to {integer}", this.module.getConfig().command.throwSection.maxAmount);
        return;
    }
    delay = delay == null ? 3 : delay;
    if (delay > this.module.getConfig().command.throwSection.maxDelay || delay < 0) {
        i18n.send(context, NEGATIVE, "The delay must be a number from 0 to {integer}", this.module.getConfig().command.throwSection.maxDelay);
        return;
    }
    if (unsafe && !context.hasPermission(module.perms().COMMAND_THROW_UNSAFE.getId())) {
        i18n.send(context, NEGATIVE, "You are not allowed to execute this command in unsafe mode.");
        return;
    }
    if (type == null) {
        type = entityMatcher.any(material, context.getLocale());
    }
    if (type == null) {
        i18n.send(context, NEGATIVE, "The given object was not found!");
        return;
    }
    if (!context.hasPermission(perms.get(type).getId())) {
        i18n.send(context, NEGATIVE, "You are not allowed to throw this.");
        return;
    }
    if ((BUGGED_ENTITIES.contains(type) || entityMatcher.isMonster(type)) && !unsafe) {
        i18n.send(context, NEUTRAL, "This object can only be thrown in unsafe mode. Add -u to enable the unsafe mode.");
        return;
    }
    task = new ThrowTask(context, type, amount, delay, !unsafe);
    if (task.start(showNotification)) {
        this.thrownItems.put(context.getUniqueId(), task);
    } else {
        i18n.send(context, NEGATIVE, "Failed to throw this!");
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) Command(org.cubeengine.butler.parametric.Command) Restricted(org.cubeengine.butler.filter.Restricted)

Aggregations

EntityType (org.spongepowered.api.entity.EntityType)33 Vector3d (com.flowpowered.math.vector.Vector3d)7 World (net.minecraft.world.World)6 Entity (org.spongepowered.api.entity.Entity)6 Transform (org.spongepowered.api.entity.Transform)6 ConstructEntityEvent (org.spongepowered.api.event.entity.ConstructEntityEvent)6 SpongeEntityType (org.spongepowered.common.entity.SpongeEntityType)4 Entity (net.minecraft.entity.Entity)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 Player (org.spongepowered.api.entity.living.player.Player)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3 World (org.spongepowered.api.world.World)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 NBTTagList (net.minecraft.nbt.NBTTagList)2