Search in sources :

Example 31 with EntityType

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

the class FabricWorld method createEntity.

@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
    World world = getWorld();
    final Optional<EntityType<?>> entityType = EntityType.get(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) {
            net.minecraft.nbt.CompoundTag tag = NBTConverter.toNative(entity.getNbtData());
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            createdEntity.fromTag(tag);
        }
        createdEntity.setPositionAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
        world.spawnEntity(createdEntity);
        return new FabricEntity(createdEntity);
    } else {
        return null;
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) ServerWorld(net.minecraft.server.world.ServerWorld) AbstractWorld(com.sk89q.worldedit.world.AbstractWorld) World(net.minecraft.world.World) CompoundTag(com.sk89q.jnbt.CompoundTag) Nullable(javax.annotation.Nullable)

Example 32 with EntityType

use of net.minecraft.entity.EntityType in project meteor-client by MeteorDevelopment.

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 33 with EntityType

use of net.minecraft.entity.EntityType in project Arclight by IzzelAliz.

the class AbstractSpawnerMixin method tick.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void tick() {
    if (!this.isActivated()) {
        this.prevMobRotation = this.mobRotation;
    } else {
        World world = this.getWorld();
        BlockPos blockpos = this.getSpawnerPosition();
        if (world.isRemote) {
            double d3 = (double) blockpos.getX() + (double) world.rand.nextFloat();
            double d4 = (double) blockpos.getY() + (double) world.rand.nextFloat();
            double d5 = (double) blockpos.getZ() + (double) world.rand.nextFloat();
            world.addParticle(ParticleTypes.SMOKE, d3, d4, d5, 0.0D, 0.0D, 0.0D);
            world.addParticle(ParticleTypes.FLAME, d3, d4, d5, 0.0D, 0.0D, 0.0D);
            if (this.spawnDelay > 0) {
                --this.spawnDelay;
            }
            this.prevMobRotation = this.mobRotation;
            this.mobRotation = (this.mobRotation + (double) (1000.0F / ((float) this.spawnDelay + 200.0F))) % 360.0D;
        } else {
            if (this.spawnDelay == -1) {
                this.resetTimer();
            }
            if (this.spawnDelay > 0) {
                --this.spawnDelay;
                return;
            }
            boolean flag = false;
            for (int i = 0; i < this.spawnCount; ++i) {
                CompoundNBT compoundnbt = this.spawnData.getNbt();
                Optional<EntityType<?>> optional = EntityType.readEntityType(compoundnbt);
                if (!optional.isPresent()) {
                    this.resetTimer();
                    return;
                }
                ListNBT listnbt = compoundnbt.getList("Pos", 6);
                int j = listnbt.size();
                double d0 = j >= 1 ? listnbt.getDouble(0) : (double) blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) this.spawnRange + 0.5D;
                double d1 = j >= 2 ? listnbt.getDouble(1) : (double) (blockpos.getY() + world.rand.nextInt(3) - 1);
                double d2 = j >= 3 ? listnbt.getDouble(2) : (double) blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) this.spawnRange + 0.5D;
                if (world.hasNoCollisions(optional.get().getBoundingBoxWithSizeApplied(d0, d1, d2)) && EntitySpawnPlacementRegistry.func_223515_a(optional.get(), world.getWorld(), SpawnReason.SPAWNER, new BlockPos(d0, d1, d2), world.getRandom())) {
                    Entity entity = EntityType.loadEntityAndExecute(compoundnbt, world, (p_221408_6_) -> {
                        p_221408_6_.setLocationAndAngles(d0, d1, d2, p_221408_6_.rotationYaw, p_221408_6_.rotationPitch);
                        return p_221408_6_;
                    });
                    if (entity == null) {
                        this.resetTimer();
                        return;
                    }
                    int k = world.getEntitiesWithinAABB(entity.getClass(), (new AxisAlignedBB((double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), (double) (blockpos.getX() + 1), (double) (blockpos.getY() + 1), (double) (blockpos.getZ() + 1))).grow((double) this.spawnRange)).size();
                    if (k >= this.maxNearbyEntities) {
                        this.resetTimer();
                        return;
                    }
                    entity.setLocationAndAngles(entity.getPosX(), entity.getPosY(), entity.getPosZ(), world.rand.nextFloat() * 360.0F, 0.0F);
                    if (entity instanceof MobEntity) {
                        MobEntity mobentity = (MobEntity) entity;
                        if (!ForgeEventFactory.canEntitySpawnSpawner(mobentity, world, (float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), (AbstractSpawner) (Object) this)) {
                            continue;
                        }
                        if (this.spawnData.getNbt().size() == 1 && this.spawnData.getNbt().contains("id", 8)) {
                            ((MobEntity) entity).onInitialSpawn(world, world.getDifficultyForLocation(new BlockPos(entity)), SpawnReason.SPAWNER, (ILivingEntityData) null, (CompoundNBT) null);
                        }
                        if (((WorldBridge) mobentity.world).bridge$spigotConfig().nerfSpawnerMobs) {
                            ((MobEntityBridge) mobentity).bridge$setAware(false);
                        }
                    }
                    if (CraftEventFactory.callSpawnerSpawnEvent(entity, blockpos).isCancelled()) {
                        Entity vehicle = entity.getRidingEntity();
                        if (vehicle != null) {
                            vehicle.removed = true;
                        }
                        for (final Entity passenger : entity.getRecursivePassengers()) {
                            passenger.removed = true;
                        }
                    }
                    this.func_221409_a(entity);
                    world.playEvent(2004, blockpos, 0);
                    if (entity instanceof MobEntity) {
                        ((MobEntity) entity).spawnExplosionParticle();
                    }
                    flag = true;
                }
            }
            if (flag) {
                this.resetTimer();
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) WeightedSpawnerEntity(net.minecraft.util.WeightedSpawnerEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) CompoundNBT(net.minecraft.nbt.CompoundNBT) World(net.minecraft.world.World) MobEntityBridge(io.izzel.arclight.common.bridge.entity.MobEntityBridge) EntityType(net.minecraft.entity.EntityType) ListNBT(net.minecraft.nbt.ListNBT) AbstractSpawner(net.minecraft.world.spawner.AbstractSpawner) BlockPos(net.minecraft.util.math.BlockPos) MobEntity(net.minecraft.entity.MobEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 34 with EntityType

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

the class ExportAllCommand method execute.

private static int execute(CommandSource source, String manager) {
    DataManager dm = CommandsBase.getDataManager(manager);
    if (dm == null) {
        return 1;
    }
    StringBuilder sb = new StringBuilder();
    if (manager.equals("blocks")) {
        dm.getKeys().forEach(state -> {
            try {
                List<FragilityData> fdList = (List<FragilityData>) dm.getData(state);
                fdList.forEach(fragilityData -> {
                    sb.append(dm.stringifyBehaviours(state, null, false));
                    sb.append("\n");
                });
            } catch (NullPointerException npe) {
                source.sendFeedback(new StringTextComponent("No existing block state data for " + KeyParser.cleanBlockStateString(state.toString())), false);
            }
        });
    } else if (manager.equals("entities")) {
        dm.getKeys().forEach(type -> {
            try {
                sb.append(dm.stringifyBehaviours(type, null, false));
                sb.append("\n");
            } catch (NullPointerException npe) {
                source.sendFeedback(new StringTextComponent("No existing entity data for " + ((EntityType) type).getRegistryName()), false);
            }
        });
    } else {
        // "tileentities"
        dm.getKeys().forEach(type -> {
            try {
                List<FragilityData> fdList = (List<FragilityData>) dm.getData(type);
                fdList.forEach(fragilityData -> {
                    sb.append(dm.stringifyBehaviours(type, null, false));
                    sb.append("\n");
                });
            } catch (NullPointerException npe) {
                source.sendFeedback(new StringTextComponent("No existing tile entity data for " + ((TileEntityType) type).getRegistryName()), false);
            }
        });
    }
    try {
        dm.export(sb.toString());
        source.sendFeedback(new StringTextComponent("File exported successfully!"), true);
        return 0;
    } catch (IOException ioe) {
        source.sendFeedback(new StringTextComponent("File failed to export."), true);
        return 1;
    }
}
Also used : CommandSource(net.minecraft.command.CommandSource) EntityType(net.minecraft.entity.EntityType) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) List(java.util.List) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) DataManager(com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager) TileEntityType(net.minecraft.tileentity.TileEntityType) StringTextComponent(net.minecraft.util.text.StringTextComponent) IOException(java.io.IOException) KeyParser(com.fredtargaryen.fragileglass.config.behaviour.configloader.KeyParser) FragilityData(com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData) DataManager(com.fredtargaryen.fragileglass.config.behaviour.datamanager.DataManager) List(java.util.List) StringTextComponent(net.minecraft.util.text.StringTextComponent) IOException(java.io.IOException) FragilityData(com.fredtargaryen.fragileglass.config.behaviour.data.FragilityData)

