net.minecraft.world.DifficultyInstance Java Examples

The following examples show how to use net.minecraft.world.DifficultyInstance. 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: EntityFallenKnight.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@Override
  public IEntityLivingData onInitialSpawn(DifficultyInstance di, IEntityLivingData livingData) {
    spawned = true;

    //From base entity living class
    getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).applyModifier(new AttributeModifier("Random spawn bonus", rand.nextGaussian() * 0.05D, 1));
//    func_189768_a(SkeletonType.NORMAL);//skeleton types do not exist anymore in 1.11.2. so its always normal.
    addRandomArmor();
    setEnchantmentBasedOnDifficulty(di); //enchantEquipment();

    float f = di.getClampedAdditionalDifficulty();
    this.setCanPickUpLoot(this.rand.nextFloat() < 0.55F * f);
    setCanPickUpLoot(rand.nextFloat() < 0.55F * f);
    setCanBreakDoors(rand.nextFloat() < f * 0.1F);

    return livingData;
  }
 
Example #2
Source File: EntityFallenKnight.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
private void spawnMount() {
  
  if(isRiding() || !spawned) {
    return;
  }

  EntityFallenMount mount = null;
  if(Config.fallenMountEnabled && rand.nextFloat() <= Config.fallenKnightChanceMounted) {
    mount = new EntityFallenMount(world);
    mount.setLocationAndAngles(posX, posY, posZ, rotationYaw, 0.0F);

    DifficultyInstance di = world.getDifficultyForLocation(new BlockPos(mount));
    mount.onInitialSpawn(di, null);
    //NB: don;t check for entity collisions as we know the knight will collide
    if(!SpawnUtil.isSpaceAvailableForSpawn(world, mount, false)) {
      mount = null;
    }
  }
  if(mount != null) {
    setCanPickUpLoot(false);
    setCanBreakDoors(false);
    world.spawnEntity(mount);      
    startRiding(mount);
    
  }
}
 
Example #3
Source File: EntityGuard.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Called only once on an entity when first time spawned, via egg, mob
 * spawner, natural spawning etc, but not called when entity is reloaded
 * from nbt. Mainly used for initializing attributes and inventory
 */
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);

	setCanPickUpLoot(true);
	setEquipmentBasedOnDifficulty(difficulty);
	setEnchantmentBasedOnDifficulty(difficulty);

	setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.DIAMOND_SWORD, 1));
	setHeldItem(EnumHand.OFF_HAND, new ItemStack(Items.SHIELD, 1));

	// addArmor();

	return livingdata;
}
 
Example #4
Source File: EntityDabSquirrel.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	if (!this.isChild()) {
		int i = this.rand.nextInt(this.getVariantMax()) + 1; // Values 1 to 3
		if (i == 3 && this.rand.nextInt(4) != 0) { // 1/4 chance it remains white (overall 1/12 chance of white)
			i = this.rand.nextInt(2) + 1; // 1 - 2
		}
		if (livingdata instanceof TypeData) {
			i = ((TypeData) livingdata).typeData;
		} else {
			livingdata = new TypeData(i);
		}

		this.setType(i);
	}
	return livingdata;
}
 
Example #5
Source File: EntityTofuMindCore.java    From TofuCraftReload with MIT License 5 votes vote down vote up
/**
 * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
 * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
 */
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
    livingdata = super.onInitialSpawn(difficulty, livingdata);
    this.setEquipmentBasedOnDifficulty(difficulty);
    this.setEnchantmentBasedOnDifficulty(difficulty);

    return livingdata;
}
 
Example #6
Source File: EntityCyberZombie.java    From Cyberware with MIT License 5 votes vote down vote up
@Override
protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty)
{
	super.setEquipmentBasedOnDifficulty(difficulty);
	
	if (CyberwareConfig.KATANA && !CyberwareConfig.NO_CLOTHES && this.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND) != null && this.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).getItem() == Items.IRON_SWORD)
	{
		this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(CyberwareContent.katana));
		this.setDropChance(EntityEquipmentSlot.MAINHAND, 0F);
	}
}
 
Example #7
Source File: EntityRainbowGuard.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);
	setLeftHanded(false);
	setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.GOLDEN_SWORD, 1));
	setCanPickUpLoot(false);
	addArmor();
	return livingdata;
}
 
Example #8
Source File: EntitySentry.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);

	setCanPickUpLoot(true);
	setEquipmentBasedOnDifficulty(difficulty);
	setEnchantmentBasedOnDifficulty(difficulty);

	setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.IRON_SWORD, 1));

	addArmor();

	return livingdata;
}
 
Example #9
Source File: EntityVillageLord.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);
	setCanPickUpLoot(false);
	addArmor();
	if (isEntityAlive()) {
		setHasLord(true);
	}
	return livingdata;
}
 
