Search in sources :

Example 11 with EntityType

use of net.minecraft.entity.EntityType in project ImmersivePortalsMod by qouteall.

the class MyNetwork method createStcSpawnEntity.

// NOTE my packet is redirected but I cannot get the packet handler info here
public static CustomPayloadS2CPacket createStcSpawnEntity(Entity entity) {
    EntityType entityType = entity.getType();
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeString(EntityType.getId(entityType).toString());
    buf.writeInt(entity.getEntityId());
    buf.writeInt(entity.dimension.getRawId());
    CompoundTag tag = new CompoundTag();
    entity.toTag(tag);
    buf.writeCompoundTag(tag);
    return new CustomPayloadS2CPacket(id_stcSpawnEntity, buf);
}
Also used : EntityType(net.minecraft.entity.EntityType) CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 12 with EntityType

use of net.minecraft.entity.EntityType in project FastAsyncWorldEdit by IntellectualSites.

the class ForgeWorld method createEntity.

@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
    World world = getWorld();
    final Optional<EntityType<?>> entityType = EntityType.byKey(entity.getType().getId());
    if (!entityType.isPresent())
        return null;
    net.minecraft.entity.Entity createdEntity = entityType.get().create(world);
    if (createdEntity != null) {
        CompoundTag nativeTag = entity.getNbtData();
        if (nativeTag != null) {
            CompoundNBT tag = NBTConverter.toNative(entity.getNbtData());
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            createdEntity.read(tag);
        }
        createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
        world.addEntity(createdEntity);
        return new ForgeEntity(createdEntity);
    } else {
        return null;
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) CompoundNBT(net.minecraft.nbt.CompoundNBT) World(net.minecraft.world.World) ServerWorld(net.minecraft.world.server.ServerWorld) AbstractWorld(com.sk89q.worldedit.world.AbstractWorld) CompoundTag(com.sk89q.jnbt.CompoundTag) Nullable(javax.annotation.Nullable)

Example 13 with EntityType

use of net.minecraft.entity.EntityType in project minecolonies by ldtteam.

the class AbstractShipRaidEvent method onUpdate.

