Search in sources :

Example 6 with EntityType

use of net.minecraft.entity.EntityType in project Fragile-Glass by fredtargaryen.

the class KeyParser method getAllEntityTypesForString.

// /////////////////////////////////
// METHODS FOR PARSING ENTITYTYPES//
// /////////////////////////////////
public static Collection<EntityType<?>> getAllEntityTypesForString(String value) throws Exception {
    Collection<EntityType<?>> entityTypes = new ArrayList<>();
    if (value.charAt(0) == '#') {
        // values[0] is a tag representing multiple entities
        entityTypes = EntityTypeTags.getCollection().get(// Hopefully replaces GetOrCreate
        new ResourceLocation(value.substring(1))).getAllElements();
    } else {
        // value is a single entity
        entityTypes = new ArrayList<>();
        // Check the first value is a ResourceLocation in the Forge EntityType registry, i.e. refers to a valid entity
        EntityType entry = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(value));
        if (entry == null) {
            throw new Exception("There is no entity type with the resource location " + value + ".");
        } else {
            entityTypes.add(entry);
        }
    }
    return entityTypes;
}
Also used : EntityType(net.minecraft.entity.EntityType) TileEntityType(net.minecraft.tileentity.TileEntityType) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList)

Example 7 with EntityType

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

the class Blueprint method transformEntityInfoWithSettings.

/**
 * Transform an entity and rotate it.
 *
 * @param entityInfo the entity nbt.
 * @param world      the world.
 * @param pos        the position.
 * @param rotation   the wanted rotation.
 * @param mirror     the mirror.
 * @return the updated nbt.
 */
private CompoundNBT transformEntityInfoWithSettings(final CompoundNBT entityInfo, final World world, final BlockPos pos, final Rotation rotation, final Mirror mirror) {
    final Optional<EntityType<?>> type = EntityType.by(entityInfo);
    if (type.isPresent()) {
        final Entity finalEntity = type.get().create(world);
        if (finalEntity != null) {
            try {
                finalEntity.deserializeNBT(entityInfo);
                final Vector3d entityVec = Blueprint.transformedVector3d(rotation, mirror, finalEntity.position()).add(Vector3d.atLowerCornerOf(pos));
                finalEntity.yRotO = (float) (finalEntity.mirror(mirror) - NINETY_DEGREES);
                final double rotationYaw = finalEntity.mirror(mirror) + ((double) finalEntity.mirror(mirror) - (double) finalEntity.rotate(rotation));
                if (finalEntity instanceof HangingEntity) {
                    finalEntity.setPos(entityVec.x, entityVec.y, entityVec.z);
                } else {
                    finalEntity.moveTo(entityVec.x, entityVec.y, entityVec.z, (float) rotationYaw, finalEntity.xRot);
                }
                return finalEntity.serializeNBT();
            } catch (final Exception ex) {
                Log.getLogger().error("Entity: " + type.get().getDescriptionId() + " failed to load. ", ex);
                return null;
            }
        }
    }
    return null;
}
Also used : EntityType(net.minecraft.entity.EntityType) HangingEntity(net.minecraft.entity.item.HangingEntity) Entity(net.minecraft.entity.Entity) HangingEntity(net.minecraft.entity.item.HangingEntity) Vector3d(net.minecraft.util.math.vector.Vector3d)

Example 8 with EntityType

use of net.minecraft.entity.EntityType in project Champions by TheIllusiveC4.

the class ChampionEggItem method onItemUse.

