2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2018-07-01 21:17:28 +00:00
|
|
|
* Copyright (c) 2016-2018.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2012-08-07 08:24:06 +00:00
|
|
|
package net.minecraftforge.common;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2016-11-13 22:09:54 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2012-12-13 05:58:35 +00:00
|
|
|
import net.minecraft.util.WeightedRandom;
|
2012-12-24 09:29:33 +00:00
|
|
|
|
2012-08-07 08:24:06 +00:00
|
|
|
public class DungeonHooks
|
|
|
|
{
|
|
|
|
private static ArrayList<DungeonMob> dungeonMobs = new ArrayList<DungeonMob>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a mob to the possible list of creatures the spawner will create.
|
|
|
|
* If the mob is already in the spawn list, the rarity will be added to the existing one,
|
|
|
|
* causing the mob to be more common.
|
|
|
|
*
|
|
|
|
* @param name The name of the monster, use the same name used when registering the entity.
|
|
|
|
* @param rarity The rarity of selecting this mob over others. Must be greater then 0.
|
|
|
|
* Vanilla Minecraft has the following mobs:
|
|
|
|
* Spider 100
|
|
|
|
* Skeleton 100
|
|
|
|
* Zombie 200
|
|
|
|
* Meaning, Zombies are twice as common as spiders or skeletons.
|
|
|
|
* @return The new rarity of the monster,
|
|
|
|
*/
|
2016-11-13 22:09:54 +00:00
|
|
|
public static float addDungeonMob(ResourceLocation name, int rarity)
|
2012-08-07 08:24:06 +00:00
|
|
|
{
|
|
|
|
if (rarity <= 0)
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("Rarity must be greater then zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (DungeonMob mob : dungeonMobs)
|
|
|
|
{
|
|
|
|
if (name.equals(mob.type))
|
|
|
|
{
|
|
|
|
return mob.itemWeight += rarity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dungeonMobs.add(new DungeonMob(rarity, name));
|
|
|
|
return rarity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will completely remove a Mob from the dungeon spawn list.
|
|
|
|
*
|
|
|
|
* @param name The name of the mob to remove
|
|
|
|
* @return The rarity of the removed mob, prior to being removed.
|
|
|
|
*/
|
2017-01-12 00:13:32 +00:00
|
|
|
public static int removeDungeonMob(ResourceLocation name)
|
2012-08-07 08:24:06 +00:00
|
|
|
{
|
|
|
|
for (DungeonMob mob : dungeonMobs)
|
|
|
|
{
|
|
|
|
if (name.equals(mob.type))
|
|
|
|
{
|
|
|
|
dungeonMobs.remove(mob);
|
|
|
|
return mob.itemWeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a random mob name from the list.
|
|
|
|
* @param rand World generation random number generator
|
|
|
|
* @return The mob name
|
|
|
|
*/
|
2016-11-13 22:09:54 +00:00
|
|
|
public static ResourceLocation getRandomDungeonMob(Random rand)
|
2012-08-07 08:24:06 +00:00
|
|
|
{
|
2016-03-23 14:34:48 +00:00
|
|
|
DungeonMob mob = WeightedRandom.getRandomItem(rand, dungeonMobs);
|
2012-08-07 08:24:06 +00:00
|
|
|
return mob.type;
|
|
|
|
}
|
|
|
|
|
2012-12-18 23:02:41 +00:00
|
|
|
|
2013-12-10 05:59:12 +00:00
|
|
|
public static class DungeonMob extends WeightedRandom.Item
|
2012-08-07 08:24:06 +00:00
|
|
|
{
|
2016-11-13 22:09:54 +00:00
|
|
|
public ResourceLocation type;
|
|
|
|
public DungeonMob(int weight, ResourceLocation type)
|
2012-08-07 08:24:06 +00:00
|
|
|
{
|
|
|
|
super(weight);
|
|
|
|
this.type = type;
|
|
|
|
}
|
2012-12-18 23:02:41 +00:00
|
|
|
|
2012-08-07 08:24:06 +00:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object target)
|
|
|
|
{
|
2013-01-02 04:57:45 +00:00
|
|
|
return target instanceof DungeonMob && type.equals(((DungeonMob)target).type);
|
2012-08-07 08:24:06 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-30 08:01:00 +00:00
|
|
|
|
2012-12-24 09:29:33 +00:00
|
|
|
static
|
2012-09-30 08:01:00 +00:00
|
|
|
{
|
2016-11-13 22:09:54 +00:00
|
|
|
addDungeonMob(new ResourceLocation("skeleton"), 100);
|
|
|
|
addDungeonMob(new ResourceLocation("zombie"), 200);
|
|
|
|
addDungeonMob(new ResourceLocation("spider"), 100);
|
2012-09-30 08:01:00 +00:00
|
|
|
}
|
2012-08-07 08:24:06 +00:00
|
|
|
}
|