Search in sources :

Example 26 with EntityType

use of net.minecraft.entity.EntityType in project Client by MatHax.

the class EntityTypeListSetting method parseImpl.

@Override
protected Object2BooleanMap<EntityType<?>> parseImpl(String str) {
    String[] values = str.split(",");
    Object2BooleanMap<EntityType<?>> entities = new Object2BooleanOpenHashMap<>(values.length);
    try {
        for (String value : values) {
            EntityType<?> entity = parseId(Registry.ENTITY_TYPE, value);
            if (entity != null)
                entities.put(entity, true);
        }
    } catch (Exception ignored) {
    }
    return entities;
}
Also used : EntityType(net.minecraft.entity.EntityType) Object2BooleanOpenHashMap(it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap) NbtString(net.minecraft.nbt.NbtString)

Example 27 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)

Example 28 with EntityType

use of net.minecraft.entity.EntityType in project endergetic by team-abnormals.

the class PuffBugBottleItem method use.

@Override
public ActionResult<ItemStack> use(World worldIn, PlayerEntity playerIn, Hand handIn) {
    ItemStack itemstack = playerIn.getItemInHand(handIn);
    if (worldIn.isClientSide) {
        return new ActionResult<>(ActionResultType.PASS, itemstack);
    } else {
        RayTraceResult raytraceresult = getPlayerPOVHitResult(worldIn, playerIn, RayTraceContext.FluidMode.SOURCE_ONLY);
        if (raytraceresult.getType() != RayTraceResult.Type.BLOCK) {
            return new ActionResult<>(ActionResultType.PASS, itemstack);
        } else {
            BlockRayTraceResult blockraytraceresult = (BlockRayTraceResult) raytraceresult;
            BlockPos blockpos = blockraytraceresult.getBlockPos();
            if (!(worldIn.getBlockState(blockpos).getBlock() instanceof FlowingFluidBlock)) {
                return new ActionResult<>(ActionResultType.PASS, itemstack);
            } else if (worldIn.mayInteract(playerIn, blockpos) && playerIn.mayUseItemAt(blockpos, blockraytraceresult.getDirection(), itemstack)) {
                EntityType<?> entitytype = EEEntities.PUFF_BUG.get();
                if (entitytype.spawn((ServerWorld) worldIn, itemstack, playerIn, blockpos, SpawnReason.SPAWN_EGG, false, false) == null) {
                    return new ActionResult<>(ActionResultType.PASS, itemstack);
                } else {
                    if (!playerIn.abilities.instabuild) {
                        this.emptyBottle(playerIn, handIn);
                    }
                    playerIn.awardStat(Stats.ITEM_USED.get(this));
                    return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
                }
            } else {
                return new ActionResult<>(ActionResultType.FAIL, itemstack);
            }
        }
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) ActionResult(net.minecraft.util.ActionResult) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack)

Example 29 with EntityType

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

the class MyNetworkClient method processStcSpawnEntity.

private static void processStcSpawnEntity(PacketContext context, PacketByteBuf buf) {
    String entityTypeString = buf.readString();
    int entityId = buf.readInt();
    int dimId = buf.readInt();
    DimensionType dimensionType = DimensionType.byRawId(dimId);
    CompoundTag compoundTag = buf.readCompoundTag();
    if (dimensionType == null) {
        Helper.err(String.format("Invalid dimension for spawning entity %s %s %s", dimId, entityTypeString, compoundTag));
    }
    Optional<EntityType<?>> entityType = EntityType.get(entityTypeString);
    if (!entityType.isPresent()) {
        Helper.err("unknown entity type " + entityTypeString);
        return;
    }
    MinecraftClient.getInstance().execute(() -> {
        ClientWorld world = CGlobal.clientWorldLoader.getOrCreateFakedWorld(dimensionType);
        if (world.getEntityById(entityId) != null) {
            Helper.err(String.format("duplicate entity %s %s %s", ((Integer) entityId).toString(), entityType.get(), compoundTag));
            return;
        }
        Entity entity = entityType.get().create(world);
        entity.fromTag(compoundTag);
        entity.setEntityId(entityId);
        entity.updateTrackedPosition(entity.x, entity.y, entity.z);
        world.addEntity(entityId, entity);
        return;
    });
}
Also used : EntityType(net.minecraft.entity.EntityType) DimensionType(net.minecraft.world.dimension.DimensionType) Entity(net.minecraft.entity.Entity) LoadingIndicatorEntity(com.qouteall.immersive_portals.portal.LoadingIndicatorEntity) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) ClientWorld(net.minecraft.client.world.ClientWorld) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 30 with EntityType

use of net.minecraft.entity.EntityType in project bioplethora by AquexTheSeal.

the class BioplethoraSpawnEggItem method initUnaddedEggs.

public static void initUnaddedEggs() {
    final Map<EntityType<?>, SpawnEggItem> EGGS = ObfuscationReflectionHelper.getPrivateValue(SpawnEggItem.class, null, "field_195987_b");
    DefaultDispenseItemBehavior defaultDispenseItemBehavior = new DefaultDispenseItemBehavior() {

        @Override
        public ItemStack execute(IBlockSource source, ItemStack stack) {
            Direction direction = source.getBlockState().getValue(DispenserBlock.FACING);
            EntityType<?> entitytype = ((SpawnEggItem) stack.getItem()).getType(stack.getTag());
            entitytype.spawn(source.getLevel(), stack, null, source.getPos().relative(direction), SpawnReason.DISPENSER, direction != Direction.UP, false);
            stack.shrink(1);
            return stack;
        }
    };
    for (final SpawnEggItem egg : UNADDED_EGGS) {
        EGGS.put(egg.getType(null), egg);
        DispenserBlock.registerBehavior(egg, defaultDispenseItemBehavior);
    }
    UNADDED_EGGS.clear();
}
Also used : EntityType(net.minecraft.entity.EntityType) DefaultDispenseItemBehavior(net.minecraft.dispenser.DefaultDispenseItemBehavior) IBlockSource(net.minecraft.dispenser.IBlockSource) SpawnEggItem(net.minecraft.item.SpawnEggItem) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Aggregations

EntityType (net.minecraft.entity.EntityType)48 Entity (net.minecraft.entity.Entity)16 ResourceLocation (net.minecraft.util.ResourceLocation)13 LivingEntity (net.minecraft.entity.LivingEntity)11 CompoundNBT (net.minecraft.nbt.CompoundNBT)11 BlockPos (net.minecraft.util.math.BlockPos)11 PlayerEntity (net.minecraft.entity.player.PlayerEntity)9 ItemStack (net.minecraft.item.ItemStack)9 HashMap (java.util.HashMap)6 World (net.minecraft.world.World)5 ArrayList (java.util.ArrayList)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 EffectInstance (net.minecraft.potion.EffectInstance)4 List (java.util.List)3 Nonnull (javax.annotation.Nonnull)3 MobEntity (net.minecraft.entity.MobEntity)3 TileEntity (net.minecraft.tileentity.TileEntity)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IPlacementHandler (com.ldtteam.structurize.placement.handlers.placement.IPlacementHandler)2 Random (java.util.Random)2