@Nonnull
@Override
public ActionResultType onItemUse(ItemUseContext context) {
    World world = context.getWorld();
    if (!world.isRemote() && world instanceof ServerWorld) {
        ItemStack itemstack = context.getItem();
        BlockPos blockpos = context.getPos();
        Direction direction = context.getFace();
        BlockState blockstate = world.getBlockState(blockpos);
        BlockPos blockpos1;
        if (blockstate.getCollisionShape(world, blockpos).isEmpty()) {
            blockpos1 = blockpos;
        } else {
            blockpos1 = blockpos.offset(direction);
        }
        Optional<EntityType<?>> entitytype = getType(itemstack);
        entitytype.ifPresent(type -> {
            Entity entity = type.create((ServerWorld) world, itemstack.getTag(), null, context.getPlayer(), blockpos1, SpawnReason.SPAWN_EGG, true, !Objects.equals(blockpos, blockpos1) && direction == Direction.UP);
            if (entity instanceof LivingEntity) {
                ChampionCapability.getCapability((LivingEntity) entity).ifPresent(champion -> read(champion, itemstack));
                world.addEntity(entity);
                itemstack.shrink(1);
            }
        });
    }
    return ActionResultType.SUCCESS;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) 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) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction) Nonnull(javax.annotation.Nonnull)

Example 9 with EntityType

use of net.minecraft.entity.EntityType in project Champions by TheIllusiveC4.

the class ChampionEggItem method getDisplayName.

@Nonnull
@Override
public ITextComponent getDisplayName(@Nonnull ItemStack stack) {
    int tier = 0;
    Optional<EntityType<?>> type = getType(stack);
    if (stack.hasTag()) {
        CompoundNBT tag = stack.getChildTag(CHAMPION_TAG);
        if (tag != null) {
            tier = tag.getInt(TIER_TAG);
        }
    }
    IFormattableTextComponent root = new TranslationTextComponent("rank.champions.title." + tier);
    root.appendString(" ");
    root.append(type.map(EntityType::getName).orElse(EntityType.ZOMBIE.getName()));
    root.appendString(" ");
    root.append(new TranslationTextComponent(this.getTranslationKey(stack)));
    return root;
}
Also used : EntityType(net.minecraft.entity.EntityType) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) Nonnull(javax.annotation.Nonnull)

Example 10 with EntityType

use of net.minecraft.entity.EntityType in project Champions by TheIllusiveC4.

the class Champions method setup.

private void setup(final FMLCommonSetupEvent evt) {
    ChampionCapability.register();
    NetworkHandler.register();
    AffixManager.register();
    evt.enqueueWork(() -> {
        Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation(Champions.MODID, "entity_champion"), EntityIsChampion.type);
        DefaultDispenseItemBehavior dispenseBehavior = new DefaultDispenseItemBehavior() {

            @Nonnull
            @Override
            public ItemStack dispenseStack(IBlockSource source, @Nonnull ItemStack stack) {
                Direction direction = source.getBlockState().get(DispenserBlock.FACING);
                Optional<EntityType<?>> entitytype = ChampionEggItem.getType(stack);
                entitytype.ifPresent(type -> {
                    Entity entity = type.create(source.getWorld(), stack.getTag(), null, null, source.getBlockPos().offset(direction), SpawnReason.DISPENSER, true, direction != Direction.UP);
                    if (entity instanceof LivingEntity) {
                        ChampionCapability.getCapability((LivingEntity) entity).ifPresent(champion -> ChampionEggItem.read(champion, stack));
                        source.getWorld().addEntity(entity);
                        stack.shrink(1);
                    }
                });
                return stack;
            }
        };
        DispenserBlock.registerDispenseBehavior(ChampionsRegistry.EGG, dispenseBehavior);
        ArgumentTypes.register(Champions.MODID + ":affix", AffixArgument.class, new ArgumentSerializer<>(AffixArgument::affix));
    });
}
Also used : EntityType(net.minecraft.entity.EntityType) LivingEntity(net.minecraft.entity.LivingEntity) LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) DefaultDispenseItemBehavior(net.minecraft.dispenser.DefaultDispenseItemBehavior) IBlockSource(net.minecraft.dispenser.IBlockSource) Nonnull(javax.annotation.Nonnull) ResourceLocation(net.minecraft.util.ResourceLocation) 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