mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Expanded custom villagers to Zombies and world gen.
Fixed edge cases where custom professiosn wernt being used correctly. Closes #2862
This commit is contained in:
1 parent
0a5daa194b
commit
9a23cf76d2
5 files changed
+274
-42
No files matched your search
@@ -12,31 +12,17 @@
|
||||
|
||||
package net.minecraftforge.fml.common.registry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.entity.passive.EntityVillager.EmeraldForItems;
|
||||
import net.minecraft.entity.passive.EntityVillager.ITradeList;
|
||||
import net.minecraft.entity.passive.EntityVillager.ItemAndEmeraldToItem;
|
||||
import net.minecraft.entity.passive.EntityVillager.ListEnchantedBookForEmeralds;
|
||||
import net.minecraft.entity.passive.EntityVillager.ListEnchantedItemForEmeralds;
|
||||
import net.minecraft.entity.passive.EntityVillager.ListItemForEmeralds;
|
||||
import net.minecraft.entity.passive.EntityVillager.PriceInfo;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.gen.structure.StructureComponent;
|
||||
@@ -45,8 +31,6 @@ import net.minecraft.world.gen.structure.StructureVillagePieces.PieceWeight;
|
||||
import net.minecraft.world.gen.structure.StructureVillagePieces.Village;
|
||||
/**
|
||||
* Registry for villager trading control
|
||||
*
|
||||
* @author cpw
|
||||
*/
|
||||
public class VillagerRegistry
|
||||
{
|
||||
@@ -151,7 +135,9 @@ public class VillagerRegistry
|
||||
return;
|
||||
}
|
||||
|
||||
VillagerProfession prof = new VillagerProfession("minecraft:farmer", "minecraft:textures/entity/villager/farmer.png");
|
||||
VillagerProfession prof = new VillagerProfession("minecraft:farmer",
|
||||
"minecraft:textures/entity/villager/farmer.png",
|
||||
"minecraft:textures/entity/zombie_villager/zombie_farmer.png");
|
||||
{
|
||||
register(prof, 0);
|
||||
(new VillagerCareer(prof, "farmer")).init(VanillaTrades.trades[0][0]);
|
||||
@@ -159,24 +145,32 @@ public class VillagerRegistry
|
||||
(new VillagerCareer(prof, "shepherd")).init(VanillaTrades.trades[0][2]);
|
||||
(new VillagerCareer(prof, "fletcher")).init(VanillaTrades.trades[0][3]);
|
||||
}
|
||||
prof = new VillagerProfession("minecraft:librarian", "minecraft:textures/entity/villager/librarian.png");
|
||||
prof = new VillagerProfession("minecraft:librarian",
|
||||
"minecraft:textures/entity/villager/librarian.png",
|
||||
"minecraft:textures/entity/zombie_villager/zombie_librarian.png");
|
||||
{
|
||||
register(prof, 1);
|
||||
(new VillagerCareer(prof, "librarian")).init(VanillaTrades.trades[1][0]);
|
||||
}
|
||||
prof = new VillagerProfession("minecraft:priest", "minecraft:textures/entity/villager/priest.png");
|
||||
prof = new VillagerProfession("minecraft:priest",
|
||||
"minecraft:textures/entity/villager/priest.png",
|
||||
"minecraft:textures/entity/zombie_villager/zombie_priest.png");
|
||||
{
|
||||
register(prof, 2);
|
||||
(new VillagerCareer(prof, "cleric")).init(VanillaTrades.trades[2][0]);
|
||||
}
|
||||
prof = new VillagerProfession("minecraft:smith", "minecraft:textures/entity/villager/smith.png");
|
||||
prof = new VillagerProfession("minecraft:smith",
|
||||
"minecraft:textures/entity/villager/smith.png",
|
||||
"minecraft:textures/entity/zombie_villager/zombie_smith.png");
|
||||
{
|
||||
register(prof, 3);
|
||||
(new VillagerCareer(prof, "armor")).init(VanillaTrades.trades[3][0]);
|
||||
(new VillagerCareer(prof, "weapon")).init(VanillaTrades.trades[3][1]);
|
||||
(new VillagerCareer(prof, "tool")).init(VanillaTrades.trades[3][2]);
|
||||
}
|
||||
prof = new VillagerProfession("minecraft:butcher", "minecraft:textures/entity/villager/butcher.png");
|
||||
prof = new VillagerProfession("minecraft:butcher",
|
||||
"minecraft:textures/entity/villager/butcher.png",
|
||||
"minecraft:textures/entity/zombie_villager/zombie_butcher.png");
|
||||
{
|
||||
register(prof, 4);
|
||||
(new VillagerCareer(prof, "butcher")).init(VanillaTrades.trades[4][0]);
|
||||
@@ -188,12 +182,19 @@ public class VillagerRegistry
|
||||
{
|
||||
private ResourceLocation name;
|
||||
private ResourceLocation texture;
|
||||
private ResourceLocation zombie;
|
||||
private List<VillagerCareer> careers = Lists.newArrayList();
|
||||
|
||||
@Deprecated //Use Zombie texture
|
||||
public VillagerProfession(String name, String texture)
|
||||
{
|
||||
this (name, texture, "minecraft:textures/entity/zombie_villager/zombie_villager.png");
|
||||
}
|
||||
public VillagerProfession(String name, String texture, String zombie)
|
||||
{
|
||||
this.name = new ResourceLocation(name);
|
||||
this.texture = new ResourceLocation(texture);
|
||||
this.zombie = new ResourceLocation(zombie);
|
||||
this.setRegistryName(this.name);
|
||||
}
|
||||
|
||||
@@ -206,6 +207,7 @@ public class VillagerRegistry
|
||||
}
|
||||
|
||||
public ResourceLocation getSkin() { return this.texture; }
|
||||
public ResourceLocation getZombieSkin() { return this.zombie; }
|
||||
public VillagerCareer getCareer(int id)
|
||||
{
|
||||
for (VillagerCareer car : this.careers)
|
||||
@@ -302,10 +304,22 @@ public class VillagerRegistry
|
||||
*/
|
||||
public static void setRandomProfession(EntityVillager entity, Random rand)
|
||||
{
|
||||
Set<ResourceLocation> entries = INSTANCE.professions.getKeys();
|
||||
entity.setProfession(rand.nextInt(entries.size()));
|
||||
List<VillagerProfession> entries = INSTANCE.professions.getValues();
|
||||
entity.setProfession(entries.get(rand.nextInt(entries.size())));
|
||||
}
|
||||
public static void setRandomProfession(EntityZombie entity, Random rand)
|
||||
{
|
||||
List<VillagerProfession> entries = INSTANCE.professions.getValues();
|
||||
entity.setVillagerType(entries.get(rand.nextInt(entries.size())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Below this is INTERNAL USE ONLY DO NOT USE MODDERS
|
||||
public static void onSetProfession(EntityVillager entity, VillagerProfession prof)
|
||||
{
|
||||
int network = INSTANCE.professions.getId(prof);
|
||||
@@ -329,6 +343,46 @@ public class VillagerRegistry
|
||||
entity.setProfession(prof);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void onSetProfession(EntityZombie entity, VillagerProfession prof)
|
||||
{
|
||||
if (prof == null)
|
||||
{
|
||||
if (entity.getVillagerType() != 0)
|
||||
entity.setVillagerType(-1);
|
||||
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);
|
||||
}
|
||||
|
||||
if (network != entity.getVillagerType())
|
||||
entity.setVillagerType(network);
|
||||
}
|
||||
public static void onSetProfession(EntityZombie entity, int network)
|
||||
{
|
||||
if (network == -1)
|
||||
{
|
||||
if (entity.getVillagerTypeForge() != null)
|
||||
entity.setVillagerType(null);
|
||||
return;
|
||||
}
|
||||
VillagerProfession prof = INSTANCE.professions.getObjectById(network);
|
||||
if (prof == null && network != 0 || INSTANCE.professions.getId(prof) != network)
|
||||
{
|
||||
throw new RuntimeException("Attempted to set villager profession to unregistered profession: " + network + " " + prof);
|
||||
}
|
||||
|
||||
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); }
|
||||
|
||||
//TODO: Figure out a good generic system for this. Put on hold for Patches.
|
||||
|
||||
private static class VanillaTrades
|
||||
|
||||
Reference in new issue
Block a user