2013-03-08 00:25:48 +00:00
|
|
|
/*
|
2016-06-23 03:49:47 +00:00
|
|
|
* Minecraft Forge
|
|
|
|
* Copyright (c) 2016.
|
2013-06-29 17:33:14 +00:00
|
|
|
*
|
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
|
2013-03-08 00:25:48 +00:00
|
|
|
*/
|
|
|
|
|
2014-09-23 05:01:24 +00:00
|
|
|
package net.minecraftforge.fml.common.registry;
|
2012-08-19 14:13:15 +00:00
|
|
|
|
2016-05-15 03:11:55 +00:00
|
|
|
import java.util.Collections;
|
2012-08-19 14:13:15 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Random;
|
2015-11-28 21:30:58 +00:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import com.google.common.collect.Maps;
|
2014-09-20 00:24:36 +00:00
|
|
|
import org.apache.commons.lang3.Validate;
|
|
|
|
|
2016-06-03 23:49:30 +00:00
|
|
|
import net.minecraft.entity.monster.EntityZombie;
|
2016-06-23 06:39:36 +00:00
|
|
|
import net.minecraft.entity.monster.ZombieType;
|
2012-12-09 05:41:16 +00:00
|
|
|
import net.minecraft.entity.passive.EntityVillager;
|
2015-11-28 21:30:58 +00:00
|
|
|
import net.minecraft.entity.passive.EntityVillager.ITradeList;
|
2014-09-20 00:24:36 +00:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2013-07-08 20:59:52 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2015-11-13 07:32:08 +00:00
|
|
|
import net.minecraft.world.gen.structure.StructureComponent;
|
2013-12-03 04:46:42 +00:00
|
|
|
import net.minecraft.world.gen.structure.StructureVillagePieces;
|
2015-11-13 07:32:08 +00:00
|
|
|
import net.minecraft.world.gen.structure.StructureVillagePieces.PieceWeight;
|
|
|
|
import net.minecraft.world.gen.structure.StructureVillagePieces.Village;
|
2012-08-19 14:13:15 +00:00
|
|
|
/**
|
|
|
|
* Registry for villager trading control
|
|
|
|
*/
|
|
|
|
public class VillagerRegistry
|
|
|
|
{
|
2015-12-21 21:42:40 +00:00
|
|
|
public static final ResourceLocation PROFESSIONS = new ResourceLocation("minecraft:villagerprofessions");
|
2012-08-19 14:13:15 +00:00
|
|
|
private static final VillagerRegistry INSTANCE = new VillagerRegistry();
|
|
|
|
|
2012-08-19 15:23:29 +00:00
|
|
|
private Map<Class<?>, IVillageCreationHandler> villageCreationHandlers = Maps.newHashMap();
|
2012-08-19 14:13:15 +00:00
|
|
|
|
2014-09-20 00:24:36 +00:00
|
|
|
private VillagerRegistry()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2012-08-19 14:30:24 +00:00
|
|
|
/**
|
2013-01-22 02:37:29 +00:00
|
|
|
* Allow access to the {@link net.minecraft.world.gen.structure.StructureVillagePieces} array controlling new village
|
2012-08-19 14:30:24 +00:00
|
|
|
* creation so you can insert your own new village pieces
|
|
|
|
*
|
|
|
|
* @author cpw
|
|
|
|
*/
|
2012-08-19 14:13:15 +00:00
|
|
|
public interface IVillageCreationHandler
|
|
|
|
{
|
2012-08-19 14:30:24 +00:00
|
|
|
/**
|
2013-01-22 02:37:29 +00:00
|
|
|
* Called when {@link net.minecraft.world.gen.structure.MapGenVillage} is creating a new village
|
2012-08-19 14:30:24 +00:00
|
|
|
*
|
|
|
|
* @param random
|
|
|
|
* @param i
|
|
|
|
*/
|
2013-12-03 04:46:42 +00:00
|
|
|
StructureVillagePieces.PieceWeight getVillagePieceWeight(Random random, int i);
|
2012-08-19 15:23:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The class of the root structure component to add to the village
|
|
|
|
*/
|
|
|
|
Class<?> getComponentClass();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-22 02:37:29 +00:00
|
|
|
* Build an instance of the village component {@link net.minecraft.world.gen.structure.StructureVillagePieces}
|
2015-11-28 21:30:58 +00:00
|
|
|
*
|
2012-08-19 15:23:29 +00:00
|
|
|
* @param villagePiece
|
|
|
|
* @param startPiece
|
|
|
|
* @param pieces
|
|
|
|
* @param random
|
|
|
|
* @param p1
|
|
|
|
* @param p2
|
|
|
|
* @param p3
|
2014-09-20 00:24:36 +00:00
|
|
|
* @param facing
|
2012-08-19 15:23:29 +00:00
|
|
|
* @param p5
|
|
|
|
*/
|
2015-11-13 07:32:08 +00:00
|
|
|
Village buildComponent(StructureVillagePieces.PieceWeight villagePiece, StructureVillagePieces.Start startPiece, List<StructureComponent> pieces, Random random, int p1,
|
2015-11-28 21:30:58 +00:00
|
|
|
int p2, int p3, EnumFacing facing, int p5);
|
2012-08-19 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static VillagerRegistry instance()
|
|
|
|
{
|
|
|
|
return INSTANCE;
|
|
|
|
}
|
|
|
|
|
2012-08-19 14:30:24 +00:00
|
|
|
/**
|
|
|
|
* Register a new village creation handler
|
|
|
|
*
|
|
|
|
* @param handler
|
|
|
|
*/
|
|
|
|
public void registerVillageCreationHandler(IVillageCreationHandler handler)
|
|
|
|
{
|
2012-08-19 15:23:29 +00:00
|
|
|
villageCreationHandlers.put(handler.getComponentClass(), handler);
|
2012-08-19 14:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 07:32:08 +00:00
|
|
|
public static void addExtraVillageComponents(List<PieceWeight> list, Random random, int i)
|
2012-08-19 14:13:15 +00:00
|
|
|
{
|
2015-11-13 07:32:08 +00:00
|
|
|
List<StructureVillagePieces.PieceWeight> parts = list;
|
2012-08-19 15:23:29 +00:00
|
|
|
for (IVillageCreationHandler handler : instance().villageCreationHandlers.values())
|
2012-08-19 14:13:15 +00:00
|
|
|
{
|
2012-08-19 15:23:29 +00:00
|
|
|
parts.add(handler.getVillagePieceWeight(random, i));
|
2012-08-19 14:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 07:32:08 +00:00
|
|
|
public static Village getVillageComponent(StructureVillagePieces.PieceWeight villagePiece, StructureVillagePieces.Start startPiece, List<StructureComponent> pieces, Random random,
|
2015-11-28 21:30:58 +00:00
|
|
|
int p1, int p2, int p3, EnumFacing facing, int p5)
|
2012-08-19 15:23:29 +00:00
|
|
|
{
|
2014-09-20 00:24:36 +00:00
|
|
|
return instance().villageCreationHandlers.get(villagePiece.villagePieceClass).buildComponent(villagePiece, startPiece, pieces, random, p1, p2, p3, facing, p5);
|
2012-08-19 15:23:29 +00:00
|
|
|
}
|
|
|
|
|
2014-09-20 00:24:36 +00:00
|
|
|
public void register(VillagerProfession prof)
|
|
|
|
{
|
2015-03-15 20:22:28 +00:00
|
|
|
register(prof, -1);
|
|
|
|
}
|
2015-11-28 21:30:58 +00:00
|
|
|
|
2015-03-15 20:22:28 +00:00
|
|
|
private void register(VillagerProfession prof, int id)
|
|
|
|
{
|
|
|
|
professions.register(id, prof.name, prof);
|
2014-09-20 00:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean hasInit = false;
|
2016-04-01 21:13:06 +00:00
|
|
|
private FMLControlledNamespacedRegistry<VillagerProfession> professions = PersistentRegistryManager.createRegistry(PROFESSIONS, VillagerProfession.class, null, 0, 1024, true, null, null, null);
|
|
|
|
public IForgeRegistry<VillagerProfession> getRegistry() { return this.professions; }
|
2014-09-23 02:30:14 +00:00
|
|
|
|
2012-08-23 05:40:03 +00:00
|
|
|
|
2014-09-20 00:24:36 +00:00
|
|
|
private void init()
|
2012-08-23 05:40:03 +00:00
|
|
|
{
|
2014-09-20 00:24:36 +00:00
|
|
|
if (hasInit)
|
2015-11-28 21:30:58 +00:00
|
|
|
{
|
2014-09-20 00:24:36 +00:00
|
|
|
return;
|
2015-11-28 21:30:58 +00:00
|
|
|
}
|
2014-09-20 00:24:36 +00:00
|
|
|
|
2016-06-03 23:49:30 +00:00
|
|
|
VillagerProfession prof = new VillagerProfession("minecraft:farmer",
|
|
|
|
"minecraft:textures/entity/villager/farmer.png",
|
|
|
|
"minecraft:textures/entity/zombie_villager/zombie_farmer.png");
|
2014-09-20 00:24:36 +00:00
|
|
|
{
|
2015-03-15 20:22:28 +00:00
|
|
|
register(prof, 0);
|
2015-11-28 21:30:58 +00:00
|
|
|
(new VillagerCareer(prof, "farmer")).init(VanillaTrades.trades[0][0]);
|
|
|
|
(new VillagerCareer(prof, "fisherman")).init(VanillaTrades.trades[0][1]);
|
|
|
|
(new VillagerCareer(prof, "shepherd")).init(VanillaTrades.trades[0][2]);
|
|
|
|
(new VillagerCareer(prof, "fletcher")).init(VanillaTrades.trades[0][3]);
|
2014-09-20 00:24:36 +00:00
|
|
|
}
|
2016-06-03 23:49:30 +00:00
|
|
|
prof = new VillagerProfession("minecraft:librarian",
|
|
|
|
"minecraft:textures/entity/villager/librarian.png",
|
|
|
|
"minecraft:textures/entity/zombie_villager/zombie_librarian.png");
|
2014-09-20 00:24:36 +00:00
|
|
|
{
|
2015-03-15 20:22:28 +00:00
|
|
|
register(prof, 1);
|
2014-09-23 02:30:14 +00:00
|
|
|
(new VillagerCareer(prof, "librarian")).init(VanillaTrades.trades[1][0]);
|
2014-09-20 00:24:36 +00:00
|
|
|
}
|
2016-06-03 23:49:30 +00:00
|
|
|
prof = new VillagerProfession("minecraft:priest",
|
|
|
|
"minecraft:textures/entity/villager/priest.png",
|
|
|
|
"minecraft:textures/entity/zombie_villager/zombie_priest.png");
|
2014-09-20 00:24:36 +00:00
|
|
|
{
|
2015-03-15 20:22:28 +00:00
|
|
|
register(prof, 2);
|
2014-09-23 02:30:14 +00:00
|
|
|
(new VillagerCareer(prof, "cleric")).init(VanillaTrades.trades[2][0]);
|
2014-09-20 00:24:36 +00:00
|
|
|
}
|
2016-06-03 23:49:30 +00:00
|
|
|
prof = new VillagerProfession("minecraft:smith",
|
|
|
|
"minecraft:textures/entity/villager/smith.png",
|
|
|
|
"minecraft:textures/entity/zombie_villager/zombie_smith.png");
|
2012-08-23 05:40:03 +00:00
|
|
|
{
|
2015-03-15 20:22:28 +00:00
|
|
|
register(prof, 3);
|
2015-11-28 21:30:58 +00:00
|
|
|
(new VillagerCareer(prof, "armor")).init(VanillaTrades.trades[3][0]);
|
2014-09-23 02:30:14 +00:00
|
|
|
(new VillagerCareer(prof, "weapon")).init(VanillaTrades.trades[3][1]);
|
2015-11-28 21:30:58 +00:00
|
|
|
(new VillagerCareer(prof, "tool")).init(VanillaTrades.trades[3][2]);
|
2014-09-20 00:24:36 +00:00
|
|
|
}
|
2016-06-03 23:49:30 +00:00
|
|
|
prof = new VillagerProfession("minecraft:butcher",
|
|
|
|
"minecraft:textures/entity/villager/butcher.png",
|
|
|
|
"minecraft:textures/entity/zombie_villager/zombie_butcher.png");
|
2014-09-20 00:24:36 +00:00
|
|
|
{
|
2015-03-15 20:22:28 +00:00
|
|
|
register(prof, 4);
|
2014-09-23 02:30:14 +00:00
|
|
|
(new VillagerCareer(prof, "butcher")).init(VanillaTrades.trades[4][0]);
|
|
|
|
(new VillagerCareer(prof, "leather")).init(VanillaTrades.trades[4][1]);
|
2012-08-23 05:40:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 21:13:06 +00:00
|
|
|
public static class VillagerProfession extends IForgeRegistryEntry.Impl<VillagerProfession>
|
2012-08-23 05:40:03 +00:00
|
|
|
{
|
2014-09-20 00:24:36 +00:00
|
|
|
private ResourceLocation name;
|
2015-11-28 08:01:31 +00:00
|
|
|
private ResourceLocation texture;
|
2016-06-03 23:49:30 +00:00
|
|
|
private ResourceLocation zombie;
|
2014-09-20 00:24:36 +00:00
|
|
|
private List<VillagerCareer> careers = Lists.newArrayList();
|
|
|
|
|
2016-06-03 23:49:30 +00:00
|
|
|
@Deprecated //Use Zombie texture
|
2014-09-20 00:24:36 +00:00
|
|
|
public VillagerProfession(String name, String texture)
|
2016-06-03 23:49:30 +00:00
|
|
|
{
|
|
|
|
this (name, texture, "minecraft:textures/entity/zombie_villager/zombie_villager.png");
|
|
|
|
}
|
|
|
|
public VillagerProfession(String name, String texture, String zombie)
|
2012-08-23 05:40:03 +00:00
|
|
|
{
|
2014-09-20 00:24:36 +00:00
|
|
|
this.name = new ResourceLocation(name);
|
2015-11-28 08:01:31 +00:00
|
|
|
this.texture = new ResourceLocation(texture);
|
2016-06-03 23:49:30 +00:00
|
|
|
this.zombie = new ResourceLocation(zombie);
|
2016-04-01 21:13:06 +00:00
|
|
|
this.setRegistryName(this.name);
|
2014-09-20 00:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void register(VillagerCareer career)
|
|
|
|
{
|
|
|
|
Validate.isTrue(!careers.contains(career), "Attempted to register career that is already registered.");
|
|
|
|
Validate.isTrue(career.profession == this, "Attempted to register career for the wrong profession.");
|
2015-11-28 08:01:31 +00:00
|
|
|
career.id = careers.size();
|
2014-09-20 00:24:36 +00:00
|
|
|
careers.add(career);
|
2012-08-23 05:40:03 +00:00
|
|
|
}
|
2016-04-01 21:13:06 +00:00
|
|
|
|
|
|
|
public ResourceLocation getSkin() { return this.texture; }
|
2016-06-03 23:49:30 +00:00
|
|
|
public ResourceLocation getZombieSkin() { return this.zombie; }
|
2016-04-01 21:13:06 +00:00
|
|
|
public VillagerCareer getCareer(int id)
|
|
|
|
{
|
|
|
|
for (VillagerCareer car : this.careers)
|
|
|
|
{
|
|
|
|
if (car.id == id)
|
|
|
|
return car;
|
|
|
|
}
|
|
|
|
return this.careers.get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getRandomCareer(Random rand)
|
|
|
|
{
|
|
|
|
return this.careers.get(rand.nextInt(this.careers.size())).id;
|
|
|
|
}
|
2012-08-23 05:40:03 +00:00
|
|
|
}
|
2012-09-15 19:49:08 +00:00
|
|
|
|
2014-09-20 00:24:36 +00:00
|
|
|
public static class VillagerCareer
|
2012-09-15 19:49:08 +00:00
|
|
|
{
|
2014-09-20 00:24:36 +00:00
|
|
|
private VillagerProfession profession;
|
|
|
|
private String name;
|
2015-11-28 08:01:31 +00:00
|
|
|
private int id;
|
2016-05-15 03:11:55 +00:00
|
|
|
private List<List<ITradeList>> trades = Lists.newArrayList();
|
2015-11-28 21:30:58 +00:00
|
|
|
|
2014-09-20 00:24:36 +00:00
|
|
|
public VillagerCareer(VillagerProfession parent, String name)
|
|
|
|
{
|
|
|
|
this.profession = parent;
|
|
|
|
this.name = name;
|
|
|
|
parent.register(this);
|
|
|
|
}
|
|
|
|
|
2016-04-01 21:13:06 +00:00
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
2016-05-15 03:11:55 +00:00
|
|
|
|
|
|
|
public VillagerCareer addTrade(int level, ITradeList... trades)
|
2016-04-01 21:13:06 +00:00
|
|
|
{
|
2016-05-15 03:11:55 +00:00
|
|
|
if (level <= 0)
|
|
|
|
throw new IllegalArgumentException("Levels start at 1");
|
|
|
|
|
|
|
|
List<ITradeList> levelTrades = level <= this.trades.size() ? this.trades.get(level - 1) : null;
|
|
|
|
if (levelTrades == null)
|
|
|
|
{
|
|
|
|
while (this.trades.size() < level)
|
|
|
|
{
|
2016-05-15 04:40:31 +00:00
|
|
|
levelTrades = Lists.newArrayList();
|
|
|
|
this.trades.add(levelTrades);
|
2016-05-15 03:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (levelTrades == null) //Not sure how this could happen, but screw it
|
|
|
|
{
|
|
|
|
levelTrades = Lists.newArrayList();
|
|
|
|
this.trades.set(level - 1, levelTrades);
|
|
|
|
}
|
|
|
|
for (ITradeList t : trades)
|
|
|
|
levelTrades.add(t);
|
|
|
|
return this;
|
2016-04-01 21:13:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-15 03:11:55 +00:00
|
|
|
|
|
|
|
public List<ITradeList> getTrades(int level)
|
|
|
|
{
|
2016-05-15 04:40:31 +00:00
|
|
|
return level >= 0 && level < this.trades.size() ? Collections.unmodifiableList(this.trades.get(level)) : null;
|
2016-05-15 03:11:55 +00:00
|
|
|
}
|
2016-04-01 21:13:06 +00:00
|
|
|
private VillagerCareer init(EntityVillager.ITradeList[][] trades)
|
2014-09-20 00:24:36 +00:00
|
|
|
{
|
2016-05-15 03:11:55 +00:00
|
|
|
for (int x = 0; x < trades.length; x++)
|
|
|
|
this.trades.add(Lists.newArrayList(trades[x]));
|
2014-09-20 00:24:36 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o)
|
|
|
|
{
|
2015-11-28 21:30:58 +00:00
|
|
|
if (o == this)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!(o instanceof VillagerCareer))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-20 00:24:36 +00:00
|
|
|
VillagerCareer oc = (VillagerCareer)o;
|
|
|
|
return name.equals(oc.name) && profession == oc.profession;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook called when spawning a Villager, sets it's profession to a random registered profession.
|
|
|
|
*
|
|
|
|
* @param entity The new entity
|
2015-11-28 21:30:58 +00:00
|
|
|
* @param rand The world's RNG
|
2014-09-20 00:24:36 +00:00
|
|
|
*/
|
|
|
|
public static void setRandomProfession(EntityVillager entity, Random rand)
|
|
|
|
{
|
2016-06-03 23:49:30 +00:00
|
|
|
List<VillagerProfession> entries = INSTANCE.professions.getValues();
|
|
|
|
entity.setProfession(entries.get(rand.nextInt(entries.size())));
|
2012-09-15 19:49:08 +00:00
|
|
|
}
|
2016-06-03 23:49:30 +00:00
|
|
|
public static void setRandomProfession(EntityZombie entity, Random rand)
|
|
|
|
{
|
|
|
|
List<VillagerProfession> entries = INSTANCE.professions.getValues();
|
|
|
|
entity.setVillagerType(entries.get(rand.nextInt(entries.size())));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-20 00:24:36 +00:00
|
|
|
|
2016-06-03 23:49:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Below this is INTERNAL USE ONLY DO NOT USE MODDERS
|
2016-04-07 19:29:00 +00:00
|
|
|
public static void onSetProfession(EntityVillager entity, VillagerProfession prof)
|
|
|
|
{
|
|
|
|
int network = INSTANCE.professions.getId(prof);
|
|
|
|
if (network == -1 || prof != INSTANCE.professions.getObjectById(network))
|
|
|
|
{
|
|
|
|
throw new RuntimeException("Attempted to set villager profession to unregistered profession: " + network + " " + prof);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (network != entity.getProfession())
|
|
|
|
entity.setProfession(network);
|
|
|
|
}
|
|
|
|
public static void onSetProfession(EntityVillager entity, int network)
|
|
|
|
{
|
|
|
|
VillagerProfession prof = INSTANCE.professions.getObjectById(network);
|
|
|
|
if (prof == null || INSTANCE.professions.getId(prof) != network)
|
|
|
|
{
|
|
|
|
throw new RuntimeException("Attempted to set villager profession to unregistered profession: " + network + " " + prof);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prof != entity.getProfessionForge())
|
|
|
|
entity.setProfession(prof);
|
|
|
|
}
|
|
|
|
|
2016-06-03 23:49:30 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public static void onSetProfession(EntityZombie entity, VillagerProfession prof)
|
|
|
|
{
|
|
|
|
if (prof == null)
|
|
|
|
{
|
2016-06-25 18:05:46 +00:00
|
|
|
if (entity.func_189777_di() != ZombieType.NORMAL && entity.func_189777_di() != ZombieType.HUSK)
|
2016-06-23 06:39:36 +00:00
|
|
|
entity.func_189778_a(ZombieType.NORMAL);
|
2016-06-03 23:49:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int network = INSTANCE.professions.getId(prof);
|
|
|
|
if (network == -1 || prof != INSTANCE.professions.getObjectById(network))
|
|
|
|
{
|
|
|
|
throw new RuntimeException("Attempted to set villager profession to unregistered profession: " + network + " " + prof);
|
|
|
|
}
|
|
|
|
|
2016-06-23 06:39:36 +00:00
|
|
|
if (network >= 0 && network < 5) // Vanilla
|
|
|
|
{
|
|
|
|
if (entity.func_189777_di() == null || entity.func_189777_di().func_190150_a() != network + 1)
|
|
|
|
{
|
|
|
|
entity.func_189778_a(ZombieType.func_190144_b(network));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (entity.func_189777_di() != null)
|
2016-06-23 13:29:03 +00:00
|
|
|
entity.func_189778_a(ZombieType.NORMAL);
|
2016-06-03 23:49:30 +00:00
|
|
|
}
|
2016-06-23 06:39:36 +00:00
|
|
|
public static void onSetProfession(EntityZombie entity, ZombieType type, int network)
|
2016-06-03 23:49:30 +00:00
|
|
|
{
|
2016-06-23 06:39:36 +00:00
|
|
|
if (type == ZombieType.NORMAL || type == ZombieType.HUSK)
|
2016-06-03 23:49:30 +00:00
|
|
|
{
|
|
|
|
if (entity.getVillagerTypeForge() != null)
|
|
|
|
entity.setVillagerType(null);
|
|
|
|
return;
|
|
|
|
}
|
2016-06-23 06:39:36 +00:00
|
|
|
int realID = network - 1;
|
|
|
|
if (type == null) //Forge type?
|
|
|
|
realID = network * -1; // Forge encoded as -ID
|
|
|
|
VillagerProfession prof = INSTANCE.professions.getObjectById(realID);
|
|
|
|
if (prof == null && network != 0 || INSTANCE.professions.getId(prof) != realID)
|
2016-06-03 23:49:30 +00:00
|
|
|
{
|
2016-06-23 06:39:36 +00:00
|
|
|
throw new RuntimeException("Attempted to set villager profession to unregistered profession: " + realID + " " + prof);
|
2016-06-03 23:49:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prof != entity.getVillagerTypeForge())
|
|
|
|
entity.setVillagerType(prof);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated public static VillagerProfession getById(int network){ return INSTANCE.professions.getObjectById(network); }
|
|
|
|
@Deprecated public static int getId(VillagerProfession prof){ return INSTANCE.professions.getId(prof); }
|
|
|
|
|
2014-09-20 00:24:36 +00:00
|
|
|
//TODO: Figure out a good generic system for this. Put on hold for Patches.
|
2014-09-23 02:30:14 +00:00
|
|
|
|
|
|
|
private static class VanillaTrades
|
|
|
|
{
|
|
|
|
//This field is moved from EntityVillager over to here.
|
|
|
|
//Moved to inner class to stop static initializer issues.
|
|
|
|
//It is nasty I know but it's vanilla.
|
2016-05-18 12:11:56 +00:00
|
|
|
private static final ITradeList[][][][] trades = EntityVillager.GET_TRADES_DONT_USE();
|
2014-09-23 02:30:14 +00:00
|
|
|
}
|
2012-08-19 14:13:15 +00:00
|
|
|
}
|