Java Code Examples for net.minecraft.world.EnumDifficulty#PEACEFUL

The following examples show how to use net.minecraft.world.EnumDifficulty#PEACEFUL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityTofuSlime.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public boolean getCanSpawnHere() {

    if (this.world.getDifficulty() != EnumDifficulty.PEACEFUL) {
        int lightValue = this.world.getLightFromNeighbors(new BlockPos(MathHelper.floor(this.posX), MathHelper.floor(this.posY), MathHelper.floor(this.posZ)));

        if (this.dimension == TofuMain.TOFU_DIMENSION.getId() && this.rand.nextInt((int) (this.world.getLightBrightness(getPosition()) * 10 + 30)) == 0
                && this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(48.0D, 20.0D, 48.0D)).size() == 0) {

            //It does not spawn when there is a light like a torch (spawns when there is no light like a torch even if there is light in the sky)
            return this.world.getLightFor(EnumSkyBlock.BLOCK, getPosition()) < 2 + this.rand.nextInt(6) && this.baseGetCanSpawnHere();
        }

        if (this.dimension == 0 && this.rand.nextInt(10) == 0
                && isSpawnChunk(this.world, this.posX, this.posZ)
                && this.posY < 40.0D
                && lightValue <= this.rand.nextInt(10))
            return this.baseGetCanSpawnHere();
    }
    return false;
}
 
Example 2
Source File: SchematicWorldHandler.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void recreateSchematicWorld(boolean remove)
{
    if (remove)
    {
        world = null;
    }
    else
    {
        // Note: The dimension used here must have no skylight, because the custom Chunks don't have those arrays
        world = new WorldSchematic(null, SETTINGS, 1, EnumDifficulty.PEACEFUL, MC.profiler);
        //this.world.addEventListener(LitematicaRenderer.getInstance().getRenderGlobal());
    }

    LitematicaRenderer.getInstance().onSchematicWorldChanged(world);
}
 
Example 3
Source File: MaterialCache.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MaterialCache()
{
    WorldSettings settings = new WorldSettings(0L, GameType.CREATIVE, false, false, WorldType.FLAT);

    this.tempWorld = new WorldSchematic(null, settings, -1, EnumDifficulty.PEACEFUL, Minecraft.getMinecraft().profiler);
    this.checkPos = new BlockPos(8, 0, 8);

    WorldUtils.loadChunksClientWorld(this.tempWorld, this.checkPos, new Vec3i(1, 1, 1));
}
 
Example 4
Source File: TileExtendedNode.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean handleGrowingNodeSecond(boolean needUpdate) {
    if(extendedNodeType == null || extendedNodeType != ExtendedNodeType.GROWING) return needUpdate;

    if(worldObj.difficultySetting == EnumDifficulty.PEACEFUL) return needUpdate;
    if(worldObj.isRemote) return needUpdate;
    if(ticksExisted % 8 != 0) return needUpdate;

    List livingEntities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(6.0D, 6.0D, 6.0D));
    if ((livingEntities != null) && (livingEntities.size() > 0)) {
        for (Object e : livingEntities) {
            EntityLivingBase livingEntity = (EntityLivingBase) e;
            if ((livingEntity.isEntityAlive()) && (!livingEntity.isEntityInvulnerable())) {
                if(livingEntity instanceof EntityPlayer && ((EntityPlayer) livingEntity).capabilities.isCreativeMode) continue;
                if(!behavior.mayZapNow()) continue;

                ResearchHelper.distributeResearch(Gadomancy.MODID.toUpperCase() + ".GROWING_AGGRESSION", worldObj, xCoord, yCoord, zCoord, 6);

                livingEntity.attackEntityFrom(DamageSource.magic, behavior.getZapDamage());

                worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "thaumcraft:zap", 0.8F, 1.0F);

                PacketTCNodeBolt packet = new PacketTCNodeBolt(xCoord + 0.5F, yCoord + 0.5F, zCoord + 0.5F, (float) livingEntity.posX, (float) (livingEntity.posY + livingEntity.height), (float) livingEntity.posZ, 0, false);
                PacketHandler.INSTANCE.sendToAllAround(packet, new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 32.0D));
            }
        }
    }

    return needUpdate;
}
 
Example 5
Source File: AuraEffects.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void doBlockEffect(ChunkCoordinates originTile, ChunkCoordinates selectedBlock, World world) {
    EntityLiving mob = world.rand.nextBoolean() ? new EntitySkeleton(world) : new EntityZombie(world);
    if(setAndCheckPosition(mob, selectedBlock, world, true) && world.difficultySetting != EnumDifficulty.PEACEFUL) {
        for(int i = 0; i < 5; i++) {
            mob.setCurrentItemOrArmor(i, null);
        }

        int timeout = 40;
        int totalCount = (world.rand.nextInt(3) == 0 ? 1 : 0) + 2;
        do {
            int slot = mob.getEquipmentInSlot(0) == null ? 0 : (mob.getEquipmentInSlot(4) == null ? 4 : (world.rand.nextInt(3)+1));
            if(mob.getEquipmentInSlot(slot) == null) {
                ItemStack[] items = ITEMS_SOUL[slot];
                ItemStack stack = items[world.rand.nextInt(items.length)];
                if(stack.getItem() != Items.bow || mob instanceof EntitySkeleton) {
                    totalCount--;
                    mob.setCurrentItemOrArmor(slot, stack);
                    mob.setEquipmentDropChance(slot, 0);
                }
            }
            timeout--;
        } while (totalCount > 0 && timeout > 0);

        if(timeout > 0) {
            mob.addPotionEffect(new PotionEffect(Potion.invisibility.getId(), MiscUtils.ticksForMinutes(60*24*365), 1, true));

            ChunkCoordinates pos = new ChunkCoordinates((int) mob.posX, (int) mob.posY, (int) mob.posZ);
            pos = iterateDown(pos, world);
            mob.setPosition(pos.posX + 0.5, pos.posY, pos.posZ + 0.5);
            world.spawnEntityInWorld(mob);
        }
    }
}
 
Example 6
Source File: AuraEffects.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void doBlockEffect(ChunkCoordinates originTile, ChunkCoordinates selectedBlock, World world) {
    EntitySlime slime = new EntitySlime(world);
    NBTTagCompound data = new NBTTagCompound();
    slime.writeEntityToNBT(data);
    data.setInteger("Size", 0);
    slime.readEntityFromNBT(data);
    boolean canSpawn = setAndCheckPosition(slime, selectedBlock, world, true) && world.difficultySetting != EnumDifficulty.PEACEFUL;
    if(canSpawn) {
        ChunkCoordinates pos = new ChunkCoordinates((int) slime.posX, (int) slime.posY, (int) slime.posZ);
        pos = iterateDown(pos, world);
        slime.setPosition(pos.posX + 0.5, pos.posY, pos.posZ + 0.5);
        world.spawnEntityInWorld(slime);
    }
}
 
Example 7
Source File: EntityFallenMount.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@Override
public void onUpdate() {
  super.onUpdate();
  if(!world.isRemote && world.getDifficulty() == EnumDifficulty.PEACEFUL) {
    setDead();
  }
}
 
Example 8
Source File: FakeWorldClient.java    From Framez with GNU General Public License v3.0 4 votes vote down vote up
private FakeWorldClient() {

        super(new NetHandlerPlayClient(Minecraft.getMinecraft(), null, new NetworkManager(true)), new WorldSettings(0, GameType.NOT_SET,
                false, false, WorldType.DEFAULT), 0, EnumDifficulty.PEACEFUL, Minecraft.getMinecraft().theWorld.theProfiler);
    }