Example 35 with EntityType

use of net.minecraft.entity.EntityType in project Mekanism by mekanism.

the class SpawnHelper method onBiomeLoad.

public static void onBiomeLoad(BiomeLoadingEvent event) {
    // Add spawns to any biomes that have mob spawns for the "parent" types of our mobs
    MobSpawnInfoBuilder spawns = event.getSpawns();
    List<MobSpawnInfo.Spawners> monsterSpawns = spawns.getSpawner(EntityClassification.MONSTER);
    if (!monsterSpawns.isEmpty()) {
        // Fail quick if no monsters can spawn in this biome anyway
        ResourceLocation biomeName = event.getName();
        getSpawnConfigs().filter(spawnConfig -> spawnConfig.shouldSpawn.get() && !spawnConfig.biomeBlackList.get().contains(biomeName)).forEach(spawnConfig -> {
            EntityType<?> parent = spawnConfig.parentTypeProvider.getEntityType();
            monsterSpawns.stream().filter(monsterSpawn -> monsterSpawn.type == parent).findFirst().ifPresent(parentEntry -> {
                // If the adult mob can spawn in this biome let the baby mob spawn in it
                // Note: We adjust the mob's spawning based on the adult's spawn rates
                MobSpawnInfo.Spawners spawner = getSpawner(spawnConfig, parentEntry);
                spawns.addSpawn(EntityClassification.MONSTER, spawner);
                MobSpawnInfo.SpawnCosts parentCost = spawns.getCost(parent);
                if (parentCost == null) {
                    Mekanism.logger.debug("Adding spawn rate for '{}' in biome '{}', with weight: {}, minSize: {}, maxSize: {}", spawner.type.getRegistryName(), biomeName, spawner.weight, spawner.minCount, spawner.maxCount);
                } else {
                    double spawnCostPerEntity = parentCost.getCharge() * spawnConfig.spawnCostPerEntityPercentage.get();
                    double maxSpawnCost = parentCost.getEnergyBudget() * spawnConfig.maxSpawnCostPercentage.get();
                    spawns.addMobCharge(spawner.type, spawnCostPerEntity, maxSpawnCost);
                    Mekanism.logger.debug("Adding spawn rate for '{}' in biome '{}', with weight: {}, minSize: {}, maxSize: {}, spawnCostPerEntity: {}, maxSpawnCost: {}", spawner.type.getRegistryName(), biomeName, spawner.weight, spawner.minCount, spawner.maxCount, spawnCostPerEntity, maxSpawnCost);
                }
            });
        });
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) Mekanism(mekanism.common.Mekanism) BiomeLoadingEvent(net.minecraftforge.event.world.BiomeLoadingEvent) AdditionsEntityTypes(mekanism.additions.common.registries.AdditionsEntityTypes) ParrotEntity(net.minecraft.entity.passive.ParrotEntity) EntityTypeRegistryObject(mekanism.common.registration.impl.EntityTypeRegistryObject) MobSpawnInfo(net.minecraft.world.biome.MobSpawnInfo) EntityBabyStray(mekanism.additions.common.entity.baby.EntityBabyStray) MobSpawnInfoBuilder(net.minecraftforge.common.world.MobSpawnInfoBuilder) AdditionsCommonConfig(mekanism.additions.common.config.AdditionsCommonConfig) EntityClassification(net.minecraft.entity.EntityClassification) SoundEvents(net.minecraft.util.SoundEvents) List(java.util.List) Stream(java.util.stream.Stream) EntitySpawnPlacementRegistry(net.minecraft.entity.EntitySpawnPlacementRegistry) MekanismAdditionsConfig(mekanism.additions.common.config.MekanismAdditionsConfig) ResourceLocation(net.minecraft.util.ResourceLocation) StructureSpawnListGatherEvent(net.minecraftforge.event.world.StructureSpawnListGatherEvent) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) Heightmap(net.minecraft.world.gen.Heightmap) MobSpawnInfoBuilder(net.minecraftforge.common.world.MobSpawnInfoBuilder) ResourceLocation(net.minecraft.util.ResourceLocation) MobSpawnInfo(net.minecraft.world.biome.MobSpawnInfo)

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