@Override
public void onUpdate() {
    status = EventStatus.PROGRESSING;
    colony.getRaiderManager().setNightsSinceLastRaid(0);
    if (spawners.size() <= 0 && raiders.size() == 0 && respawns.isEmpty()) {
        status = EventStatus.WAITING;
        return;
    }
    updateRaidBar();
    if (!respawns.isEmpty()) {
        for (final Tuple<EntityType<?>, BlockPos> entry : respawns) {
            final BlockPos spawnPos = ShipBasedRaiderUtils.getLoadedPositionTowardsCenter(entry.getB(), colony, MAX_LANDING_DISTANCE, spawnPoint, MIN_CENTER_DISTANCE, 10);
            if (spawnPos != null) {
                RaiderMobUtils.spawn(entry.getA(), 1, spawnPos, colony.getWorld(), colony, id);
            }
        }
        respawns.clear();
        return;
    }
    spawners.removeIf(spawner -> colony.getWorld() != null && WorldUtil.isBlockLoaded(colony.getWorld(), spawner) && colony.getWorld().getBlockState(spawner).getBlock() != Blocks.SPAWNER);
    // Spawns landing troops.
    if (raiders.size() < spawners.size() * 2) {
        BlockPos spawnPos = ShipBasedRaiderUtils.getLoadedPositionTowardsCenter(spawnPoint, colony, MAX_LANDING_DISTANCE, spawnPoint, MIN_CENTER_DISTANCE, 10);
        if (spawnPos != null) {
            // Find nice position on the ship
            if (spawnPos.distSqr(spawnPoint) < 25) {
                spawnPos = ShipBasedRaiderUtils.findSpawnPosOnShip(spawnPos, colony.getWorld(), 3);
            }
            RaiderMobUtils.spawn(getNormalRaiderType(), shipSize.normal, spawnPos, colony.getWorld(), colony, id);
            RaiderMobUtils.spawn(getArcherRaiderType(), shipSize.archer, spawnPos, colony.getWorld(), colony, id);
            RaiderMobUtils.spawn(getBossRaiderType(), shipSize.boss, spawnPos, colony.getWorld(), colony, id);
        }
    }
    // Mark entities when spies exist
    if (colony.getRaiderManager().areSpiesEnabled()) {
        for (final Entity entity : getEntities()) {
            if (entity instanceof LivingEntity) {
                ((LivingEntity) entity).addEffect(new EffectInstance(Effects.GLOWING, 550));
            }
        }
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) MobSpawnerTileEntity(net.minecraft.tileentity.MobSpawnerTileEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) TileEntity(net.minecraft.tileentity.TileEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) EffectInstance(net.minecraft.potion.EffectInstance)

Example 14 with EntityType

use of net.minecraft.entity.EntityType in project minecolonies by ldtteam.

the class HordeRaidEvent method onUpdate.

@Override
public void onUpdate() {
    if (status == EventStatus.PREPARING) {
        prepareEvent();
    }
    updateRaidBar();
    colony.getRaiderManager().setNightsSinceLastRaid(0);
    if (horde.hordeSize <= 0) {
        status = EventStatus.DONE;
    }
    if (!respawns.isEmpty()) {
        for (final Tuple<EntityType<?>, BlockPos> entry : respawns) {
            final BlockPos spawnPos = ShipBasedRaiderUtils.getLoadedPositionTowardsCenter(entry.getB(), colony, MAX_RESPAWN_DEVIATION, spawnPoint, MIN_CENTER_DISTANCE, 10);
            if (spawnPos != null) {
                RaiderMobUtils.spawn(entry.getA(), 1, spawnPos, colony.getWorld(), colony, id);
            }
        }
        respawns.clear();
        return;
    }
    if (boss.size() + archers.size() + normal.size() < horde.numberOfBosses + horde.numberOfRaiders + horde.numberOfArchers) {
        final BlockPos spawnPos = ShipBasedRaiderUtils.getLoadedPositionTowardsCenter(spawnPoint, colony, MAX_RESPAWN_DEVIATION, spawnPoint, MIN_CENTER_DISTANCE, 10);
        if (spawnPos != null) {
            spawnHorde(spawnPos, colony, id, horde.numberOfBosses - boss.size(), horde.numberOfArchers - archers.size(), horde.numberOfRaiders - normal.size());
        }
    }
    if (horde.numberOfBosses + horde.numberOfRaiders + horde.numberOfArchers < Math.round(horde.initialSize * 0.05)) {
        status = EventStatus.DONE;
    }
    for (final Entity entity : getEntities()) {
        if (!entity.isAlive() || !WorldUtil.isEntityBlockLoaded(colony.getWorld(), new BlockPos(entity.position()))) {
            entity.remove();
            respawns.add(new Tuple<>(entity.getType(), new BlockPos(entity.position())));
            continue;
        }
        if (colony.getRaiderManager().areSpiesEnabled()) {
            ((LivingEntity) entity).addEffect(new EffectInstance(Effects.GLOWING, 550));
        }
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) EffectInstance(net.minecraft.potion.EffectInstance)

Example 15 with EntityType

use of net.minecraft.entity.EntityType in project Werewolves by TeamLapen.

the class ModEntityEventHandler method makeWerewolfFriendly.

/**
 * copy from {@link de.teamlapen.vampirism.entity.ModEntityEventHandler#makeVampireFriendly(String, MobEntity, Class, Class, int, BiFunction, Predicate)}
 */
public static <T extends MobEntity, S extends LivingEntity, Q extends NearestAttackableTargetGoal<S>> void makeWerewolfFriendly(String name, T entity, Class<Q> targetClass, Class<S> targetEntityClass, int attackPriority, BiFunction<T, Predicate<LivingEntity>, Q> replacement, Predicate<EntityType<? extends T>> typeCheck) {
    try {
        Goal target = null;
        for (PrioritizedGoal t : entity.targetSelector.availableGoals) {
            Goal g = t.getGoal();
            if (targetClass.equals(g.getClass()) && t.getPriority() == attackPriority && targetEntityClass.equals(((NearestAttackableTargetGoal<?>) g).targetType)) {
                target = g;
                break;
            }
        }
        if (target != null) {
            entity.targetSelector.removeGoal(target);
            EntityType<? extends T> type = (EntityType<? extends T>) entity.getType();
            if (typeCheck.test(type)) {
                Predicate<LivingEntity> newPredicate = nonWerewolfCheck;
                if (((Q) target).targetConditions.selector != null) {
                    newPredicate = newPredicate.and(((NearestAttackableTargetGoal<?>) target).targetConditions.selector);
                }
                entity.targetSelector.addGoal(attackPriority, replacement.apply(entity, newPredicate));
            }
        } else {
            if (entityAIReplacementWarnMap.getOrDefault(name, true)) {
                LOGGER.warn("Could not replace {} attack target task for {}", name, entity.getType().getDescription());
                entityAIReplacementWarnMap.put(name, false);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Could not replace " + name + " attack target task for " + entity.getType().getDescription(), e);
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) Goal(net.minecraft.entity.ai.goal.Goal) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal)

Aggregations

EntityType (net.minecraft.entity.EntityType)38 Entity (net.minecraft.entity.Entity)15 CompoundNBT (net.minecraft.nbt.CompoundNBT)10 ResourceLocation (net.minecraft.util.ResourceLocation)10 BlockPos (net.minecraft.util.math.BlockPos)10 LivingEntity (net.minecraft.entity.LivingEntity)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)7 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 EffectInstance (net.minecraft.potion.EffectInstance)4 World (net.minecraft.world.World)4 List (java.util.List)3 Nonnull (javax.annotation.Nonnull)3 MobEntity (net.minecraft.entity.MobEntity)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IPlacementHandler (com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2 SplittableRandom (java.util.SplittableRandom)2