diff options
author | Connor-Colenso <52056774+Connor-Colenso@users.noreply.github.com> | 2023-01-23 16:23:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-23 16:23:02 +0000 |
commit | dce9e27a012290d5d06eb081aaf0b711076b3297 (patch) | |
tree | dd2c9552f725045bab7f0f674ab2b1b08a985784 /src/main/java/gtPlusPlus/plugin/villagers | |
parent | 6b3d66f0d27eaeb2a8e9d6aa9f291ede934dd08b (diff) | |
download | GT5-Unofficial-dce9e27a012290d5d06eb081aaf0b711076b3297.tar.gz GT5-Unofficial-dce9e27a012290d5d06eb081aaf0b711076b3297.tar.bz2 GT5-Unofficial-dce9e27a012290d5d06eb081aaf0b711076b3297.zip |
Remove Australia dimension and associated world gen, mobs etc. (#516)
Co-authored-by: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gtPlusPlus/plugin/villagers')
5 files changed, 6 insertions, 1357 deletions
diff --git a/src/main/java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java b/src/main/java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java index 3eba3333b4..fe588cabbc 100644 --- a/src/main/java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java +++ b/src/main/java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java @@ -2,18 +2,13 @@ package gtPlusPlus.plugin.villagers; import static gtPlusPlus.plugin.villagers.VillagerUtils.mVillagerMap; -import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.VillagerRegistry; import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler; import gtPlusPlus.api.interfaces.IPlugin; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.Utils; import gtPlusPlus.plugin.manager.Core_Manager; -import gtPlusPlus.plugin.villagers.entity.EntityBaseVillager; -import gtPlusPlus.plugin.villagers.entity.EntityNativeAustralian; -import gtPlusPlus.plugin.villagers.trade.TradeHandlerAboriginal; import gtPlusPlus.plugin.villagers.trade.TradeHandlerBanker; import gtPlusPlus.plugin.villagers.trade.TradeHandlerTechnician; import gtPlusPlus.plugin.villagers.trade.TradeHandlerTrader; @@ -25,9 +20,8 @@ public class Core_VillagerAdditions implements IPlugin { public static final Core_VillagerAdditions mInstance; private static boolean shouldLoad = false; - public static final HashMap<Integer, ResourceLocation> mVillagerSkins = new HashMap<Integer, ResourceLocation>(); - public static final AutoMap<Pair<Integer, IVillageTradeHandler>> mVillagerTrades = - new AutoMap<Pair<Integer, IVillageTradeHandler>>(); + public static final HashMap<Integer, ResourceLocation> mVillagerSkins = new HashMap<>(); + public static final AutoMap<Pair<Integer, IVillageTradeHandler>> mVillagerTrades = new AutoMap<>(); static { mInstance = new Core_VillagerAdditions(); @@ -43,24 +37,10 @@ public class Core_VillagerAdditions implements IPlugin { } if (shouldLoad) { // Register Custom Villager Entity - EntityRegistry.registerGlobalEntityID( - EntityBaseVillager.class, - "WiseVillager", - EntityRegistry.findGlobalUniqueEntityId(), - Utils.rgbtoHexValue(180, 120, 120), - Utils.rgbtoHexValue(0, 0, 0)); - EntityRegistry.registerGlobalEntityID( - EntityNativeAustralian.class, - "Aboriginal", - EntityRegistry.findGlobalUniqueEntityId(), - Utils.rgbtoHexValue(50, 50, 50), - Utils.rgbtoHexValue(25, 25, 25)); VillagerUtils.registerNewVillager(0, "Banker", "Banker", "Banker", "banker", new TradeHandlerBanker()); VillagerUtils.registerNewVillager( 1, "Technician", "Technician", "Technician", "technician", new TradeHandlerTechnician()); VillagerUtils.registerNewVillager(2, "Trader", "Trader", "Trader", "trader", new TradeHandlerTrader()); - VillagerUtils.registerNewVillager( - 3, "Aboriginal", "Aboriginal", "Aboriginal", "aboriginal", new TradeHandlerAboriginal()); if (mVillagerMap.size() > 0) { for (VillagerObject g : mVillagerMap.values()) { @@ -94,34 +74,22 @@ public class Core_VillagerAdditions implements IPlugin { @Override public boolean init() { - if (shouldLoad) { - return true; - } - return false; + return shouldLoad; } @Override public boolean postInit() { - if (shouldLoad) { - return true; - } - return false; + return shouldLoad; } @Override public boolean serverStart() { - if (shouldLoad) { - return true; - } - return false; + return shouldLoad; } @Override public boolean serverStop() { - if (shouldLoad) { - return true; - } - return false; + return shouldLoad; } @Override diff --git a/src/main/java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java b/src/main/java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java deleted file mode 100644 index 655d1c567c..0000000000 --- a/src/main/java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java +++ /dev/null @@ -1,569 +0,0 @@ -package gtPlusPlus.plugin.villagers.entity; - -import cpw.mods.fml.common.registry.VillagerRegistry; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import gtPlusPlus.plugin.villagers.NameLists; -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.Iterator; -import java.util.Random; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentData; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.Entity; -import net.minecraft.entity.passive.EntityVillager; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.MathHelper; -import net.minecraft.util.Tuple; -import net.minecraft.village.MerchantRecipe; -import net.minecraft.village.MerchantRecipeList; -import net.minecraft.village.Village; -import net.minecraft.world.World; - -public class EntityBaseVillager extends EntityVillager { - - // public static final VillagerProfession mProfession; - - /* - * - * Your problem is that you are extending EntityVillager, but buyingList and - * addDefaultEquipment are both PRIVATE members of EntityVillager - you cannot - * use or override them without Reflection or ASM. - * - * What you can do, however, is override getRecipes to return your own list, but - * because you override EntityVillager, your mob is still using the villager's - * buyingList (which is NULL) when useRecipe or any other villager method is - * called. You either have to override every method from EntityVillager which - * interacts with buyingList and make it use your own list, or you need to not - * extend EntityVillager and just implement IMerchant instead. - */ - - private final int mRoleID; - - public EntityBaseVillager(World aWorld) { - this(aWorld, 0); - } - - public EntityBaseVillager(World aWorld, int aID) { - super(aWorld, aID); - mRoleID = aID; - } - - @Override - public void writeEntityToNBT(NBTTagCompound aNBT) { - if (this.hasCustomNameTag()) { - if (!aNBT.hasKey("aCustomName")) { - aNBT.setString("aCustomName", this.getCommandSenderName()); - } - } - super.writeEntityToNBT(aNBT); - } - - @Override - public void readEntityFromNBT(NBTTagCompound aNBT) { - if (aNBT.hasKey("aCustomName")) { - if (!this.getCustomNameTag().equals(aNBT.getString("aCustomName"))) { - this.setCustomNameTag(aNBT.getString("aCustomName")); - } - } - super.readEntityFromNBT(aNBT); - } - - @Override - public void writeToNBT(NBTTagCompound aNBT) { - // TODO Auto-generated method stub - super.writeToNBT(aNBT); - } - - @Override - public void readFromNBT(NBTTagCompound aNBT) { - // TODO Auto-generated method stub - super.readFromNBT(aNBT); - } - - @Override - protected boolean canDespawn() { - return !this.hasCustomNameTag(); - } - - @Override - public void setProfession(int p_70938_1_) { - super.setProfession(p_70938_1_); - } - - @Override - public int getProfession() { - int prof = super.getProfession(); - // Logger.INFO(""+mRoleID); - return prof < 7735 ? 7738 : prof; - } - - @Override - public void useRecipe(MerchantRecipe p_70933_1_) { - super.useRecipe(p_70933_1_); - } - - @Override - public void setRecipes(MerchantRecipeList p_70930_1_) { - super.setRecipes(p_70930_1_); - } - - public boolean shouldAlwaysSprint() { - return false; - } - ; - - @Override - public void onLivingUpdate() { - - // Set Custom Name - if (!this.hasCustomNameTag()) { - this.setCustomNameTag(NameLists.generateRandomName()); - } - - super.onLivingUpdate(); - - // Make these guys always sprint - if (shouldAlwaysSprint()) { - if (!this.isSprinting()) { - this.setSprinting(true); - } - } else { - if (this.isSprinting()) { - this.setSprinting(false); - } - } - } - - @Override - public Entity getEntityToAttack() { - return super.getEntityToAttack(); - } - - @Override - public boolean getAlwaysRenderNameTag() { - return hasCustomNameTag(); - } - - @Override - public Random getRNG() { - return CORE.RANDOM; - } - - @Override - public void setSprinting(boolean bool) { - super.setSprinting(bool); - } - - /** - * Custom Shit - */ - protected float getField_82191_bN() { - Field v82191 = ReflectionUtils.getField(getClass(), "field_82191_bN"); - try { - return v82191 != null ? v82191.getFloat(this) : 0f; - } catch (IllegalArgumentException | IllegalAccessException e) { - return 0f; - } - } - - protected void setField_82191_bN(float f) { - try { - ReflectionUtils.setField(this, "field_82191_bN", f); - } catch (IllegalArgumentException e) { - } - } - - protected boolean getNeedsInitilization() { - Field v82191 = ReflectionUtils.getField(EntityVillager.class, "needsInitilization"); - try { - return v82191 != null ? v82191.getBoolean(this) : false; - } catch (IllegalArgumentException | IllegalAccessException e) { - return false; - } - } - - protected void setNeedsInitilization(boolean f) { - try { - ReflectionUtils.setField(this, "needsInitilization", f); - } catch (IllegalArgumentException e) { - } - } - - protected MerchantRecipeList getBuyingList() { - Field v82191; - MerchantRecipeList o = null; - v82191 = ReflectionUtils.getField(getClass(), "buyingList"); - try { - if (v82191 != null) o = (MerchantRecipeList) v82191.get(this); - Logger.WARNING("Is BuyingList Valid? " + (v82191 != null)); - return v82191 != null ? o : null; - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - return null; - } - } - - protected void setBuyingList(MerchantRecipeList f) { - try { - Logger.WARNING("set BuyingList? " + (ReflectionUtils.setField(this, "buyingList", f))); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } - } - - protected Village getVillageObject() { - Field v82191 = ReflectionUtils.getField(getClass(), "villageObj"); - try { - return v82191 != null ? (Village) v82191.get(this) : null; - } catch (IllegalArgumentException | IllegalAccessException e) { - return null; - } - } - - protected String getLastBuyingPlayer() { - Field v82191 = ReflectionUtils.getField(getClass(), "lastBuyingPlayer"); - try { - return v82191 != null ? (String) v82191.get(this) : ""; - } catch (IllegalArgumentException | IllegalAccessException e) { - return ""; - } - } - - public MerchantRecipeList getRecipes(EntityPlayer p_70934_1_) { - if (getBuyingList() == null) { - this.addDefaultEquipmentAndRecipies(1); - } - return getBuyingList(); - } - - /** - * Adjusts the probability of obtaining a given recipe being offered by a - * villager - */ - private float adjustProbability(float p_82188_1_) { - float f1 = p_82188_1_ + getField_82191_bN(); - return f1 > 0.9F ? 0.9F - (f1 - 0.9F) : f1; - } - - /** - * based on the villagers profession add items, equipment, and recipies adds - * par1 random items to the list of things that the villager wants to buy. (at - * most 1 of each wanted type is added) - */ - private void addDefaultEquipmentAndRecipies(int p_70950_1_) { - if (this.getBuyingList() != null) { - setField_82191_bN(MathHelper.sqrt_float((float) this.getBuyingList().size()) * 0.2F); - } else { - setField_82191_bN(0.0F); - } - - MerchantRecipeList merchantrecipelist; - merchantrecipelist = new MerchantRecipeList(); - VillagerRegistry.manageVillagerTrades(merchantrecipelist, this, this.getProfession(), this.rand); - int k; - label50: - switch (this.getProfession()) { - case 0: - addPurchaseRecipe(merchantrecipelist, Items.wheat, this.rand, this.adjustProbability(0.9F)); - addPurchaseRecipe( - merchantrecipelist, - Item.getItemFromBlock(Blocks.wool), - this.rand, - this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.chicken, this.rand, this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.cooked_fished, this.rand, this.adjustProbability(0.4F)); - addEmeraldTrade(merchantrecipelist, Items.bread, this.rand, this.adjustProbability(0.9F)); - addEmeraldTrade(merchantrecipelist, Items.melon, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.apple, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.cookie, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.shears, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.flint_and_steel, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.cooked_chicken, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.arrow, this.rand, this.adjustProbability(0.5F)); - - if (this.rand.nextFloat() < this.adjustProbability(0.5F)) { - merchantrecipelist.add(new MerchantRecipe( - new ItemStack(Blocks.gravel, 10), - new ItemStack(Items.emerald), - new ItemStack(Items.flint, 4 + this.rand.nextInt(2), 0))); - } - - break; - case 1: - addPurchaseRecipe(merchantrecipelist, Items.paper, this.rand, this.adjustProbability(0.8F)); - addPurchaseRecipe(merchantrecipelist, Items.book, this.rand, this.adjustProbability(0.8F)); - addPurchaseRecipe(merchantrecipelist, Items.written_book, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade( - merchantrecipelist, - Item.getItemFromBlock(Blocks.bookshelf), - this.rand, - this.adjustProbability(0.8F)); - addEmeraldTrade( - merchantrecipelist, - Item.getItemFromBlock(Blocks.glass), - this.rand, - this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.compass, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.clock, this.rand, this.adjustProbability(0.2F)); - - if (this.rand.nextFloat() < this.adjustProbability(0.07F)) { - Enchantment enchantment = Enchantment.enchantmentsBookList[ - this.rand.nextInt(Enchantment.enchantmentsBookList.length)]; - int i1 = MathHelper.getRandomIntegerInRange( - this.rand, enchantment.getMinLevel(), enchantment.getMaxLevel()); - ItemStack itemstack = - Items.enchanted_book.getEnchantedItemStack(new EnchantmentData(enchantment, i1)); - k = 2 + this.rand.nextInt(5 + i1 * 10) + 3 * i1; - merchantrecipelist.add( - new MerchantRecipe(new ItemStack(Items.book), new ItemStack(Items.emerald, k), itemstack)); - } - - break; - case 2: - addEmeraldTrade(merchantrecipelist, Items.ender_eye, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.experience_bottle, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.redstone, this.rand, this.adjustProbability(0.4F)); - addEmeraldTrade( - merchantrecipelist, - Item.getItemFromBlock(Blocks.glowstone), - this.rand, - this.adjustProbability(0.3F)); - Item[] aitem = new Item[] { - Items.iron_sword, - Items.diamond_sword, - Items.iron_chestplate, - Items.diamond_chestplate, - Items.iron_axe, - Items.diamond_axe, - Items.iron_pickaxe, - Items.diamond_pickaxe - }; - Item[] aitem1 = aitem; - int j = aitem.length; - k = 0; - - while (true) { - if (k >= j) { - break label50; - } - - Item item = aitem1[k]; - - if (this.rand.nextFloat() < this.adjustProbability(0.05F)) { - merchantrecipelist.add(new MerchantRecipe( - new ItemStack(item, 1, 0), - new ItemStack(Items.emerald, 2 + this.rand.nextInt(3), 0), - EnchantmentHelper.addRandomEnchantment( - this.rand, new ItemStack(item, 1, 0), 5 + this.rand.nextInt(15)))); - } - - ++k; - } - case 3: - addPurchaseRecipe(merchantrecipelist, Items.coal, this.rand, this.adjustProbability(0.7F)); - addPurchaseRecipe(merchantrecipelist, Items.iron_ingot, this.rand, this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.gold_ingot, this.rand, this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.diamond, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.iron_sword, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_sword, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.iron_axe, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_axe, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.iron_pickaxe, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_pickaxe, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.iron_shovel, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_shovel, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_hoe, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_hoe, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_boots, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_boots, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_helmet, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_helmet, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_chestplate, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_chestplate, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_leggings, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_leggings, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.chainmail_boots, this.rand, this.adjustProbability(0.1F)); - addEmeraldTrade(merchantrecipelist, Items.chainmail_helmet, this.rand, this.adjustProbability(0.1F)); - addEmeraldTrade( - merchantrecipelist, Items.chainmail_chestplate, this.rand, this.adjustProbability(0.1F)); - addEmeraldTrade(merchantrecipelist, Items.chainmail_leggings, this.rand, this.adjustProbability(0.1F)); - break; - case 4: - addPurchaseRecipe(merchantrecipelist, Items.coal, this.rand, this.adjustProbability(0.7F)); - addPurchaseRecipe(merchantrecipelist, Items.porkchop, this.rand, this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.beef, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.saddle, this.rand, this.adjustProbability(0.1F)); - addEmeraldTrade(merchantrecipelist, Items.leather_chestplate, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.leather_boots, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.leather_helmet, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.leather_leggings, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.cooked_porkchop, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.cooked_beef, this.rand, this.adjustProbability(0.3F)); - } - - if (merchantrecipelist.isEmpty()) { - addPurchaseRecipe(merchantrecipelist, Items.gold_ingot, this.rand, 1.0F); - } - - Collections.shuffle(merchantrecipelist); - - if (this.getBuyingList() == null) { - this.setBuyingList(new MerchantRecipeList()); - } - - for (int l = 0; l < p_70950_1_ && l < merchantrecipelist.size(); ++l) { - try { - this.getBuyingList().addToListWithCheck((MerchantRecipe) merchantrecipelist.get(l)); - } catch (Throwable t) { - Logger.INFO("Villager with ID " + this.entityUniqueID.toString() + " at | X: " + this.posX + " Y: " - + this.posY + " Z: " + this.posZ - + " may have corrupt trades, it is advised to remove/kill it."); - } - } - - try { - if (this.getBuyingList() != null) { - for (Object g : this.getBuyingList()) { - if (g != null) { - if (g instanceof MerchantRecipe) { - MerchantRecipe m = (MerchantRecipe) g; - ItemStack selling = m.getItemToSell(); - ItemStack[] buying = new ItemStack[] { - m.getItemToBuy(), m.getSecondItemToBuy() != null ? m.getSecondItemToBuy() : null - }; - if (selling == null) { - Logger.WARNING("Villager is Selling an invalid item"); - } else if (buying[0] == null && buying[1] == null) { - Logger.WARNING("Villager is buying two invalid items"); - } else { - Logger.WARNING( - "Villager is Selling x" + selling.stackSize + selling.getDisplayName() - + " for x" + buying[0].stackSize + " " - + buying[0].getDisplayName() + buying[1] - != null - ? " and for x" + buying[1].stackSize + " " + buying[1].getDisplayName() - : ""); - } - } else Logger.WARNING("Found: " + g.getClass().getName()); - } - } - } else { - - } - } catch (Throwable t) { - - } - } - - /** - * main AI tick function, replaces updateEntityActionState - */ - @Override - protected void updateAITick() { - if (!this.isTrading()) { - if (this.getNeedsInitilization()) { - if (this.getBuyingList().size() > 1) { - Iterator<MerchantRecipe> iterator = this.getBuyingList().iterator(); - - while (iterator.hasNext()) { - MerchantRecipe merchantrecipe = (MerchantRecipe) iterator.next(); - - if (merchantrecipe.isRecipeDisabled()) { - merchantrecipe.func_82783_a(this.rand.nextInt(6) + this.rand.nextInt(6) + 2); - } - } - } - - this.addDefaultEquipmentAndRecipies(1); - this.setNeedsInitilization(false); - - if (this.getVillageObject() != null && this.getLastBuyingPlayer() != null) { - this.worldObj.setEntityState(this, (byte) 14); - this.getVillageObject().setReputationForPlayer(this.getLastBuyingPlayer(), 1); - } - } - } - super.updateAITick(); - } - - public static void addEmeraldTrade(MerchantRecipeList aRecipeList, Item aItem, Random aRand, float aChance) { - if (aRand.nextFloat() < aChance) { - int i = getLootAmount_BlacksmithSellingList(aItem, aRand); - ItemStack itemstack; - ItemStack itemstack1; - - if (i < 0) { - itemstack = new ItemStack(Items.emerald, 1, 0); - itemstack1 = new ItemStack(aItem, -i, 0); - } else { - itemstack = new ItemStack(Items.emerald, i, 0); - itemstack1 = new ItemStack(aItem, 1, 0); - } - - aRecipeList.add(new MerchantRecipe(itemstack, itemstack1)); - } - } - - public static void addCustomTrade( - MerchantRecipeList aRecipeList, - ItemStack aItem1, - ItemStack aItem2, - ItemStack aItem3, - Random aRand, - float aChance) { - if (aRand.nextFloat() < aChance) { - aRecipeList.add(new MerchantRecipe(aItem1, aItem2, aItem3)); - } - } - - private static int getLootAmount_BlacksmithSellingList(Item aItem, Random aRand) { - Tuple tuple = (Tuple) blacksmithSellingList.get(aItem); - return tuple == null - ? 1 - : (((Integer) tuple.getFirst()).intValue() >= ((Integer) tuple.getSecond()).intValue() - ? ((Integer) tuple.getFirst()).intValue() - : ((Integer) tuple.getFirst()).intValue() - + aRand.nextInt(((Integer) tuple.getSecond()).intValue() - - ((Integer) tuple.getFirst()).intValue())); - } - - public static void addPurchaseRecipe(MerchantRecipeList aTradeList, Item aItem, Random aRand, float aChance) { - if (aRand.nextFloat() < aChance) { - aTradeList.add(new MerchantRecipe(getSimpleLootStack(aItem, aRand), Items.emerald)); - } - } - - private static ItemStack getSimpleLootStack(Item aItem, Random aRand) { - return new ItemStack(aItem, getLootAmount_VillagerSellingList(aItem, aRand), 0); - } - - public static void addPurchaseRecipe( - MerchantRecipeList aTradeList, Item aItem, int aMeta, Random aRand, float aChance) { - if (aRand.nextFloat() < aChance) { - aTradeList.add(new MerchantRecipe(getComplexLootStack(aItem, aMeta, aRand), Items.emerald)); - } - } - - private static ItemStack getComplexLootStack(Item aItem, int aMeta, Random aRand) { - return new ItemStack(aItem, getLootAmount_VillagerSellingList(aItem, aRand), aMeta); - } - - private static int getLootAmount_VillagerSellingList(Item aItem, Random aRand) { - Tuple tuple = (Tuple) villagersSellingList.get(aItem); - return tuple == null - ? 1 - : (((Integer) tuple.getFirst()).intValue() >= ((Integer) tuple.getSecond()).intValue() - ? ((Integer) tuple.getFirst()).intValue() - : ((Integer) tuple.getFirst()).intValue() - + aRand.nextInt(((Integer) tuple.getSecond()).intValue() - - ((Integer) tuple.getFirst()).intValue())); - } -} diff --git a/src/main/java/gtPlusPlus/plugin/villagers/entity/EntityNativeAustralian.java b/src/main/java/gtPlusPlus/plugin/villagers/entity/EntityNativeAustralian.java deleted file mode 100644 index 000d98af0d..0000000000 --- a/src/main/java/gtPlusPlus/plugin/villagers/entity/EntityNativeAustralian.java +++ /dev/null @@ -1,557 +0,0 @@ -package gtPlusPlus.plugin.villagers.entity; - -import cpw.mods.fml.common.registry.VillagerRegistry; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.Iterator; -import java.util.Random; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentData; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityAgeable; -import net.minecraft.entity.IEntityLivingData; -import net.minecraft.entity.passive.EntityVillager; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.MathHelper; -import net.minecraft.util.Tuple; -import net.minecraft.village.MerchantRecipe; -import net.minecraft.village.MerchantRecipeList; -import net.minecraft.village.Village; -import net.minecraft.world.World; - -public class EntityNativeAustralian extends EntityVillager { - - // public static final VillagerProfession mProfession; - - /* - * - * Your problem is that you are extending EntityVillager, but buyingList and - * addDefaultEquipment are both PRIVATE members of EntityVillager - you cannot - * use or override them without Reflection or ASM. - * - * What you can do, however, is override getRecipes to return your own list, but - * because you override EntityVillager, your mob is still using the villager's - * buyingList (which is NULL) when useRecipe or any other villager method is - * called. You either have to override every method from EntityVillager which - * interacts with buyingList and make it use your own list, or you need to not - * extend EntityVillager and just implement IMerchant instead. - */ - - private final int mRoleID; - - public EntityNativeAustralian(World aWorld) { - super(aWorld, 7738); - mRoleID = 7738; - } - - public EntityVillager createChild(EntityAgeable p_90011_1_) { - EntityNativeAustralian entityvillager = new EntityNativeAustralian(this.worldObj); - entityvillager.onSpawnWithEgg((IEntityLivingData) null); - return entityvillager; - } - - public boolean allowLeashing() { - return true; - } - - @Override - public void writeEntityToNBT(NBTTagCompound aNBT) { - if (this.hasCustomNameTag()) { - if (!aNBT.hasKey("aCustomName")) { - aNBT.setString("aCustomName", this.getCommandSenderName()); - } - } - super.writeEntityToNBT(aNBT); - } - - @Override - public void readEntityFromNBT(NBTTagCompound aNBT) { - if (aNBT.hasKey("aCustomName")) { - if (!this.getCustomNameTag().equals(aNBT.getString("aCustomName"))) { - this.setCustomNameTag(aNBT.getString("aCustomName")); - } - } - super.readEntityFromNBT(aNBT); - } - - @Override - public void writeToNBT(NBTTagCompound aNBT) { - // TODO Auto-generated method stub - super.writeToNBT(aNBT); - } - - @Override - public void readFromNBT(NBTTagCompound aNBT) { - // TODO Auto-generated method stub - super.readFromNBT(aNBT); - } - - @Override - protected boolean canDespawn() { - return !false; - } - - @Override - public void setProfession(int p_70938_1_) { - super.setProfession(7738); - } - - @Override - public int getProfession() { - return mRoleID; - } - - @Override - public void useRecipe(MerchantRecipe p_70933_1_) { - super.useRecipe(p_70933_1_); - } - - @Override - public void setRecipes(MerchantRecipeList p_70930_1_) { - super.setRecipes(p_70930_1_); - } - - public boolean shouldAlwaysSprint() { - return false; - } - ; - - @Override - public void onLivingUpdate() { - super.onLivingUpdate(); - } - - @Override - public Entity getEntityToAttack() { - return super.getEntityToAttack(); - } - - @Override - public boolean getAlwaysRenderNameTag() { - return hasCustomNameTag(); - } - - @Override - public Random getRNG() { - return CORE.RANDOM; - } - - @Override - public void setSprinting(boolean bool) { - super.setSprinting(bool); - } - - /** - * Custom Shit - */ - protected float getField_82191_bN() { - Field v82191 = ReflectionUtils.getField(getClass(), "field_82191_bN"); - try { - return v82191 != null ? v82191.getFloat(this) : 0f; - } catch (IllegalArgumentException | IllegalAccessException e) { - return 0f; - } - } - - protected void setField_82191_bN(float f) { - try { - ReflectionUtils.setField(this, "field_82191_bN", f); - } catch (IllegalArgumentException e) { - } - } - - protected boolean getNeedsInitilization() { - Field v82191 = ReflectionUtils.getField(EntityVillager.class, "needsInitilization"); - try { - return v82191 != null ? v82191.getBoolean(this) : false; - } catch (IllegalArgumentException | IllegalAccessException e) { - return false; - } - } - - protected void setNeedsInitilization(boolean f) { - try { - ReflectionUtils.setField(this, "needsInitilization", f); - } catch (IllegalArgumentException e) { - } - } - - protected MerchantRecipeList getBuyingList() { - Field v82191; - MerchantRecipeList o = null; - v82191 = ReflectionUtils.getField(getClass(), "buyingList"); - try { - if (v82191 != null) o = (MerchantRecipeList) v82191.get(this); - Logger.WARNING("Is BuyingList Valid? " + (v82191 != null)); - return v82191 != null ? o : null; - } catch (IllegalArgumentException | IllegalAccessException e) { - e.printStackTrace(); - return null; - } - } - - protected void setBuyingList(MerchantRecipeList f) { - try { - Logger.WARNING("set BuyingList? " + (ReflectionUtils.setField(this, "buyingList", f))); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } - } - - protected Village getVillageObject() { - Field v82191 = ReflectionUtils.getField(getClass(), "villageObj"); - try { - return v82191 != null ? (Village) v82191.get(this) : null; - } catch (IllegalArgumentException | IllegalAccessException e) { - return null; - } - } - - protected String getLastBuyingPlayer() { - Field v82191 = ReflectionUtils.getField(getClass(), "lastBuyingPlayer"); - try { - return v82191 != null ? (String) v82191.get(this) : ""; - } catch (IllegalArgumentException | IllegalAccessException e) { - return ""; - } - } - - public MerchantRecipeList getRecipes(EntityPlayer p_70934_1_) { - if (getBuyingList() == null) { - this.addDefaultEquipmentAndRecipies(1); - } - return getBuyingList(); - } - - /** - * Adjusts the probability of obtaining a given recipe being offered by a - * villager - */ - private float adjustProbability(float p_82188_1_) { - float f1 = p_82188_1_ + getField_82191_bN(); - return f1 > 0.9F ? 0.9F - (f1 - 0.9F) : f1; - } - - /** - * based on the villagers profession add items, equipment, and recipies adds - * par1 random items to the list of things that the villager wants to buy. (at - * most 1 of each wanted type is added) - */ - private void addDefaultEquipmentAndRecipies(int p_70950_1_) { - if (this.getBuyingList() != null) { - setField_82191_bN(MathHelper.sqrt_float((float) this.getBuyingList().size()) * 0.2F); - } else { - setField_82191_bN(0.0F); - } - - MerchantRecipeList merchantrecipelist; - merchantrecipelist = new MerchantRecipeList(); - VillagerRegistry.manageVillagerTrades(merchantrecipelist, this, this.getProfession(), this.rand); - int k; - label50: - switch (this.getProfession()) { - case 0: - addPurchaseRecipe(merchantrecipelist, Items.wheat, this.rand, this.adjustProbability(0.9F)); - addPurchaseRecipe( - merchantrecipelist, - Item.getItemFromBlock(Blocks.wool), - this.rand, - this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.chicken, this.rand, this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.cooked_fished, this.rand, this.adjustProbability(0.4F)); - addEmeraldTrade(merchantrecipelist, Items.bread, this.rand, this.adjustProbability(0.9F)); - addEmeraldTrade(merchantrecipelist, Items.melon, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.apple, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.cookie, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.shears, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.flint_and_steel, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.cooked_chicken, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.arrow, this.rand, this.adjustProbability(0.5F)); - - if (this.rand.nextFloat() < this.adjustProbability(0.5F)) { - merchantrecipelist.add(new MerchantRecipe( - new ItemStack(Blocks.gravel, 10), - new ItemStack(Items.emerald), - new ItemStack(Items.flint, 4 + this.rand.nextInt(2), 0))); - } - - break; - case 1: - addPurchaseRecipe(merchantrecipelist, Items.paper, this.rand, this.adjustProbability(0.8F)); - addPurchaseRecipe(merchantrecipelist, Items.book, this.rand, this.adjustProbability(0.8F)); - addPurchaseRecipe(merchantrecipelist, Items.written_book, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade( - merchantrecipelist, - Item.getItemFromBlock(Blocks.bookshelf), - this.rand, - this.adjustProbability(0.8F)); - addEmeraldTrade( - merchantrecipelist, - Item.getItemFromBlock(Blocks.glass), - this.rand, - this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.compass, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.clock, this.rand, this.adjustProbability(0.2F)); - - if (this.rand.nextFloat() < this.adjustProbability(0.07F)) { - Enchantment enchantment = Enchantment.enchantmentsBookList[ - this.rand.nextInt(Enchantment.enchantmentsBookList.length)]; - int i1 = MathHelper.getRandomIntegerInRange( - this.rand, enchantment.getMinLevel(), enchantment.getMaxLevel()); - ItemStack itemstack = - Items.enchanted_book.getEnchantedItemStack(new EnchantmentData(enchantment, i1)); - k = 2 + this.rand.nextInt(5 + i1 * 10) + 3 * i1; - merchantrecipelist.add( - new MerchantRecipe(new ItemStack(Items.book), new ItemStack(Items.emerald, k), itemstack)); - } - - break; - case 2: - addEmeraldTrade(merchantrecipelist, Items.ender_eye, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.experience_bottle, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.redstone, this.rand, this.adjustProbability(0.4F)); - addEmeraldTrade( - merchantrecipelist, - Item.getItemFromBlock(Blocks.glowstone), - this.rand, - this.adjustProbability(0.3F)); - Item[] aitem = new Item[] { - Items.iron_sword, - Items.diamond_sword, - Items.iron_chestplate, - Items.diamond_chestplate, - Items.iron_axe, - Items.diamond_axe, - Items.iron_pickaxe, - Items.diamond_pickaxe - }; - Item[] aitem1 = aitem; - int j = aitem.length; - k = 0; - - while (true) { - if (k >= j) { - break label50; - } - - Item item = aitem1[k]; - - if (this.rand.nextFloat() < this.adjustProbability(0.05F)) { - merchantrecipelist.add(new MerchantRecipe( - new ItemStack(item, 1, 0), - new ItemStack(Items.emerald, 2 + this.rand.nextInt(3), 0), - EnchantmentHelper.addRandomEnchantment( - this.rand, new ItemStack(item, 1, 0), 5 + this.rand.nextInt(15)))); - } - - ++k; - } - case 3: - addPurchaseRecipe(merchantrecipelist, Items.coal, this.rand, this.adjustProbability(0.7F)); - addPurchaseRecipe(merchantrecipelist, Items.iron_ingot, this.rand, this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.gold_ingot, this.rand, this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.diamond, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.iron_sword, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_sword, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.iron_axe, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_axe, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.iron_pickaxe, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_pickaxe, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.iron_shovel, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_shovel, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_hoe, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_hoe, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_boots, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_boots, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_helmet, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_helmet, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_chestplate, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_chestplate, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.iron_leggings, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.diamond_leggings, this.rand, this.adjustProbability(0.2F)); - addEmeraldTrade(merchantrecipelist, Items.chainmail_boots, this.rand, this.adjustProbability(0.1F)); - addEmeraldTrade(merchantrecipelist, Items.chainmail_helmet, this.rand, this.adjustProbability(0.1F)); - addEmeraldTrade( - merchantrecipelist, Items.chainmail_chestplate, this.rand, this.adjustProbability(0.1F)); - addEmeraldTrade(merchantrecipelist, Items.chainmail_leggings, this.rand, this.adjustProbability(0.1F)); - break; - case 4: - addPurchaseRecipe(merchantrecipelist, Items.coal, this.rand, this.adjustProbability(0.7F)); - addPurchaseRecipe(merchantrecipelist, Items.porkchop, this.rand, this.adjustProbability(0.5F)); - addPurchaseRecipe(merchantrecipelist, Items.beef, this.rand, this.adjustProbability(0.5F)); - addEmeraldTrade(merchantrecipelist, Items.saddle, this.rand, this.adjustProbability(0.1F)); - addEmeraldTrade(merchantrecipelist, Items.leather_chestplate, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.leather_boots, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.leather_helmet, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.leather_leggings, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.cooked_porkchop, this.rand, this.adjustProbability(0.3F)); - addEmeraldTrade(merchantrecipelist, Items.cooked_beef, this.rand, this.adjustProbability(0.3F)); - } - - if (merchantrecipelist.isEmpty()) { - addPurchaseRecipe(merchantrecipelist, Items.gold_ingot, this.rand, 1.0F); - } - - Collections.shuffle(merchantrecipelist); - - if (this.getBuyingList() == null) { - this.setBuyingList(new MerchantRecipeList()); - } - - for (int l = 0; l < p_70950_1_ && l < merchantrecipelist.size(); ++l) { - try { - this.getBuyingList().addToListWithCheck((MerchantRecipe) merchantrecipelist.get(l)); - } catch (Throwable t) { - Logger.INFO("Villager with ID " + this.entityUniqueID.toString() + " at | X: " + this.posX + " Y: " - + this.posY + " Z: " + this.posZ - + " may have corrupt trades, it is advised to remove/kill it."); - } - } - - try { - if (this.getBuyingList() != null) { - for (Object g : this.getBuyingList()) { - if (g != null) { - if (g instanceof MerchantRecipe) { - MerchantRecipe m = (MerchantRecipe) g; - ItemStack selling = m.getItemToSell(); - ItemStack[] buying = new ItemStack[] { - m.getItemToBuy(), m.getSecondItemToBuy() != null ? m.getSecondItemToBuy() : null - }; - if (selling == null) { - Logger.WARNING("Villager is Selling an invalid item"); - } else if (buying[0] == null && buying[1] == null) { - Logger.WARNING("Villager is buying two invalid items"); - } else { - Logger.WARNING( - "Villager is Selling x" + selling.stackSize + selling.getDisplayName() - + " for x" + buying[0].stackSize + " " - + buying[0].getDisplayName() + buying[1] - != null - ? " and for x" + buying[1].stackSize + " " + buying[1].getDisplayName() - : ""); - } - } else Logger.WARNING("Found: " + g.getClass().getName()); - } - } - } else { - - } - } catch (Throwable t) { - - } - } - - /** - * main AI tick function, replaces updateEntityActionState - */ - @Override - protected void updateAITick() { - if (!this.isTrading()) { - if (this.getNeedsInitilization()) { - if (this.getBuyingList().size() > 1) { - Iterator<MerchantRecipe> iterator = this.getBuyingList().iterator(); - - while (iterator.hasNext()) { - MerchantRecipe merchantrecipe = (MerchantRecipe) iterator.next(); - - if (merchantrecipe.isRecipeDisabled()) { - merchantrecipe.func_82783_a(this.rand.nextInt(6) + this.rand.nextInt(6) + 2); - } - } - } - - this.addDefaultEquipmentAndRecipies(1); - this.setNeedsInitilization(false); - - if (this.getVillageObject() != null && this.getLastBuyingPlayer() != null) { - this.worldObj.setEntityState(this, (byte) 14); - this.getVillageObject().setReputationForPlayer(this.getLastBuyingPlayer(), 1); - } - } - } - super.updateAITick(); - } - - public static void addEmeraldTrade(MerchantRecipeList aRecipeList, Item aItem, Random aRand, float aChance) { - if (aRand.nextFloat() < aChance) { - int i = getLootAmount_BlacksmithSellingList(aItem, aRand); - ItemStack itemstack; - ItemStack itemstack1; - - if (i < 0) { - itemstack = new ItemStack(Items.emerald, 1, 0); - itemstack1 = new ItemStack(aItem, -i, 0); - } else { - itemstack = new ItemStack(Items.emerald, i, 0); - itemstack1 = new ItemStack(aItem, 1, 0); - } - - aRecipeList.add(new MerchantRecipe(itemstack, itemstack1)); - } - } - - public static void addCustomTrade( - MerchantRecipeList aRecipeList, - ItemStack aItem1, - ItemStack aItem2, - ItemStack aItem3, - Random aRand, - float aChance) { - if (aRand.nextFloat() < aChance) { - aRecipeList.add(new MerchantRecipe(aItem1, aItem2, aItem3)); - } - } - - private static int getLootAmount_BlacksmithSellingList(Item aItem, Random aRand) { - Tuple tuple = (Tuple) blacksmithSellingList.get(aItem); - return tuple == null - ? 1 - : (((Integer) tuple.getFirst()).intValue() >= ((Integer) tuple.getSecond()).intValue() - ? ((Integer) tuple.getFirst()).intValue() - : ((Integer) tuple.getFirst()).intValue() - + aRand.nextInt(((Integer) tuple.getSecond()).intValue() - - ((Integer) tuple.getFirst()).intValue())); - } - - public static void addPurchaseRecipe(MerchantRecipeList aTradeList, Item aItem, Random aRand, float aChance) { - if (aRand.nextFloat() < aChance) { - aTradeList.add(new MerchantRecipe(getSimpleLootStack(aItem, aRand), Items.emerald)); - } - } - - private static ItemStack getSimpleLootStack(Item aItem, Random aRand) { - return new ItemStack(aItem, getLootAmount_VillagerSellingList(aItem, aRand), 0); - } - - public static void addPurchaseRecipe( - MerchantRecipeList aTradeList, Item aItem, int aMeta, Random aRand, float aChance) { - if (aRand.nextFloat() < aChance) { - aTradeList.add(new MerchantRecipe(getComplexLootStack(aItem, aMeta, aRand), Items.emerald)); - } - } - - private static ItemStack getComplexLootStack(Item aItem, int aMeta, Random aRand) { - return new ItemStack(aItem, getLootAmount_VillagerSellingList(aItem, aRand), aMeta); - } - - private static int getLootAmount_VillagerSellingList(Item aItem, Random aRand) { - Tuple tuple = (Tuple) villagersSellingList.get(aItem); - return tuple == null - ? 1 - : (((Integer) tuple.getFirst()).intValue() >= ((Integer) tuple.getSecond()).intValue() - ? ((Integer) tuple.getFirst()).intValue() - : ((Integer) tuple.getFirst()).intValue() - + aRand.nextInt(((Integer) tuple.getSecond()).intValue() - - ((Integer) tuple.getFirst()).intValue())); - } -} diff --git a/src/main/java/gtPlusPlus/plugin/villagers/entity/trade/BaseVillagerTrade.java b/src/main/java/gtPlusPlus/plugin/villagers/entity/trade/BaseVillagerTrade.java deleted file mode 100644 index 6ff46380b8..0000000000 --- a/src/main/java/gtPlusPlus/plugin/villagers/entity/trade/BaseVillagerTrade.java +++ /dev/null @@ -1,30 +0,0 @@ -package gtPlusPlus.plugin.villagers.entity.trade; - -import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler; -import java.util.Random; -import net.minecraft.entity.passive.EntityVillager; -import net.minecraft.village.MerchantRecipeList; - -public abstract class BaseVillagerTrade implements IVillageTradeHandler { - - /* - Recently in my mod I started working on a new villager and after doing so I could not figure out to assign new trades to this villager. - Registering the villager - VillagerRegistry.instance().registerVillageTradeHandler(i, new TradeHandler());} - VillagerRegistry.instance().registerVillagerId(8); - VillagerRegistry.instance().registerVillagerSkin(8, new ResourceLocation("chow", "textures/dealer.png")); - VillagerRegistry.instance().getRegisteredVillagers(); - In my trade handler for vanilla villagers it goes off case 0 for instance being the farmer. I thought that it being case 8 would represent the id 8 for the custom villager but it still doesn't work. Could anyone help me out with this please? - * - * - First, you'll need to make a new class that extends IVillageTradeHandler. - In the constructor, add ItemStacks of the items you want it to trade to an ArrayList, - then in the manipulateTradesForVillager method, have it make sure the villager is yours by using villager.getProfession() - and your villager ID, then in a for loop use recipeList.addToListWithCheck to add new instances of MerchantRecipe to your villager's trade list. - Then, in your mod's main class, register the trade handler with VillageRegistry.instance().registerVillagerTradeHandler(villagerId, instanceOfTradeHandler); - */ - - @Override - public abstract void manipulateTradesForVillager( - EntityVillager villager, MerchantRecipeList recipeList, Random random); -} diff --git a/src/main/java/gtPlusPlus/plugin/villagers/trade/TradeHandlerAboriginal.java b/src/main/java/gtPlusPlus/plugin/villagers/trade/TradeHandlerAboriginal.java deleted file mode 100644 index 3d087ea053..0000000000 --- a/src/main/java/gtPlusPlus/plugin/villagers/trade/TradeHandlerAboriginal.java +++ /dev/null @@ -1,163 +0,0 @@ -package gtPlusPlus.plugin.villagers.trade; - -import static java.util.Collections.shuffle; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.minecraft.ItemUtils; -import java.util.Random; -import net.minecraft.entity.passive.EntityVillager; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.village.MerchantRecipe; -import net.minecraft.village.MerchantRecipeList; - -public class TradeHandlerAboriginal extends TradeHandlerBase { - - private static final AutoMap<ItemStack> mInputs = new AutoMap<ItemStack>(); - private static final AutoMap<ItemStack> mOutputs = new AutoMap<ItemStack>(); - private static boolean initialised = false; - - public static void init() { - mOutputs.put(ItemUtils.getSimpleStack(Blocks.anvil, 1)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.bookshelf, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.cactus, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.dirt, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.cobblestone, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.mossy_cobblestone, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.pumpkin, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.hardened_clay, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.log, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.obsidian, 8)); - mOutputs.put(ItemUtils.getSimpleStack(Items.wheat, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.gravel, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Blocks.sand, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.apple, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.emerald, 1)); - mOutputs.put(ItemUtils.getSimpleStack(Items.diamond, 1)); - mOutputs.put(ItemUtils.getSimpleStack(Items.baked_potato, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.beef, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.bone, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.bread, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.carrot, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.potato, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.poisonous_potato, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.chicken, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.porkchop, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.cooked_beef, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.cooked_chicken, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.cooked_porkchop, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.fish, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.cooked_fished, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.feather, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.egg, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.gold_nugget, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.leather, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.melon_seeds, 0)); - mOutputs.put(ItemUtils.getSimpleStack(Items.reeds, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.wooden_door)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.log)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.log2)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.planks)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.sapling)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.sandstone)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.nether_brick)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.bookshelf)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.crafting_table)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.gravel)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.hardened_clay)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.cactus)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.quartz_block)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.stone)); - mInputs.put(ItemUtils.getSimpleStack(Blocks.mossy_cobblestone)); - mInputs.put(ItemUtils.getSimpleStack(Items.apple, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.emerald, 1)); - mInputs.put(ItemUtils.getSimpleStack(Items.diamond, 1)); - mInputs.put(ItemUtils.getSimpleStack(Items.baked_potato, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.beef, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.bone, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.bread, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.carrot, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.potato, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.poisonous_potato, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.chicken, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.porkchop, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.cooked_beef, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.cooked_chicken, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.cooked_porkchop, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.fish, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.cooked_fished, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.feather, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.egg, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.gold_nugget, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.leather, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.melon_seeds, 0)); - mInputs.put(ItemUtils.getSimpleStack(Items.reeds, 0)); - initialised = true; - } - - public TradeHandlerAboriginal() { - Logger.INFO("Created Trade Manager for 'Trader' villager profession type."); - } - - @SuppressWarnings("unchecked") - @Override - public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random) { - if (!initialised) { - init(); - } - if (initialised) { - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - recipeList.add(new MerchantRecipe(getInput(), getInput(), getOutput())); - shuffle(recipeList); - } - } - - private ItemStack getInput() { - ItemStack input = mInputs.get(MathUtils.randInt(0, mInputs.size() - 1)); - int outputSize = (input.stackSize == 0 - ? (Math.max(MathUtils.randInt(1, 64), MathUtils.randInt(1, 32))) - : input.stackSize); - return ItemUtils.getSimpleStack(input, outputSize); - } - - static final int MID_BOUND = 24; - - private ItemStack getOutput() { - ItemStack output = mOutputs.get(MathUtils.randInt(0, mOutputs.size() - 1)); - int outputSize = (output.stackSize == 0 - ? (Math.min( - MathUtils.randInt(MathUtils.randInt(1, MID_BOUND), MathUtils.randInt(MID_BOUND, 32)), - MathUtils.randInt(MathUtils.randInt(12, MID_BOUND), MathUtils.randInt(MID_BOUND, 48)))) - : output.stackSize); - return ItemUtils.getSimpleStack(output, outputSize); - } -} |