@Override public void render(TileEntityVillager tileEntity, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { World worldClient = tileEntity.getWorld(); IBlockState bs = worldClient.getBlockState(tileEntity.getPos()); String professionNameString = tileEntity.getProfession(); ResourceLocation professionName = new ResourceLocation(professionNameString); VillagerProfession profession = PROFESSIONS.getObject(professionName); if(profession == null) { profession = PROFESSIONS.getObjectById(0); } this.drawVillagerHead(x, y, z, bs, profession); }
public static void init() { mechanicProfession = new VillagerProfession(Names.MOD_ID + ":mechanic", Textures.VILLAGER_MECHANIC, "minecraft:textures/entity/zombie_villager/zombie_villager.png"); VillagerCareer career = new VillagerCareer(mechanicProfession, Names.MOD_ID + ".mechanic"); career.addTrade(1, new ListItemForEmeralds(Itemss.PCB_BLUEPRINT, new PriceInfo(10, 19)), new ListItemForEmeralds(Itemss.NUKE_VIRUS, new PriceInfo(1, 5)), new ListItemForEmeralds(Itemss.STOP_WORM, new PriceInfo(1, 5)) ); for (int i = 0; i < ItemAssemblyProgram.PROGRAMS_AMOUNT; i++) { career.addTrade(1, new ListItemForEmeralds(new ItemStack(Itemss.ASSEMBLY_PROGRAM, 1, i), new PriceInfo(5, 11))); } }
private static VillagerProfession regProfession(String name) { VillagerProfession prof = new VillagerProfession(HarshenCastle.MODID + ":" + name, HarshenCastle.MODID + ":textures/entity/villager/" + name + ".png", HarshenCastle.MODID + ":textures/entity/zombie_villager/" + name + ".png"); ForgeRegistries.VILLAGER_PROFESSIONS.register(prof); return prof; }
@Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { World world = sender.getEntityWorld(); if (!world.isRemote) { if (args.length == 0) { for (Map.Entry<Integer, String> kvp : VillagerRegistryHelper.getProfessionIdsAndNamesSortedById()) { sender.sendMessage(new TextComponentString(kvp.getKey() + ": " + kvp.getValue())); } return; } if (args.length == 2 && args[0].equals("profession")) { VillagerProfession profession = VillagerRegistryHelper.getProfession(args[1]); if (profession != null) { for (VillagerCareer career : new VTTVillagerProfession(profession).getCareers()) { VTTVillagerCareer vttCareer = new VTTVillagerCareer(career); sender.sendMessage(new TextComponentString(vttCareer.getId() + ": " + vttCareer.getName())); sender.sendMessage(new TextComponentString(" " + vttCareer.getCareerLevels() + " levels")); } } } } }
@SubscribeEvent public static void registerSoundEvents(RegistryEvent.Register<VillagerProfession> event) { if (!ModConfig.villagers) return; event.getRegistry().registerAll( MECHANIC_PROFESSION ); }
private void addVillager(String name, EntityVillager.ITradeList[][] trades) { VillagerProfession prof = new VillagerProfession(Const.MODRES + name, Const.MODRES + "textures/entity/villager/" + name + ".png", "minecraft:textures/entity/zombie_villager/zombie_villager.png"); VillagerProfRegistry.register(prof); VillagerCareer villager = new VillagerCareer(prof, name); for (int i = 0; i < trades.length; i++) { villager.addTrade(i + 1, trades[i]); } }
public void drawVillagerHead(double x, double y, double z, IBlockState block, VillagerProfession profession) { GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glPushMatrix(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glTranslated(x + 0.5, y, z + 0.5); GL11.glScalef(0.33333F, -0.33333F, -0.33333F); ResourceLocation villagerTexture = profession.getSkin(); if(this.rendererDispatcher == null) { this.rendererDispatcher = TileEntityRendererDispatcher.instance; } this.bindTexture(villagerTexture); Block b = block.getBlock(); int direction = b.getMetaFromState(block); this.head.rotateAngleX = 0F; this.head.rotateAngleY = direction * ((float)Math.PI / 2); this.head.rotateAngleZ = 0F; //this.setLightmapDisabled(true); this.head.render(0.3F); //this.setLightmapDisabled(false); GL11.glPopMatrix(); GL11.glPopAttrib(); }
public static void registerUselessVillager() { final VillagerProfession prof = new VillagerProfession( "openblocks:radio", "openblocks:textures/models/king-ish.png", "minecraft:textures/entity/zombie_villager/zombie_villager.png"); // TODO: zombie texture? GameRegistry.findRegistry(VillagerProfession.class).register(prof); final VillagerCareer career = new VillagerCareer(prof, "audiophile") .addTrade(1, new EmeraldForItems(Item.getItemFromBlock(Blocks.NOTEBLOCK), new PriceInfo(5, 7))) .addTrade(2, new ListItemForEmeralds(Item.getItemFromBlock(Blocks.JUKEBOX), new PriceInfo(10, 15))); // extra for sound quality! for (ItemStack record : OreDictionary.getOres("record")) career.addTrade(3, new ListItemForEmeralds(record.getItem(), new PriceInfo(3, 6))); }
@SubscribeEvent public static void onVillagerRegister(RegistryEvent.Register<VillagerProfession> event) { init(); event.getRegistry().register(mechanicProfession); }
private static VillagerCareer regCareer(VillagerProfession parent, String name, HarshenTrade trade) { return new VillagerCareer(parent, name).addTrade(1, trade); }
/** * Parses the contents of an individual trade file, and adds or removes the trades to or from the specified profession and career * @param fileContents */ private static void loadTradesFromFile(String fileContents) { // parse the provided string as JSON JsonObject jsonObject = new JsonParser().parse(fileContents).getAsJsonObject(); // identify the profession and career to apply these trades to String jsonProfession = jsonObject.get("Profession").getAsString(); String jsonCareer = jsonObject.get("Career").getAsString(); // get the specified career and profession from the villager registry VillagerProfession profession = VillagerRegistryHelper.getProfession(jsonProfession); if (profession == null) throw new UnknownProfessionException(jsonProfession); VillagerCareer career = new VTTVillagerProfession(profession).getCareer(jsonCareer); if (career == null) throw new UnknownCareerException(jsonCareer); // iterate over the trade recipes included in the offers object JsonArray jsonRecipes = jsonObject.get("Offers").getAsJsonObject().get("Recipes").getAsJsonArray(); for (JsonElement jsonRecipe : jsonRecipes) { JsonObject jsonRecipeObject = jsonRecipe.getAsJsonObject(); // get the level this trade change applies to, and what type of change it is String jsonRecipeAction = jsonRecipeObject.get("action").getAsString(); int jsonCareerLevel = (jsonRecipeObject.has("CareerLevel") ? jsonRecipeObject.get("CareerLevel").getAsInt() : 0); // add a new trade if we're supposed to add one if (jsonRecipeAction.equals("add")) { addTradeToCareer(career, jsonCareerLevel, jsonRecipeObject); } // or remove a trade if we're supposed to remove one else if (jsonRecipeAction.equals("remove")) { removeTradeFromCareer(career, jsonCareerLevel, jsonRecipeObject); } // if we're supposed to replace a trade else if (jsonRecipeAction.equals("replace")) { // remove the old one, and add a new one removeTradeFromCareer(career, jsonCareerLevel, jsonRecipeObject); addTradeToCareer(career, jsonCareerLevel, jsonRecipeObject); } // if we're supposed to clear the trades else if (jsonRecipeAction.equals("clear")) { // if a career level was specified... if (jsonCareerLevel > 0) { // clear the trades for that level clearCareerTrades(career, jsonCareerLevel); } // if not... else { // clear all the trades from the career clearCareerTrades(career); } } } // sort them so that the buying trades appear before the selling trades for each level (like vanilla) if (ModConfiguration.sortTrades) sortCareerTrades(career); }
@Override protected VillagerProfession chooseForgeProfession(int count, net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession prof) { return count == 0 ? VillagerRegistry.instance().getRegistry().getValue(new ResourceLocation("minecraft:librarian")) : CoreInit.professionScientist; }
public static void register(VillagerProfession quickdraw) { villagers.add(quickdraw); }
@SubscribeEvent public static void onRegistryEvent(RegistryEvent.Register<VillagerProfession> event) { for (VillagerProfession b : villagers) { event.getRegistry().register(b); } }
@SideOnly(Side.CLIENT) @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) { NBTTagCompound tagItemStack = stack.getTagCompound(); if(tagItemStack == null) return; StringBuilder tooltipText = new StringBuilder(); String name = tagItemStack.getString("Name"); if((name != null) && (name.length() > 0)) { tooltipText.append("Name:§b"); tooltipText.append(name); tooltipText.append("§r"); tooltip.add(tooltip.toString()); } String professionString = tagItemStack.getString("prf"); if((professionString == null) || (professionString.length() == 0)) professionString = "minecraft:farmer"; ResourceLocation professionName = new ResourceLocation(professionString); VillagerProfession profession = BlockVillagerTrader.PROFESSIONS.getObject(professionName); int careerId = TypeTransformer.fromUnsignedByte(tagItemStack.getByte("car")); VillagerCareer career = profession.getCareer(careerId); tooltipText = new StringBuilder(); tooltipText.append("entity.Villager."); tooltipText.append(career.getName()); String localizedCareer = I18n.format(tooltipText.toString()); tooltipText = new StringBuilder(); tooltipText.append("Profession:§b"); tooltipText.append(localizedCareer); tooltipText.append("§r"); tooltip.add(tooltipText.toString()); tooltipText = new StringBuilder(); tooltipText.append("Level:§b"); tooltipText.append(TypeTransformer.fromUnsignedByte(tagItemStack.getByte("lov"))); tooltipText.append("§r"); tooltip.add(tooltipText.toString()); }