Search in sources :

Example 1 with EnumCreatureType

use of net.minecraft.entity.EnumCreatureType in project Tropicraft by Tropicraft.

the class TropiWorldEntitySpawner method findChunksForSpawning.

/**
 * adds all chunks within the spawn radius of the players to eligibleChunksForSpawning. pars: the world,
 * hostileCreatures, passiveCreatures. returns number of eligible chunks.
 */
public int findChunksForSpawning(WorldServer worldServerIn, boolean spawnHostileMobs, boolean spawnPeacefulMobs, boolean spawnOnSetTickRate) {
    if (!spawnHostileMobs && !spawnPeacefulMobs) {
        return 0;
    } else {
        this.eligibleChunksForSpawning.clear();
        int i = 0;
        for (EntityPlayer entityplayer : worldServerIn.playerEntities) {
            if (!entityplayer.isSpectator()) {
                int j = MathHelper.floor(entityplayer.posX / 16.0D);
                int k = MathHelper.floor(entityplayer.posZ / 16.0D);
                int l = 8;
                for (int i1 = -8; i1 <= 8; ++i1) {
                    for (int j1 = -8; j1 <= 8; ++j1) {
                        boolean flag = i1 == -8 || i1 == 8 || j1 == -8 || j1 == 8;
                        ChunkPos chunkpos = new ChunkPos(i1 + j, j1 + k);
                        if (!this.eligibleChunksForSpawning.contains(chunkpos)) {
                            ++i;
                            if (!flag && worldServerIn.getWorldBorder().contains(chunkpos)) {
                                PlayerChunkMapEntry playerchunkmapentry = worldServerIn.getPlayerChunkMap().getEntry(chunkpos.x, chunkpos.z);
                                if (playerchunkmapentry != null && playerchunkmapentry.isSentToPlayers()) {
                                    this.eligibleChunksForSpawning.add(chunkpos);
                                }
                            }
                        }
                    }
                }
            }
        }
        int j4 = 0;
        BlockPos blockpos1 = worldServerIn.getSpawnPoint();
        for (EnumCreatureType enumcreaturetype : EnumCreatureType.values()) {
            if ((!enumcreaturetype.getPeacefulCreature() || spawnPeacefulMobs) && (enumcreaturetype.getPeacefulCreature() || spawnHostileMobs) && (!enumcreaturetype.getAnimal() || spawnOnSetTickRate)) {
                int k4 = worldServerIn.countEntities(enumcreaturetype, true);
                int newMax = enumcreaturetype.getMaxNumberOfCreature();
                // fix for tropi counts
                if (enumcreaturetype == EnumCreatureType.MONSTER) {
                    // default is 70
                    newMax = 35;
                } else if (enumcreaturetype == EnumCreatureType.CREATURE) {
                // default is 10
                // newMax = 10;
                } else if (enumcreaturetype == EnumCreatureType.AMBIENT) {
                // default is 15
                } else if (enumcreaturetype == EnumCreatureType.WATER_CREATURE) {
                // default is 5
                }
                int l4 = newMax * i / MOB_COUNT_DIV;
                if (k4 <= l4) {
                    java.util.ArrayList<ChunkPos> shuffled = com.google.common.collect.Lists.newArrayList(this.eligibleChunksForSpawning);
                    java.util.Collections.shuffle(shuffled);
                    BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
                    label411: for (ChunkPos chunkpos1 : shuffled) {
                        BlockPos blockpos = getRandomChunkPosition(worldServerIn, chunkpos1.x, chunkpos1.z);
                        int k1 = blockpos.getX();
                        int l1 = blockpos.getY();
                        int i2 = blockpos.getZ();
                        IBlockState iblockstate = worldServerIn.getBlockState(blockpos);
                        if (!iblockstate.isNormalCube()) {
                            int j2 = 0;
                            for (int k2 = 0; k2 < 3; ++k2) {
                                int l2 = k1;
                                int i3 = l1;
                                int j3 = i2;
                                int k3 = 6;
                                Biome.SpawnListEntry biome$spawnlistentry = null;
                                IEntityLivingData ientitylivingdata = null;
                                int l3 = MathHelper.ceil(Math.random() * 4.0D);
                                for (int i4 = 0; i4 < l3; ++i4) {
                                    l2 += worldServerIn.rand.nextInt(6) - worldServerIn.rand.nextInt(6);
                                    i3 += worldServerIn.rand.nextInt(1) - worldServerIn.rand.nextInt(1);
                                    j3 += worldServerIn.rand.nextInt(6) - worldServerIn.rand.nextInt(6);
                                    blockpos$mutableblockpos.setPos(l2, i3, j3);
                                    float f = (float) l2 + 0.5F;
                                    float f1 = (float) j3 + 0.5F;
                                    if (!worldServerIn.isAnyPlayerWithinRangeAt((double) f, (double) i3, (double) f1, 24.0D) && blockpos1.distanceSq((double) f, (double) i3, (double) f1) >= 576.0D) {
                                        if (biome$spawnlistentry == null) {
                                            biome$spawnlistentry = worldServerIn.getSpawnListEntryForTypeAt(enumcreaturetype, blockpos$mutableblockpos);
                                            if (biome$spawnlistentry == null) {
                                                break;
                                            }
                                        }
                                        if (worldServerIn.canCreatureTypeSpawnHere(enumcreaturetype, biome$spawnlistentry, blockpos$mutableblockpos) && canCreatureTypeSpawnAtLocation(EntitySpawnPlacementRegistry.getPlacementForEntity(biome$spawnlistentry.entityClass), worldServerIn, blockpos$mutableblockpos)) {
                                            EntityLiving entityliving;
                                            try {
                                                entityliving = (EntityLiving) biome$spawnlistentry.newInstance(worldServerIn);
                                            } catch (Exception exception) {
                                                exception.printStackTrace();
                                                return j4;
                                            }
                                            entityliving.setLocationAndAngles((double) f, (double) i3, (double) f1, worldServerIn.rand.nextFloat() * 360.0F, 0.0F);
                                            // if (canSpawn == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW || (canSpawn == net.minecraftforge.fml.common.eventhandler.Event.Result.DEFAULT && (entityliving.getCanSpawnHere() && entityliving.isNotColliding())))
                                            if ((entityliving.getCanSpawnHere() && entityliving.isNotColliding())) {
                                                if (!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(entityliving, worldServerIn, f, i3, f1))
                                                    ientitylivingdata = entityliving.onInitialSpawn(worldServerIn.getDifficultyForLocation(new BlockPos(entityliving)), ientitylivingdata);
                                                if (entityliving.isNotColliding()) {
                                                    ++j2;
                                                    worldServerIn.spawnEntity(entityliving);
                                                } else {
                                                    entityliving.setDead();
                                                }
                                                if (j2 >= net.minecraftforge.event.ForgeEventFactory.getMaxSpawnPackSize(entityliving)) {
                                                    continue label411;
                                                }
                                            }
                                            j4 += j2;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return j4;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumCreatureType(net.minecraft.entity.EnumCreatureType) EntityLiving(net.minecraft.entity.EntityLiving) IEntityLivingData(net.minecraft.entity.IEntityLivingData) PlayerChunkMapEntry(net.minecraft.server.management.PlayerChunkMapEntry) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with EnumCreatureType

use of net.minecraft.entity.EnumCreatureType in project BiomesOPlenty by Glitchfiend.

the class BOPBiome method configure.

@Override
public void configure(IConfigObj conf) {
    this.topBlock = conf.getBlockState("topBlock", this.topBlock);
    this.fillerBlock = conf.getBlockState("fillerBlock", this.fillerBlock);
    this.skyColor = conf.getInt("skyColor", this.skyColor);
    this.fogColor = conf.getInt("fogColor", this.fogColor);
    this.fogDensity = conf.getFloat("fogDensity", this.fogDensity);
    this.hasBiomeEssence = conf.getBool("hasBiomeEssence", this.hasBiomeEssence);
    // Allow weights to be overridden
    IConfigObj confWeights = conf.getObject("weights");
    for (BOPClimates climate : BOPClimates.values()) {
        Integer weight = confWeights.getInt(climate.name().toLowerCase(), this.weightMap.get(climate));
        if (weight == null) {
            continue;
        }
        if (weight.intValue() < 1) {
            this.weightMap.remove(climate);
        } else {
            this.weightMap.put(climate, weight);
        }
    }
    // Allow generators to be configured
    IConfigObj confGenerators = conf.getObject("generators");
    this.generationManager.configure(confGenerators);
    // Allow spawnable entites to be configured
    ArrayList<IConfigObj> confEntities = conf.getObjectArray("entities");
    if (confEntities != null) {
        for (IConfigObj confEntity : confEntities) {
            String entityName = confEntity.getString("name");
            EnumCreatureType creatureType = confEntity.getEnum("creatureType", EnumCreatureType.class);
            if (entityName == null || creatureType == null) {
                continue;
            }
            // Look for an entity class matching this name
            // case insensitive, dot used as mod delimiter, no spaces or underscores
            // eg  'villager', 'Zombie', 'SQUID', 'enderdragon', 'biomesoplenty.wasp' all ok
            Class<? extends Entity> entityClazz = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(entityName)).getEntityClass();
            Class<? extends EntityLiving> livingClazz = null;
            if (!(entityClazz.isAssignableFrom(EntityLiving.class))) {
                confEntity.addMessage("Entity " + entityName + " is not of type EntityLiving");
                continue;
            } else {
                livingClazz = (Class<? extends EntityLiving>) entityClazz;
            }
            if (livingClazz == null) {
                confEntity.addMessage("No entity registered called " + entityName);
                continue;
            }
            if (!creatureType.getCreatureClass().isAssignableFrom(livingClazz)) {
                confEntity.addMessage("Entity " + entityName + " is not of type " + creatureType);
                continue;
            }
            List<SpawnListEntry> spawns = this.getSpawnableList(creatureType);
            Integer weight = confEntity.getInt("weight");
            if (weight != null && weight < 1) {
                // weight was set to zero (or negative) so find and remove this spawn
                Iterator<SpawnListEntry> spawnIterator = spawns.iterator();
                while (spawnIterator.hasNext()) {
                    SpawnListEntry entry = spawnIterator.next();
                    if (entry.entityClass == livingClazz) {
                        spawnIterator.remove();
                    }
                }
            } else {
                // weight was positive, or omitted, so update an existing spawn or add a new spawn
                boolean foundIt = false;
                for (SpawnListEntry entry : spawns) {
                    if (entry.entityClass == entityClazz) {
                        // the entry already exists - adjust the params
                        entry.itemWeight = confEntity.getInt("weight", entry.itemWeight);
                        entry.minGroupCount = confEntity.getInt("minGroupCount", entry.minGroupCount);
                        entry.maxGroupCount = confEntity.getInt("maxGroupCount", entry.maxGroupCount);
                        foundIt = true;
                    }
                }
                if (!foundIt) {
                    // the entry does not exist - add it
                    SpawnListEntry entry = new SpawnListEntry(livingClazz, confEntity.getInt("weight", 10), confEntity.getInt("minGroupCount", 4), confEntity.getInt("maxGroupCount", 4));
                    spawns.add(entry);
                }
            }
        }
    }
}
Also used : EnumCreatureType(net.minecraft.entity.EnumCreatureType) ResourceLocation(net.minecraft.util.ResourceLocation) IConfigObj(biomesoplenty.api.config.IConfigObj) BOPClimates(biomesoplenty.api.enums.BOPClimates)

Example 3 with EnumCreatureType

use of net.minecraft.entity.EnumCreatureType in project SpongeCommon by SpongePowered.

the class MixinEntity method onConstruction.

@Inject(method = "<init>", at = @At("RETURN"))
public void onConstruction(net.minecraft.world.World worldIn, CallbackInfo ci) {
    if (this.entityType instanceof SpongeEntityType) {
        SpongeEntityType spongeEntityType = (SpongeEntityType) this.entityType;
        if (spongeEntityType.getEnumCreatureType() == null) {
            for (EnumCreatureType type : EnumCreatureType.values()) {
                if (SpongeImplHooks.isCreatureOfType((net.minecraft.entity.Entity) (Object) this, type)) {
                    spongeEntityType.setEnumCreatureType(type);
                    break;
                }
            }
        }
    }
    if (worldIn != null && !worldIn.isRemote) {
        this.spongeProfileManager = ((SpongeProfileManager) Sponge.getServer().getGameProfileManager());
        this.userStorageService = SpongeImpl.getGame().getServiceManager().provide(UserStorageService.class).get();
    }
}
Also used : EnumCreatureType(net.minecraft.entity.EnumCreatureType) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) SpongeProfileManager(org.spongepowered.common.profile.SpongeProfileManager) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with EnumCreatureType

use of net.minecraft.entity.EnumCreatureType in project SpongeCommon by SpongePowered.

the class MixinWorldEntitySpawner method findChunksForSpawning.

/**
 * @author blood - February 18th, 2017
 * @reason Refactor entire method for optimizations and spawn limits.
 *
 * @param worldServerIn The world
 * @param spawnHostileMobs If hostile entities can spawn
 * @param spawnPeacefulMobs If passive entities can spawn
 * @param spawnOnSetTickRate If tickrate has been reached for spawning passives
 * @return The amount of entities spawned
 */
@Overwrite
public int findChunksForSpawning(WorldServer worldServerIn, boolean spawnHostileMobs, boolean spawnPeacefulMobs, boolean spawnOnSetTickRate) {
    if (!spawnHostileMobs && !spawnPeacefulMobs) {
        return 0;
    }
    try (PhaseContext<?> context = GenerationPhase.State.WORLD_SPAWNER_SPAWNING.createPhaseContext().world(worldServerIn).buildAndSwitch()) {
        Iterator<Chunk> chunkIterator = this.eligibleSpawnChunks.iterator();
        while (chunkIterator.hasNext()) {
            Chunk chunk = chunkIterator.next();
            ((IMixinChunk) chunk).setIsSpawning(false);
            chunkIterator.remove();
        }
        IMixinWorldServer spongeWorld = ((IMixinWorldServer) worldServerIn);
        spongeWorld.getTimingsHandler().mobSpawn.startTiming();
        int chunkSpawnCandidates = 0;
        final int mobSpawnRange = Math.min(((IMixinWorldServer) worldServerIn).getActiveConfig().getConfig().getWorld().getMobSpawnRange(), ((org.spongepowered.api.world.World) worldServerIn).getViewDistance());
        // Vanilla uses a div count of 289 (17x17) which assumes the view distance is 8.
        // Since we allow for custom ranges, we need to adjust the div count based on the
        // mob spawn range set by server.
        final int MOB_SPAWN_COUNT_DIV = (2 * mobSpawnRange + 1) * (2 * mobSpawnRange + 1);
        for (EntityPlayer entityplayer : worldServerIn.playerEntities) {
            // We treat players who do not affect spawning as "spectators"
            if (!((IMixinEntityPlayer) entityplayer).affectsSpawning() || entityplayer.isSpectator()) {
                continue;
            }
            int playerPosX = MathHelper.floor(entityplayer.posX / 16.0D);
            int playerPosZ = MathHelper.floor(entityplayer.posZ / 16.0D);
            for (int i = -mobSpawnRange; i <= mobSpawnRange; ++i) {
                for (int j = -mobSpawnRange; j <= mobSpawnRange; ++j) {
                    boolean flag = i == -mobSpawnRange || i == mobSpawnRange || j == -mobSpawnRange || j == mobSpawnRange;
                    final Chunk chunk = ((IMixinChunkProviderServer) worldServerIn.getChunkProvider()).getLoadedChunkWithoutMarkingActive(i + playerPosX, j + playerPosZ);
                    if (chunk == null || (chunk.unloadQueued && !((IMixinChunk) chunk).isPersistedChunk())) {
                        // Don't attempt to spawn in an unloaded chunk
                        continue;
                    }
                    final IMixinChunk spongeChunk = (IMixinChunk) chunk;
                    ++chunkSpawnCandidates;
                    final ChunkPos chunkPos = chunk.getPos();
                    if (!flag && worldServerIn.getWorldBorder().contains(chunkPos)) {
                        PlayerChunkMapEntry playerchunkmapentry = worldServerIn.getPlayerChunkMap().getEntry(chunkPos.x, chunkPos.z);
                        if (playerchunkmapentry != null && playerchunkmapentry.isSentToPlayers() && !spongeChunk.isSpawning()) {
                            this.eligibleSpawnChunks.add(chunk);
                            spongeChunk.setIsSpawning(true);
                        }
                    }
                }
            }
        }
        // If there are no eligible chunks, return early
        if (this.eligibleSpawnChunks.size() == 0) {
            spongeWorld.getTimingsHandler().mobSpawn.stopTiming();
            return 0;
        }
        int totalSpawned = 0;
        final long worldTotalTime = worldServerIn.getTotalWorldTime();
        final SpongeConfig<? extends GeneralConfigBase> activeConfig = ((IMixinWorldServer) worldServerIn).getActiveConfig();
        labelOuterLoop: for (EnumCreatureType enumCreatureType : EnumCreatureType.values()) {
            int limit = 0;
            int tickRate = 0;
            if (enumCreatureType == EnumCreatureType.MONSTER) {
                limit = activeConfig.getConfig().getSpawner().getMonsterSpawnLimit();
                tickRate = activeConfig.getConfig().getSpawner().getMonsterTickRate();
            } else if (enumCreatureType == EnumCreatureType.CREATURE) {
                limit = activeConfig.getConfig().getSpawner().getAnimalSpawnLimit();
                tickRate = activeConfig.getConfig().getSpawner().getAnimalTickRate();
            } else if (enumCreatureType == EnumCreatureType.WATER_CREATURE) {
                limit = activeConfig.getConfig().getSpawner().getAquaticSpawnLimit();
                tickRate = activeConfig.getConfig().getSpawner().getAquaticTickRate();
            } else if (enumCreatureType == EnumCreatureType.AMBIENT) {
                limit = activeConfig.getConfig().getSpawner().getAmbientSpawnLimit();
                tickRate = activeConfig.getConfig().getSpawner().getAmbientTickRate();
            }
            if (limit == 0 || tickRate == 0 || (worldTotalTime % tickRate) != 0L) {
                continue;
            }
            if ((!enumCreatureType.getPeacefulCreature() || spawnPeacefulMobs) && (enumCreatureType.getPeacefulCreature() || spawnHostileMobs)) {
                int entityCount = SpongeImplHooks.countEntities(worldServerIn, enumCreatureType, true);
                int maxCount = limit * chunkSpawnCandidates / MOB_SPAWN_COUNT_DIV;
                if (entityCount > maxCount) {
                    continue labelOuterLoop;
                }
                chunkIterator = this.eligibleSpawnChunks.iterator();
                int mobLimit = maxCount - entityCount + 1;
                labelChunkStart: while (chunkIterator.hasNext() && mobLimit > 0) {
                    final Chunk chunk = chunkIterator.next();
                    final BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
                    final BlockPos blockpos = getRandomChunkPosition(worldServerIn, chunk);
                    int k1 = blockpos.getX();
                    int l1 = blockpos.getY();
                    int i2 = blockpos.getZ();
                    IBlockState iblockstate = worldServerIn.getBlockState(blockpos);
                    if (!iblockstate.isNormalCube()) {
                        int spawnCount = 0;
                        for (int spawnLimit = 0; spawnLimit < 3; ++spawnLimit) {
                            int l2 = k1;
                            int i3 = l1;
                            int j3 = i2;
                            Biome.SpawnListEntry spawnListEntry = null;
                            IEntityLivingData ientitylivingdata = null;
                            int l3 = MathHelper.ceil(Math.random() * 4.0D);
                            for (int i4 = 0; i4 < l3; ++i4) {
                                l2 += worldServerIn.rand.nextInt(6) - worldServerIn.rand.nextInt(6);
                                i3 += worldServerIn.rand.nextInt(1) - worldServerIn.rand.nextInt(1);
                                j3 += worldServerIn.rand.nextInt(6) - worldServerIn.rand.nextInt(6);
                                mutableBlockPos.setPos(l2, i3, j3);
                                final double spawnX = l2 + 0.5F;
                                final double spawnY = i3;
                                final double spawnZ = j3 + 0.5F;
                                if (!worldServerIn.isAnyPlayerWithinRangeAt(spawnX, spawnY, spawnZ, 24.0D) && worldServerIn.getSpawnPoint().distanceSq(spawnX, spawnY, spawnZ) >= 576.0D) {
                                    if (spawnListEntry == null) {
                                        spawnListEntry = worldServerIn.getSpawnListEntryForTypeAt(enumCreatureType, mutableBlockPos);
                                        if (spawnListEntry == null) {
                                            break;
                                        }
                                    }
                                    final EntityType entityType = EntityTypeRegistryModule.getInstance().getForClass(spawnListEntry.entityClass);
                                    if (entityType != null) {
                                        Vector3d vector3d = new Vector3d(spawnX, spawnY, spawnZ);
                                        Transform<org.spongepowered.api.world.World> transform = new Transform<>((org.spongepowered.api.world.World) worldServerIn, vector3d);
                                        ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(Sponge.getCauseStackManager().getCurrentCause(), entityType, transform);
                                        if (SpongeImpl.postEvent(event)) {
                                            continue;
                                        }
                                    }
                                    if (worldServerIn.canCreatureTypeSpawnHere(enumCreatureType, spawnListEntry, mutableBlockPos) && WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntitySpawnPlacementRegistry.getPlacementForEntity(spawnListEntry.entityClass), worldServerIn, mutableBlockPos)) {
                                        EntityLiving entityliving;
                                        try {
                                            entityliving = spawnListEntry.entityClass.getConstructor(new Class<?>[] { World.class }).newInstance(worldServerIn);
                                        } catch (Exception exception) {
                                            exception.printStackTrace();
                                            continue labelOuterLoop;
                                        }
                                        entityliving.setLocationAndAngles(spawnX, spawnY, spawnZ, worldServerIn.rand.nextFloat() * 360.0F, 0.0F);
                                        final boolean entityNotColliding = entityliving.isNotColliding();
                                        final SpawnerSpawnType type = SpongeImplHooks.canEntitySpawnHere(entityliving, entityNotColliding);
                                        if (type != SpawnerSpawnType.NONE) {
                                            if (type == SpawnerSpawnType.NORMAL) {
                                                ientitylivingdata = entityliving.onInitialSpawn(worldServerIn.getDifficultyForLocation(new BlockPos(entityliving)), ientitylivingdata);
                                            }
                                            if (entityNotColliding) {
                                                ++spawnCount;
                                                worldServerIn.spawnEntity(entityliving);
                                            } else {
                                                entityliving.setDead();
                                            }
                                            mobLimit--;
                                            if (mobLimit <= 0 || spawnCount >= SpongeImplHooks.getMaxSpawnPackSize(entityliving)) {
                                                continue labelChunkStart;
                                            }
                                        }
                                        totalSpawned += spawnCount;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        spongeWorld.getTimingsHandler().mobSpawn.stopTiming();
        return totalSpawned;
    }
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) World(net.minecraft.world.World) Biome(net.minecraft.world.biome.Biome) SpawnerSpawnType(org.spongepowered.common.util.SpawnerSpawnType) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) IMixinEntityPlayer(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayer) IBlockState(net.minecraft.block.state.IBlockState) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) EnumCreatureType(net.minecraft.entity.EnumCreatureType) IEntityLivingData(net.minecraft.entity.IEntityLivingData) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) PlayerChunkMapEntry(net.minecraft.server.management.PlayerChunkMapEntry) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) EntityType(org.spongepowered.api.entity.EntityType) ConstructEntityEvent(org.spongepowered.api.event.entity.ConstructEntityEvent) Vector3d(com.flowpowered.math.vector.Vector3d) IMixinEntityPlayer(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Transform(org.spongepowered.api.entity.Transform) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 5 with EnumCreatureType

use of net.minecraft.entity.EnumCreatureType in project BiomeTweaker by superckl.

the class ScriptCommandCreateBiome method perform.

@Override
public void perform() throws Exception {
    if (RegistryEventHandler.registry == null)
        throw new IllegalStateException("No biome registry avilable! Make sure you're using the biome registry script stage!");
    if (this.toCopy == null) {
        final BiomeTweakerBiome biome = new BiomeTweakerBiome(new BiomeProperties("BiomeTweaker Biome").setBaseHeight(0.125F).setHeightVariation(0.05F).setTemperature(0.8F).setRainfall(0.4F));
        if (!MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.Create(this, biome))) {
            biome.setRegistryName(ModData.MOD_ID, this.rLoc.toLowerCase());
            RegistryEventHandler.registry.register(biome);
            BiomeTweaker.getInstance().onTweak(Biome.getIdForBiome(biome));
        }
    } else {
        final Iterator<Biome> it = this.toCopy.getIterator();
        if (!it.hasNext())
            throw new IllegalStateException("No biome found to copy!");
        final Biome toCopy = it.next();
        if (it.hasNext())
            LogHelper.warn("More than one biome found to copy! Only the first one will be copied.");
        Constructor<? extends Biome> construct = null;
        try {
            // catches all vanilla biomes
            if (ScriptCommandCreateBiome.extraParameters.containsKey(toCopy.getBiomeClass())) {
                final List<? extends Property<?>> props = ScriptCommandCreateBiome.extraParameters.get(toCopy.getBiomeClass());
                final Class<?>[] types = new Class<?>[props.size() + 1];
                for (int i = 0; i < props.size(); i++) types[i] = Primitives.unwrap(props.get(i).getTypeClass());
                types[types.length - 1] = BiomeProperties.class;
                construct = toCopy.getBiomeClass().getConstructor(types);
            } else
                construct = toCopy.getBiomeClass().getConstructor(BiomeProperties.class);
        } catch (final Exception e) {
            try {
                // Catches most BOP biomes
                construct = toCopy.getBiomeClass().getConstructor();
            } catch (final Exception e1) {
            }
        }
        Biome biome;
        if (construct == null) {
            LogHelper.warn("Unable to copy biome class " + toCopy.getBiomeClass().getCanonicalName() + "! Some functionality may not be copied!");
            biome = new BiomeTweakerBiome(new BiomeProperties("BiomeTweaker Biome").setBaseHeight(0.125F).setHeightVariation(0.05F).setTemperature(0.8F).setRainfall(0.4F));
        } else
            switch(construct.getParameterCount()) {
                case 0:
                    biome = construct.newInstance();
                    break;
                case 1:
                    biome = construct.newInstance(new BiomeProperties(toCopy.getBiomeName()));
                    break;
                default:
                    final List<? extends Property<?>> props = ScriptCommandCreateBiome.extraParameters.get(toCopy.getBiomeClass());
                    final Object[] objs = new Object[props.size() + 1];
                    for (int i = 0; i < props.size(); i++) objs[i] = props.get(i).get(toCopy);
                    objs[objs.length - 1] = new BiomeProperties(toCopy.getBiomeName());
                    biome = construct.newInstance(objs);
                    break;
            }
        if (MinecraftForge.EVENT_BUS.post(new BiomeTweakEvent.Create(this, biome)))
            return;
        biome.setRegistryName(ModData.MOD_ID, this.rLoc.toLowerCase());
        RegistryEventHandler.registry.register(biome);
        // Copy props
        for (final Property<?> prop : BiomePropertyManager.getAllProperties()) if (prop.isCopyable())
            prop.copy(toCopy, biome);
        // Copy dict types
        if (BiomeDictionary.hasAnyType(toCopy))
            BiomeDictionary.addTypes(biome, BiomeDictionary.getTypes(toCopy).toArray(new BiomeDictionary.Type[0]));
        // Copy spawns
        for (final EnumCreatureType type : EnumCreatureType.values()) {
            final List<SpawnListEntry> entries = biome.getSpawnableList(type);
            entries.clear();
            entries.addAll(toCopy.getSpawnableList(type));
        }
        BiomeTweaker.getInstance().onTweak(Biome.getIdForBiome(biome));
    }
}
Also used : BiomeTweakEvent(me.superckl.api.biometweaker.event.BiomeTweakEvent) EnumCreatureType(net.minecraft.entity.EnumCreatureType) BiomeProperties(net.minecraft.world.biome.Biome.BiomeProperties) SpawnListEntry(net.minecraft.world.biome.Biome.SpawnListEntry) BiomeTweakerBiome(me.superckl.biometweaker.common.world.biome.BiomeTweakerBiome) Biome(net.minecraft.world.biome.Biome) BiomeTweakerBiome(me.superckl.biometweaker.common.world.biome.BiomeTweakerBiome) BiomeDictionary(net.minecraftforge.common.BiomeDictionary) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Property(me.superckl.api.biometweaker.property.Property)

Aggregations

EnumCreatureType (net.minecraft.entity.EnumCreatureType)6 IBlockState (net.minecraft.block.state.IBlockState)3 EntityLiving (net.minecraft.entity.EntityLiving)3 IEntityLivingData (net.minecraft.entity.IEntityLivingData)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 PlayerChunkMapEntry (net.minecraft.server.management.PlayerChunkMapEntry)3 BlockPos (net.minecraft.util.math.BlockPos)3 ChunkPos (net.minecraft.util.math.ChunkPos)3 Biome (net.minecraft.world.biome.Biome)2 IConfigObj (biomesoplenty.api.config.IConfigObj)1 BOPClimates (biomesoplenty.api.enums.BOPClimates)1 Vector3d (com.flowpowered.math.vector.Vector3d)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 BiomeTweakEvent (me.superckl.api.biometweaker.event.BiomeTweakEvent)1 Property (me.superckl.api.biometweaker.property.Property)1 BiomeTweakerBiome (me.superckl.biometweaker.common.world.biome.BiomeTweakerBiome)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)1 World (net.minecraft.world.World)1