Example #10
Source File: EntityRainbowKing.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) {
	setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.DIAMOND_SWORD));
	setItemStackToSlot(EntityEquipmentSlot.HEAD, colorArmor(new ItemStack(Items.LEATHER_HELMET, 1), 8339378));
	setItemStackToSlot(EntityEquipmentSlot.CHEST, colorArmor(new ItemStack(Items.LEATHER_CHESTPLATE, 1), 3361970));
	setItemStackToSlot(EntityEquipmentSlot.LEGS, colorArmor(new ItemStack(Items.LEATHER_LEGGINGS, 1), 0xffff00));
	setItemStackToSlot(EntityEquipmentSlot.FEET, colorArmor(new ItemStack(Items.LEATHER_BOOTS, 1), 10040115));
}
 
Example #11
Source File: EntityGnome.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance diff, IEntityLivingData data)
{
	data = super.onInitialSpawn(diff, data);
	
	this.setCarriedToAir();
	
	return data;
}
 
Example #12
Source File: EntityGnomeWood.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance diff, IEntityLivingData data)
{
	data = super.onInitialSpawn(diff, data);
	//this.setCarried(Blocks.CHEST);
	//this.assignedGnode = new TileEntityGnomeCache();
	
	return data;
}
 
Example #13
Source File: EntitySamuraiIllager.java    From Sakura_mod with MIT License 5 votes vote down vote up
/**
 * Gives armor or weapon for entity based on given DifficultyInstance
 */
protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) {
    float f = this.world.getDifficultyForLocation(new BlockPos(this)).getAdditionalDifficulty();

    if (this.rand.nextFloat() < f * 0.2F) {
        this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ItemLoader.TACHI));
    } else {
        this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ItemLoader.KATANA));
    }
}
 
Example #14
Source File: EntitySamuraiIllager.java    From Sakura_mod with MIT License 5 votes vote down vote up
/**
 * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
 * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
 */
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
    IEntityLivingData ientitylivingdata = super.onInitialSpawn(difficulty, livingdata);
    this.setEquipmentBasedOnDifficulty(difficulty);
    this.setEnchantmentBasedOnDifficulty(difficulty);
    return ientitylivingdata;
}
 
Example #15
Source File: EntityTofuCow.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
    Biome biome = this.world.getBiome(new BlockPos(this));

    if (biome instanceof BiomeZundaTofuPlains) {
        this.setVariant(1);
    } else {
        this.setVariant(0);
    }
    return super.onInitialSpawn(difficulty, livingdata);
}
 
Example #16
Source File: EntityTofuMindCore.java    From TofuCraftReload with MIT License 5 votes vote down vote up
/**
 * Gives armor or weapon for entity based on given DifficultyInstance
 */
protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) {
    if (this.world.rand.nextInt(3) == 0) {
        this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ItemLoader.diamondTofuSword));
    } else {
        this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ItemLoader.metalTofuSword));
    }
}
 
Example #17
Source File: EntityAnimalWithTypes.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
    return this.initData(super.onInitialSpawn(difficulty, livingdata));
}
 
Example #18
Source File: EntityRainbowKing.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);
	setEquipmentBasedOnDifficulty(difficulty);
	return livingdata;
}
 
Example #19
Source File: EntityShopkeeper.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IEntityLivingData finalizeMobSpawn(DifficultyInstance p_190672_1_, @Nullable IEntityLivingData p_190672_2_, boolean p_190672_3_) {
	return p_190672_2_;
}
 
Example #20
Source File: EntityFugitive.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IEntityLivingData finalizeMobSpawn(DifficultyInstance p_190672_1_, @Nullable IEntityLivingData p_190672_2_, boolean p_190672_3_) {
	return p_190672_2_;
}
 
Example #21
Source File: EntityBas.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) {
	setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.STONE_SWORD));
	setItemStackToSlot(EntityEquipmentSlot.HEAD, colorArmor(new ItemStack(Items.LEATHER_HELMET, 1), 0xb0b0b0));
}
 
Example #22
Source File: EntityBas.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Called only once on an entity when first time spawned, via egg, mob
 * spawner, natural spawning etc, but not called when entity is reloaded
 * from nbt. Mainly used for initializing attributes and inventory
 */
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {
	livingdata = super.onInitialSpawn(difficulty, livingdata);
	return livingdata;
}
 
Example #23
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 #24
Source File: EntityWitherWitch.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance di, IEntityLivingData livingData) {
  spawned = true;
  return super.onInitialSpawn(di, livingData);
}
 
Example #25
Source File: EntityTofunian.java    From TofuCraftReload with MIT License 3 votes vote down vote up
@Nullable
@Override
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {

    IEntityLivingData data = super.onInitialSpawn(difficulty, livingdata);

    initTofuProfession();

    updateEntityAI();

    initTrades();

    return data;

}
 
Example #26
Source File: EntityRainbowGuard.java    From ToroQuest with GNU General Public License v3.0 2 votes vote down vote up
protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) {

	}