mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Villager trading, manipulation and village enhancement. Still WIP but should be functional
This commit is contained in:
1 parent
69e66c327f
commit
195b1a043e
3 files changed
+134
No files matched your search
@@ -0,0 +1,85 @@
|
|||||||
|
package cpw.mods.fml.common.registry;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLLog;
|
||||||
|
|
||||||
|
import net.minecraft.src.EntityVillager;
|
||||||
|
import net.minecraft.src.MerchantRecipeList;
|
||||||
|
import net.minecraft.src.StructureVillagePieceWeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registry for villager trading control
|
||||||
|
*
|
||||||
|
* @author cpw
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class VillagerRegistry
|
||||||
|
{
|
||||||
|
private static final VillagerRegistry INSTANCE = new VillagerRegistry();
|
||||||
|
|
||||||
|
private Multimap<Integer, IVillageTradeHandler> tradeHandlers = ArrayListMultimap.create();
|
||||||
|
private List<IVillageCreationHandler> villageCreationHandlers = Lists.newArrayList();
|
||||||
|
private Map<Integer, String> newVillagers = Maps.newHashMap();
|
||||||
|
|
||||||
|
public interface IVillageCreationHandler
|
||||||
|
{
|
||||||
|
List<StructureVillagePieceWeight> getVillagePieces(Random random, int i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IVillageTradeHandler
|
||||||
|
{
|
||||||
|
void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VillagerRegistry instance()
|
||||||
|
{
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerVillagerType(int villagerId, String villagerSkin)
|
||||||
|
{
|
||||||
|
if (newVillagers.containsKey(villagerId))
|
||||||
|
{
|
||||||
|
FMLLog.severe("Attempt to register duplicate villager id %d", villagerId);
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
newVillagers.put(villagerId, villagerSkin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getVillagerSkin(int villagerType, String defaultSkin)
|
||||||
|
{
|
||||||
|
if (instance().newVillagers.containsKey(villagerType))
|
||||||
|
{
|
||||||
|
return instance().newVillagers.get(villagerType);
|
||||||
|
}
|
||||||
|
return defaultSkin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void manageVillagerTrades(MerchantRecipeList recipeList, EntityVillager villager, int villagerType, Random random)
|
||||||
|
{
|
||||||
|
for (IVillageTradeHandler handler : instance().tradeHandlers.get(villagerType))
|
||||||
|
{
|
||||||
|
handler.manipulateTradesForVillager(villager, recipeList, random);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addExtraVillageComponents(ArrayList components, Random random, int i)
|
||||||
|
{
|
||||||
|
List<StructureVillagePieceWeight> parts = components;
|
||||||
|
for (IVillageCreationHandler handler : instance().villageCreationHandlers)
|
||||||
|
{
|
||||||
|
parts.addAll(handler.getVillagePieces(random, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
--- ../src-base/common/net/minecraft/src/EntityVillager.java
|
||||||
|
+++ ../src-work/common/net/minecraft/src/EntityVillager.java
|
||||||
|
@@ -2,6 +2,8 @@
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.Side;
|
||||||
|
import cpw.mods.fml.common.asm.SideOnly;
|
||||||
|
+import cpw.mods.fml.common.registry.VillagerRegistry;
|
||||||
|
+
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
@@ -175,7 +177,7 @@
|
||||||
|
case 4:
|
||||||
|
return "/mob/villager/butcher.png";
|
||||||
|
default:
|
||||||
|
- return super.func_70073_O();
|
||||||
|
+ return VillagerRegistry.getVillagerSkin(this.func_70946_n(), super.func_70073_O());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -400,6 +402,8 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.shuffle(var2);
|
||||||
|
+
|
||||||
|
+ VillagerRegistry.manageVillagerTrades(var2, this, this.func_70946_n(), this.field_70146_Z);
|
||||||
|
|
||||||
|
if (this.field_70963_i == null)
|
||||||
|
{
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
--- ../src-base/common/net/minecraft/src/StructureVillagePieces.java
|
||||||
|
+++ ../src-work/common/net/minecraft/src/StructureVillagePieces.java
|
||||||
|
@@ -4,6 +4,8 @@
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
+
|
||||||
|
+import cpw.mods.fml.common.registry.VillagerRegistry;
|
||||||
|
|
||||||
|
public class StructureVillagePieces
|
||||||
|
{
|
||||||
|
@@ -19,6 +21,8 @@
|
||||||
|
var2.add(new StructureVillagePieceWeight(ComponentVillageField2.class, 3, MathHelper.func_76136_a(p_75084_0_, 2 + p_75084_1_, 4 + p_75084_1_ * 2)));
|
||||||
|
var2.add(new StructureVillagePieceWeight(ComponentVillageHouse2.class, 15, MathHelper.func_76136_a(p_75084_0_, 0, 1 + p_75084_1_)));
|
||||||
|
var2.add(new StructureVillagePieceWeight(ComponentVillageHouse3.class, 8, MathHelper.func_76136_a(p_75084_0_, 0 + p_75084_1_, 3 + p_75084_1_ * 2)));
|
||||||
|
+ VillagerRegistry.addExtraVillageComponents(var2, p_75084_0_, p_75084_1_);
|
||||||
|
+
|
||||||
|
Iterator var3 = var2.iterator();
|
||||||
|
|
||||||
|
while (var3.hasNext())
|
||||||
Reference in new issue
Block a user