net.minecraft.world.EnumDifficulty Java Examples

The following examples show how to use net.minecraft.world.EnumDifficulty. 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: MobSpawnEventHandler.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
public MobSpawnEventHandler() {

    ezHealthMods.put(EnumDifficulty.PEACEFUL, 1d);
    ezHealthMods.put(EnumDifficulty.EASY, Config.enderZooEasyHealthModifier);
    ezHealthMods.put(EnumDifficulty.NORMAL, Config.enderZooNormalHealthModifier);
    ezHealthMods.put(EnumDifficulty.HARD, Config.enderZooHardHealthModifier);
    ezAttackMods.put(EnumDifficulty.PEACEFUL, 1d);
    ezAttackMods.put(EnumDifficulty.EASY, Config.enderZooEasyAttackModifier);
    ezAttackMods.put(EnumDifficulty.NORMAL, Config.enderZooNormalAttackModifier);
    ezAttackMods.put(EnumDifficulty.HARD, Config.enderZooHardAttackModifier);

    otherHealthMods.put(EnumDifficulty.PEACEFUL, 1d);
    otherHealthMods.put(EnumDifficulty.EASY, Config.globalEasyHealthModifier);
    otherHealthMods.put(EnumDifficulty.NORMAL, Config.globalNormalHealthModifier);
    otherHealthMods.put(EnumDifficulty.HARD, Config.globalHardHealthModifier);
    otherAttackMods.put(EnumDifficulty.PEACEFUL, 1d);
    otherAttackMods.put(EnumDifficulty.EASY, Config.globalEasyAttackModifier);
    otherAttackMods.put(EnumDifficulty.NORMAL, Config.globalNormalAttackModifier);
    otherAttackMods.put(EnumDifficulty.HARD, Config.globalHardAttackModifier);

  }
 
Example #3
Source File: EntitySpawnHandler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onEntitySpawn(LivingSpawnEvent.SpecialSpawn event) {
    EntityLivingBase entity = event.getEntityLiving();
    EnumDifficulty difficulty = entity.world.getDifficulty();
    if (difficulty == EnumDifficulty.HARD && entity.getRNG().nextFloat() <= 0.03f) {
        if (entity instanceof EntityZombie) {
            ItemStack itemStack = MetaItems.NANO_SABER.getInfiniteChargedStack();
            ToggleEnergyConsumerBehavior.setItemActive(itemStack, true);
            entity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, itemStack);
            ((EntityZombie) entity).setDropChance(EntityEquipmentSlot.MAINHAND, 0.0f);
        }
    }
}
 
Example #4
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 #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) {
    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 #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) {
    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 #7
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 #8
Source File: EntityMonolithEye.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the task
 */
public void updateTask() {
	EntityLivingBase entitylivingbase = this.theEntity.getAttackTarget();
	this.theEntity.getNavigator().clearPath();
	this.theEntity.getLookHelper().setLookPositionWithEntity(entitylivingbase, 90.0F, 90.0F);

	if (!this.theEntity.canEntityBeSeen(entitylivingbase)) {
		this.theEntity.setAttackTarget((EntityLivingBase) null);
	} else {
		++this.tickCounter;

		if (this.tickCounter == 0) {
			this.theEntity.setTargetedEntity(this.theEntity.getAttackTarget().getEntityId());
			// this.theEntity.world.setEntityState(this.theEntity,
			// (byte) 21);
		} else if (this.tickCounter >= this.theEntity.getAttackDuration()) {
			float damage = 3.0F;

			if (this.theEntity.world.getDifficulty() == EnumDifficulty.HARD) {
				damage += 3.0F;
			}

			DamageSource ds = DamageSource.causeIndirectMagicDamage(this.theEntity, this.theEntity);

			entitylivingbase.attackEntityFrom(ds, damage);
			entitylivingbase.attackEntityFrom(DamageSource.causeMobDamage(this.theEntity),
					(float) this.theEntity.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue());
			theEntity.attackedTarget = theEntity.getAttackTarget();
			theEntity.setAttackTarget((EntityLivingBase) null);
			theEntity.world.setEntityState(theEntity, (byte) 15);
			theEntity.playSound(SoundEvents.ENTITY_GENERIC_EXPLODE, 1.0F, 1.0F / (theEntity.getRNG().nextFloat() * 0.4F + 0.8F));
		}

		super.updateTask();
	}
}
 
Example #9
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 #10
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 #11
Source File: FakeWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
public FakeWorld(WorldProvider provider) {
    super(FakeSaveHandler.instance, "", null, provider, new Profiler());
    theProfiler.profilingEnabled = false;
    difficultySetting = EnumDifficulty.NORMAL;
}
 
Example #12
Source File: FakeWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
public FakeWorld() {
    super(FakeSaveHandler.instance, "", null, FakeWorldProvider.instance, null);
    difficultySetting = EnumDifficulty.NORMAL;
}
 
Example #13
Source File: WorldSchematic.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
public WorldSchematic(NetHandlerPlayClient netHandler, WorldSettings settings, int dimension,
        EnumDifficulty difficulty, Profiler profilerIn)
{
    super(netHandler, settings, dimension, difficulty, profilerIn);
}
 
Example #14
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);
    }
 
Example #15
Source File: EntityFallenMount.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance di, IEntityLivingData data) {  

  setHorseArmorStack(ItemStack.EMPTY);        
  setHorseSaddled(true);    
  setGrowingAge(0);
  getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(Config.fallenMountHealth);
  getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.2);
  getAttributeMap().getAttributeInstanceByName("horse.jumpStrength").setBaseValue(0.5);
  setHealth(getMaxHealth());
  
  float chanceOfArmor = world.getDifficulty() == EnumDifficulty.HARD ? Config.fallenMountChanceArmoredHard
      : Config.fallenMountChanceArmored;
  if(rand.nextFloat() <= chanceOfArmor) {

    //Value between 0 and 1 (normal) - 1.5 based on how long a chunk has been occupied and the moon phase
    
    //float occupiedDiffcultyMultiplier = worldObj.func_147462_b(posX, posY, posZ);
    
    float occupiedDiffcultyMultiplier = di.getClampedAdditionalDifficulty();
    //TODO: Do I need this normalised still?
    occupiedDiffcultyMultiplier /= 1.5f; // normalize
    float chanceImprovedArmor = world.getDifficulty() == EnumDifficulty.HARD ? Config.fallenMountChanceArmorUpgradeHard
        : Config.fallenMountChanceArmorUpgrade;
    chanceImprovedArmor *= (1 + occupiedDiffcultyMultiplier); //If we have the max occupied factor, double the chance of improved armor

    int armorLevel = 0;
    for (int i = 0; i < 2; i++) {
      if(rand.nextFloat() <= chanceImprovedArmor) {
        armorLevel++;
      }
    }
    Item armorItem = Items.IRON_HORSE_ARMOR;
    switch (armorLevel) {
    case 1:
      armorItem = Items.GOLDEN_HORSE_ARMOR;
      break;
    case 2:
      armorItem = Items.DIAMOND_HORSE_ARMOR;
      break;
    }
    armor = new ItemStack(armorItem);
    setHorseArmorStack(armor);
  } else {
    armor = ItemStack.EMPTY;
    setHorseArmorStack(armor);
  }
  return data;
}
 
Example #16
Source File: EntityUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
public static boolean isHardDifficulty(World worldObj) {
  return worldObj.getDifficulty() == EnumDifficulty.HARD;
}
 
Example #17
Source File: CraftWorld.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public void setDifficulty(Difficulty difficulty) {
    this.getHandle().worldInfo.setDifficulty(EnumDifficulty.getDifficultyEnum(difficulty.getValue()));
}