![](https://forums.minecraftforge.net/uploads/set_resources_2/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
OrangeVillager61
Members-
Posts
339 -
Joined
-
Last visited
Everything posted by OrangeVillager61
-
Okay, I seem to have fixed most bugs but I have two major issues, firstly when overriding a villager, there's a around 50% chance it doesn't override and the original entity turns into a strange thing that looks like a villager but doesn't behave like an entity and I can go through it and doesn't obey the las of gravity. Also, the overrided villager doesn't gain a name until I reload the game. public class OverrideVillagers { @SubscribeEvent public void entityJoinedWorldEventHandler(EntityJoinWorldEvent event) { if (event.getEntity().getClass() == EntityVillager.class && Config.overwriteOriginalVillagers == 0) { event.getEntity().setDead(); doOverwriteVillager(event, (EntityVillager) event.getEntity()); } } private void doOverwriteVillager(EntityJoinWorldEvent event, EntityVillager entity) { if (entity.getProfession() >= 0 && entity.getProfession() <= 4) { IvVillager entityVillager = new IvVillager(entity.getWorld(), entity.getProfession()); entityVillager.setGrowingAge(entity.getGrowingAge()); entityVillager.onInitialSpawn(event.getWorld().getDifficultyForLocation(new BlockPos(entity)), (IEntityLivingData)null); entityVillager.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, 0.0F, 0.0F); event.getWorld().setEntityState(entityVillager, (byte)12); event.getWorld().spawnEntity(entityVillager); } } }
-
Okay, but I've been getting this error: Failed to save chunk net.minecraft.util.ReportedException: Saving entity NBT at net.minecraft.entity.Entity.writeToNBT(Entity.java:1877) ~[Entity.class:?] at net.minecraft.entity.Entity.writeToNBTOptional(Entity.java:1760) ~[Entity.class:?] at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:394) ~[AnvilChunkLoader.class:?] at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:191) [AnvilChunkLoader.class:?] at net.minecraft.world.gen.ChunkProviderServer.saveChunkData(ChunkProviderServer.java:209) [ChunkProviderServer.class:?] at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:237) [ChunkProviderServer.class:?] at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:1065) [WorldServer.class:?] at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:425) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.saveAllWorlds(IntegratedServer.java:238) [integratedServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:141) [integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_111] Caused by: java.lang.IllegalArgumentException: Empty string not allowed at net.minecraft.nbt.NBTTagString.<init>(NBTTagString.java:23) ~[NBTTagString.class:?] at net.minecraft.nbt.NBTTagCompound.setString(NBTTagCompound.java:158) ~[NBTTagCompound.class:?] at orangeVillager61.ImprovedVillagers.Entities.VillagerStorages.writeNBT(VillagerStorages.java:25) ~[VillagerStorages.class:?] at orangeVillager61.ImprovedVillagers.Entities.VillagerStorages.writeNBT(VillagerStorages.java:1) ~[VillagerStorages.class:?] at orangeVillager61.ImprovedVillagers.Entities.VillagerProvider.serializeNBT(VillagerProvider.java:53) ~[VillagerProvider.class:?] at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:123) ~[CapabilityDispatcher.class:?] at net.minecraft.entity.Entity.writeToNBT(Entity.java:1846) ~[Entity.class:?] ... 11 more
-
Ah, okay so this would work. @Override public NBTBase writeNBT(Capability<IVillagerStorage> capability, IVillagerStorage instance, EnumFacing side) { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger("Gender", instance.getGender()); compound.setString("Name", instance.getName()); return compound; } public void readNBT(Capability<IVillagerStorage> capability, IVillagerStorage instance, EnumFacing side, NBTBase nbt) { instance.setName(((NBTTagCompound) nbt).getString("Name")); instance.setGender(((NBTTagCompound) nbt).getInteger("Gender")); }
-
So this would work. @Override public NBTBase writeNBT(Capability<IVillagerStorage> capability, IVillagerStorage instance, EnumFacing side) { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger("Gender", instance.getGender()); compound.setString("Name", instance.getName()); return new NBTTagString(instance.getName()); } public void readNBT(Capability<IVillagerStorage> capability, IVillagerStorage instance, EnumFacing side, NBTBase nbt) { instance.setName(((NBTPrimitive) nbt).toString()); instance.setGender(((NBTPrimitive) nbt).getInt()); }
-
The crash said that I can't register two capabilities with the almost the same thing. @EventHandler public void preInit(FMLPreInitializationEvent e) { MinecraftForge.EVENT_BUS.register(new CapabilityHandler()); CapabilityManager.INSTANCE.register(IVillagerStorage.class, new VillagerStoragesGender(), VillagerStorage.class); CapabilityManager.INSTANCE.register(IVillagerStorage.class, new VillagerStoragesName(), VillagerStorage.class); } }
-
So how to have a capability use two variables? Since I tried using two of them and it crashed. public class VillagerStoragesName implements IStorage<IVillagerStorage> { @Override public NBTBase writeNBT(Capability<IVillagerStorage> capability, IVillagerStorage instance, EnumFacing side) { return new NBTTagString(instance.getName()); } public void readNBT(Capability<IVillagerStorage> capability, IVillagerStorage instance, EnumFacing side, NBTBase nbt) { instance.setName(((NBTPrimitive) nbt).toString()); } } public class VillagerStoragesGender implements IStorage<IVillagerStorage> { @Override public NBTBase writeNBT(Capability<IVillagerStorage> capability, IVillagerStorage instance, EnumFacing side) { return new NBTTagInt(instance.getGender()); } public void readNBT(Capability<IVillagerStorage> capability, IVillagerStorage instance, EnumFacing side, NBTBase nbt) { instance.setGender(((NBTPrimitive) nbt).getInt()); } }
-
Alright, so I'm trying to get MC to give every villager a name from a list I made, however this is not working. t protected String[] male_list = {"Bob", "Joseph", "Aaron", "Philp", "Adam", "Paul", "Donald", "Ryan", "Mark", "Brian", "Robert", "Willam", "Harold", "Anthony", "Julius", "Mathew", "Tyler", "Noah", "Patrick", "Caden", "Michael", "Jeffery", "James", "John", "Thomas", "Otto", "Bill", "Sheldon", "Leonard", "Howard", "Carter", "Theodore", "Herbert"}; protected String[] female_list = {"Karen", "Lessie", "Kayla", "Brianna", "Isabella", "Elizabeth", "Kira", "Jadzia", "Abigail", "Chloe", "Olivia", "Sophia", "Emily", "Charlotte", "Amelia", "Maria", "Daria", "Sarah", "Theodora", "Tia", "Jennifer", "Anglica", "Denna", "Tasha", "Catherine", "Lily", "Amy", "Penny", "Julina", "Audrey", "Avery"}; @Override public void readEntityFromNBT(NBTTagCompound compound){ this.name = this.getCustomNameTag(); System.out.println(this.name); this.Gender = compound.getInteger("Gender"); if (this.Gender != 1 || this.Gender != 2){ this.Gender = r.nextInt(2) + 1; } if (this.name == null){ if (this.Gender == 1){ this.name = male_list[r.nextInt(male_list.length)]; } else if (this.Gender == 2){ this.name = female_list[r.nextInt(female_list.length)]; } else if (this.Gender != 1 && this.Gender != 2){ this.name = "None"; System.out.println("Villager Gender Error"); } } }
-
So this would work? @SideOnly(Side.SERVER) public void initServerVars(){ BlockPos blockpos = new BlockPos(this); this.ivillageObj = this.getWorld().getVillageCollection().getNearestVillage(blockpos, 32); }@Override public boolean processInteract(EntityPlayer player, EnumHand hand){ ItemStack itemstack = player.getHeldItem(hand); this.initServerVars(); if (itemstack.getItem() == IvItems.thieving_nose && !player.capabilities.isCreativeMode && !this.isChild()) {...
-
Alright, but I've still be getting this crash, java.lang.NullPointerException: Unexpected error at orangeVillager61.ImprovedVillagers.Entities.IvVillager.processInteract(IvVillager.java:223) at net.minecraft.entity.EntityLiving.processInitialInteract(EntityLiving.java:1337) at net.minecraft.entity.player.EntityPlayer.interactOn(EntityPlayer.java:1273) at net.minecraft.client.multiplayer.PlayerControllerMP.interactWithEntity(PlayerControllerMP.java:573) at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1592) at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2274) at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2051) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1839) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1117) @Override public boolean processInteract(EntityPlayer player, EnumHand hand){ ItemStack itemstack = player.getHeldItem(hand); BlockPos blockpos = new BlockPos(this); this.ivillageObj = this.getWorld().getVillageCollection().getNearestVillage(blockpos, 32); // Crashing here. if (itemstack.getItem() == IvItems.thieving_nose && !player.capabilities.isCreativeMode && !this.isChild()) { ...
-
Whenever I spawn in a villager and it gets overridden, I get this error [FML]: A severe problem occurred during the spawning of an entity at ( 940.5,4.0, -362.5) java.lang.NoSuchMethodException: orangeVillager61.ImprovedVillagers.Entities.IvVillager.<init>(net.minecraft.world.World) at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_111] at java.lang.Class.getConstructor(Unknown Source) ~[?:1.8.0_111] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:96) [EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:73) [EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:48) [EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:63) [EntitySpawnHandler$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111] at net.minecraft.util.Util.runTask(Util.java:26) [util.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1107) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:405) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] I think it may be related to my nullpointer issue.
-
Reposting entity class + the AI I give to EntityVillagers and the IvVillager. public class IvVillager extends EntityVillager{ protected Village villageObj; public String name; public int Gender; protected boolean isWillingToMate; protected int wealth; private MerchantRecipeList buyingList; private String lastBuyingPlayer; private int careerId; private int careerLevel; private boolean isLookingForHome; private boolean areAdditionalTasksSet; private final InventoryBasic villagerInventory; Random r = new Random(); /** A multi-dimensional array mapping the various professions, careers and career levels that a Villager may offer */ protected String[] male_list = {"Bob", "Joseph", "Aaron", "Philp", "Adam", "Paul", "Donald", "Ryan", "Mark", "Brian", "Robert", "Willam", "Harold", "Anthony", "Julius", "Mathew", "Tyler", "Noah", "Patrick", "Caden", "Michael", "Jeffery", "James", "John", "Thomas", "Otto", "Bill", "Sheldon", "Leonard", "Howard", "Carter", "Theodore", "Herbert"}; protected String[] female_list = {"Karen", "Lessie", "Kayla", "Brianna", "Isabella", "Elizabeth", "Kira", "Jadzia", "Abigail", "Chloe", "Olivia", "Sophia", "Emily", "Charlotte", "Amelia", "Maria", "Daria", "Sarah", "Theodora", "Tia", "Jennifer", "Anglica", "Denna", "Tasha", "Catherine", "Lily", "Amy", "Penny", "Julina", "Audrey", "Avery"}; public IvVillager(World world, int professionId) { super(world, professionId); this.villagerInventory = new InventoryBasic("Items", false, ; this.setCanPickUpLoot(true); this.setProfession(professionId); } public InventoryBasic getVillagerInventory() { return this.villagerInventory; } private void setAdditionalAItasks() { if (!this.areAdditionalTasksSet) { this.areAdditionalTasksSet = true; if (this.isChild()) { this.tasks.addTask(8, new EntityAIPlay(this, 0.32D)); } else if (this.getProfession() == 0) { this.tasks.addTask(6, new EntityAIHarvestFarmland(this, 0.6D)); } } } @Override public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); compound.setInteger("Profession", this.getProfession()); compound.setString("ProfessionName", this.getProfessionForge().getRegistryName().toString()); compound.setInteger("Riches", this.wealth); compound.setInteger("Career", this.careerId); compound.setInteger("CareerLevel", this.careerLevel); compound.setBoolean("Willing", this.isWillingToMate); if (this.buyingList != null) { compound.setTag("Offers", this.buyingList.getRecipiesAsTags()); } NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.getVillagerInventory().getSizeInventory(); ++i) { ItemStack itemstack = this.villagerInventory.getStackInSlot(i); if (!itemstack.isEmpty()) { nbttaglist.appendTag(itemstack.writeToNBT(new NBTTagCompound())); } } compound.setTag("Inventory", nbttaglist); if (compound.getInteger("Gender") != 1 || compound.getInteger("Gender") != 2) { compound.setInteger("Gender", this.Gender); } if (this.getCustomNameTag() == null){ if (compound.getInteger("Gender") == 1){ this.setCustomNameTag(male_list[r.nextInt(male_list.length)]); } if (compound.getInteger("Gender") == 2){ this.setCustomNameTag(female_list[r.nextInt(female_list.length)]); } } } @Override public void readEntityFromNBT(NBTTagCompound compound){ super.writeEntityToNBT(compound); this.name = this.getCustomNameTag(); this.Gender = compound.getInteger("Gender"); this.setProfession(compound.getInteger("Profession")); if (compound.hasKey("ProfessionName")) { net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession p = net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(new net.minecraft.util.ResourceLocation(compound.getString("ProfessionName"))); if (p == null) p = net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(new net.minecraft.util.ResourceLocation("minecraft:farmer")); this.setProfession(p); } this.wealth = compound.getInteger("Riches"); this.careerId = compound.getInteger("Career"); this.careerLevel = compound.getInteger("CareerLevel"); this.isWillingToMate = compound.getBoolean("Willing"); if (compound.hasKey("Offers", 10)) { NBTTagCompound nbttagcompound = compound.getCompoundTag("Offers"); this.buyingList = new MerchantRecipeList(nbttagcompound); } NBTTagList nbttaglist = compound.getTagList("Inventory", 10); for (int i = 0; i < nbttaglist.tagCount(); ++i) { ItemStack itemstack = new ItemStack(nbttaglist.getCompoundTagAt(i)); if (!itemstack.isEmpty()) { this.villagerInventory.addItem(itemstack); } } this.setCanPickUpLoot(true); this.setAdditionalAItasks(); } private void populateBuyingList() { if (this.careerId != 0 && this.careerLevel != 0) { ++this.careerLevel; } else { this.careerId = this.getProfessionForge().getRandomCareer(this.rand) + 1; this.careerLevel = 1; } if (this.buyingList == null) { this.buyingList = new MerchantRecipeList(); } int i = this.careerId - 1; int j = this.careerLevel - 1; java.util.List<EntityVillager.ITradeList> trades = this.getProfessionForge().getCareer(i).getTrades(j); if (trades != null) { for (EntityVillager.ITradeList entityvillager$itradelist : trades) { entityvillager$itradelist.addMerchantRecipe(this, this.buyingList, this.rand); } } } @Override public boolean processInteract(EntityPlayer player, EnumHand hand){ BlockPos blockpos = new BlockPos(this); this.villageObj = this.world.getVillageCollection().getNearestVillage(blockpos, 32); ItemStack itemstack = player.getHeldItem(hand); if (itemstack.getItem() == IvItems.thieving_nose && !player.capabilities.isCreativeMode && !this.isChild()) { itemstack.damageItem(1, player); if (rand.nextInt(10) + 1 < 6){ } if (rand.nextInt(10) + 1 < 9 && rand.nextInt(10) + 1 > 5){ player.dropItem(new ItemStack(Items.EMERALD, r.nextInt(2) + 1), false); } if (rand.nextInt(10) + 1 < 10 && rand.nextInt(10) + 1 > { player.dropItem(new ItemStack(Items.EMERALD, r.nextInt(6) + 3), false); } if (this.villageObj != null) { this.villageObj.modifyPlayerReputation(player.getName(), -2); } return true; } else if (!this.holdingSpawnEggOfClass(itemstack, this.getClass()) && this.isEntityAlive() && !this.isTrading() && !this.isChild()) { if (this.buyingList == null) { this.populateBuyingList(); } if (hand == EnumHand.MAIN_HAND) { player.addStat(StatList.TALKED_TO_VILLAGER); } if (!this.world.isRemote && !this.buyingList.isEmpty()) { this.setCustomer(player); player.displayVillagerTradeGui(this); } else if (this.buyingList.isEmpty()) { return super.processInteract(player, hand); } return true; } else { return super.processInteract(player, hand); } } } public class ChangeVilMateAI { @SubscribeEvent public void entityVillagerAIOverride(LivingSpawnEvent event) { if (event.getEntity() != null){ if (event.getEntity() instanceof EntityVillager) { EntityVillager villager = (EntityVillager) event.getEntity(); villager.tasks.addTask(3, new VilsPerDoor(villager)); } else if (event.getEntity() instanceof IvVillager) { IvVillager villager = (IvVillager) event.getEntity(); villager.tasks.addTask(3, new IvVilsPerDoor(villager)); } } } }
-
Okay, so I've figured out everything above, however, my villagers don't work at all. They override regular villagers successfully and display the correct texture. That's it, they don't move or have any AI. They just gets hearts and endless stacks villages inside the same block. They don't die from lava, they don't even fall. public class OverrideVillagers { @SubscribeEvent public void entityJoinedWorldEventHandler(EntityJoinWorldEvent event) { if (event.getEntity().getClass() == EntityVillager.class && Config.overwriteOriginalVillagers) { doOverwriteVillager(event, (EntityVillager) event.getEntity()); } } private void doOverwriteVillager(EntityJoinWorldEvent event, EntityVillager entity) { if (entity.getProfession() >= 0 && entity.getProfession() <= 4) { entity.setDead(); EntityVillager entityVillager = new EntityVillager(event.getWorld()); entityVillager.onInitialSpawn(event.getWorld().getDifficultyForLocation(new BlockPos(entity)), (IEntityLivingData)null); entityVillager.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, 0.0F, 0.0F); event.getWorld().spawnEntity(entityVillager); event.getWorld().setEntityState(entityVillager, (byte)12); entityVillager.setProfession(entity.getProfession()); entityVillager.setGrowingAge(entity.getGrowingAge()); } } } public class IvVillager extends EntityVillager{ protected Village villageObj; public String name; public int Gender; protected boolean isWillingToMate; protected int wealth; private MerchantRecipeList buyingList; private String lastBuyingPlayer; private int careerId; private int careerLevel; private boolean isLookingForHome; private boolean areAdditionalTasksSet; private final InventoryBasic villagerInventory; Random r = new Random(); /** A multi-dimensional array mapping the various professions, careers and career levels that a Villager may offer */ protected String[] male_list = {"Bob", "Joseph", "Aaron", "Philp", "Adam", "Paul", "Donald", "Ryan", "Mark", "Brian", "Robert", "Willam", "Harold", "Anthony", "Julius", "Mathew", "Tyler", "Noah", "Patrick", "Caden", "Michael", "Jeffery", "James", "John", "Thomas", "Otto", "Bill", "Sheldon", "Leonard", "Howard", "Carter", "Theodore", "Herbert"}; protected String[] female_list = {"Karen", "Lessie", "Kayla", "Brianna", "Isabella", "Elizabeth", "Kira", "Jadzia", "Abigail", "Chloe", "Olivia", "Sophia", "Emily", "Charlotte", "Amelia", "Maria", "Daria", "Sarah", "Theodora", "Tia", "Jennifer", "Anglica", "Denna", "Tasha", "Catherine", "Lily", "Amy", "Penny", "Julina", "Audrey", "Avery"}; public IvVillager(World world, int professionId) { super(world, professionId); this.villagerInventory = new InventoryBasic("Items", false, ; this.setCanPickUpLoot(true); this.setProfession(professionId); } public InventoryBasic getVillagerInventory() { return this.villagerInventory; } private void setAdditionalAItasks() { if (!this.areAdditionalTasksSet) { this.areAdditionalTasksSet = true; if (this.isChild()) { this.tasks.addTask(8, new EntityAIPlay(this, 0.32D)); } else if (this.getProfession() == 0) { this.tasks.addTask(6, new EntityAIHarvestFarmland(this, 0.6D)); } } } @Override public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); compound.setInteger("Profession", this.getProfession()); compound.setString("ProfessionName", this.getProfessionForge().getRegistryName().toString()); compound.setInteger("Riches", this.wealth); compound.setInteger("Career", this.careerId); compound.setInteger("CareerLevel", this.careerLevel); compound.setBoolean("Willing", this.isWillingToMate); if (this.buyingList != null) { compound.setTag("Offers", this.buyingList.getRecipiesAsTags()); } NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.getVillagerInventory().getSizeInventory(); ++i) { ItemStack itemstack = this.villagerInventory.getStackInSlot(i); if (!itemstack.isEmpty()) { nbttaglist.appendTag(itemstack.writeToNBT(new NBTTagCompound())); } } compound.setTag("Inventory", nbttaglist); if (compound.getInteger("Gender") != 1 || compound.getInteger("Gender") != 2) { compound.setInteger("Gender", this.Gender); } if (this.getCustomNameTag() == null){ if (compound.getInteger("Gender") == 1){ this.setCustomNameTag(male_list[r.nextInt(male_list.length)]); } if (compound.getInteger("Gender") == 2){ this.setCustomNameTag(female_list[r.nextInt(female_list.length)]); } } } @Override public void readEntityFromNBT(NBTTagCompound compound){ super.writeEntityToNBT(compound); this.name = this.getCustomNameTag(); this.Gender = compound.getInteger("Gender"); this.setProfession(compound.getInteger("Profession")); if (compound.hasKey("ProfessionName")) { net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession p = net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(new net.minecraft.util.ResourceLocation(compound.getString("ProfessionName"))); if (p == null) p = net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(new net.minecraft.util.ResourceLocation("minecraft:farmer")); this.setProfession(p); } this.wealth = compound.getInteger("Riches"); this.careerId = compound.getInteger("Career"); this.careerLevel = compound.getInteger("CareerLevel"); this.isWillingToMate = compound.getBoolean("Willing"); if (compound.hasKey("Offers", 10)) { NBTTagCompound nbttagcompound = compound.getCompoundTag("Offers"); this.buyingList = new MerchantRecipeList(nbttagcompound); } NBTTagList nbttaglist = compound.getTagList("Inventory", 10); for (int i = 0; i < nbttaglist.tagCount(); ++i) { ItemStack itemstack = new ItemStack(nbttaglist.getCompoundTagAt(i)); if (!itemstack.isEmpty()) { this.villagerInventory.addItem(itemstack); } } this.setCanPickUpLoot(true); this.setAdditionalAItasks(); } private void populateBuyingList() { if (this.careerId != 0 && this.careerLevel != 0) { ++this.careerLevel; } else { this.careerId = this.getProfessionForge().getRandomCareer(this.rand) + 1; this.careerLevel = 1; } if (this.buyingList == null) { this.buyingList = new MerchantRecipeList(); } int i = this.careerId - 1; int j = this.careerLevel - 1; java.util.List<EntityVillager.ITradeList> trades = this.getProfessionForge().getCareer(i).getTrades(j); if (trades != null) { for (EntityVillager.ITradeList entityvillager$itradelist : trades) { entityvillager$itradelist.addMerchantRecipe(this, this.buyingList, this.rand); } } } @Override public boolean processInteract(EntityPlayer player, EnumHand hand){ BlockPos blockpos = new BlockPos(this); this.villageObj = this.world.getVillageCollection().getNearestVillage(blockpos, 32); ItemStack itemstack = player.getHeldItem(hand); if (itemstack.getItem() == IvItems.thieving_nose && !player.capabilities.isCreativeMode && !this.isChild()) { itemstack.damageItem(1, player); if (rand.nextInt(10) + 1 < 6){ } if (rand.nextInt(10) + 1 < 9 && rand.nextInt(10) + 1 > 5){ player.dropItem(new ItemStack(Items.EMERALD, r.nextInt(2) + 1), false); } if (rand.nextInt(10) + 1 < 10 && rand.nextInt(10) + 1 > { player.dropItem(new ItemStack(Items.EMERALD, r.nextInt(6) + 3), false); } if (this.villageObj != null) { this.villageObj.modifyPlayerReputation(player.getName(), -2); } return true; } else if (!this.holdingSpawnEggOfClass(itemstack, this.getClass()) && this.isEntityAlive() && !this.isTrading() && !this.isChild()) { if (this.buyingList == null) { this.populateBuyingList(); } if (hand == EnumHand.MAIN_HAND) { player.addStat(StatList.TALKED_TO_VILLAGER); } if (!this.world.isRemote && !this.buyingList.isEmpty()) { this.setCustomer(player); player.displayVillagerTradeGui(this); } else if (this.buyingList.isEmpty()) { return super.processInteract(player, hand); } return true; } else { return super.processInteract(player, hand); } } } public class CommonProxy { @EventHandler public void preInit(FMLPreInitializationEvent e) { ResourceLocation resourceLocation1 = new ResourceLocation("minecraft", "EntityVillager"); EntityRegistry.registerModEntity(resourceLocation1, IvVillager.class, "IvVillager", 0, Iv.instance, 32, 1, true); } @EventHandler public void init(FMLInitializationEvent e) { } @EventHandler public void postInit(FMLPostInitializationEvent e) { } }
-
Alright, thanks everyone, my village now properly generates.
-
Okay, so the code runs, but then gives me this crash. net.minecraft.util.ReportedException: Exception preparing structure feature at net.minecraft.world.WorldServer.initialize(WorldServer.java:934) ~[WorldServer.class:?] at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:88) ~[integratedServer.class:?] at net.minecraft.server.integrated.IntegratedServer.init(IntegratedServer.java:124) ~[integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:507) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_111] Caused by: java.lang.RuntimeException: StructureStart "orangeVillager61.ImprovedVillagers.generation.IvMapGenVillage$Start" missing ID Mapping, Modder see MapGenStructureIO at net.minecraft.world.gen.structure.StructureStart.writeStructureComponentsToNBT(StructureStart.java:74) ~[structureStart.class:?] at net.minecraft.world.gen.structure.MapGenStructure.setStructureStart(MapGenStructure.java:212) ~[MapGenStructure.class:?] at net.minecraft.world.gen.structure.MapGenStructure.recursiveGenerate(MapGenStructure.java:48) ~[MapGenStructure.class:?] at net.minecraft.world.gen.MapGenBase.generate(MapGenBase.java:31) ~[MapGenBase.class:?] at net.minecraft.world.gen.ChunkProviderOverworld.provideChunk(ChunkProviderOverworld.java:228) ~[ChunkProviderOverworld.class:?] at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:150) ~[ChunkProviderServer.class:?] at net.minecraft.world.World.getChunkFromChunkCoords(World.java:351) ~[World.class:?] at net.minecraft.world.World.getChunkFromBlockCoords(World.java:343) ~[World.class:?] at net.minecraft.world.World.getBlockState(World.java:977) ~[World.class:?] at net.minecraft.world.World.isAirBlock(World.java:268) ~[World.class:?] at net.minecraft.world.World.getGroundAboveSeaLevel(World.java:241) ~[World.class:?] at net.minecraft.world.WorldProvider.canCoordinateBeSpawn(WorldProvider.java:87) ~[WorldProvider.class:?] at net.minecraft.world.WorldServer.createSpawnPosition(WorldServer.java:993) ~[WorldServer.class:?] at net.minecraft.world.WorldServer.initialize(WorldServer.java:912) ~[WorldServer.class:?] ... 4 more
-
Okay, that fixed my bug, but I have another similar bug. java.lang.ClassCastException: orangeVillager61.ImprovedVillagers.generation.IvMapGenVillage cannot be cast to net.minecraft.world.gen.structure.MapGenVillage at net.minecraft.world.gen.ChunkProviderOverworld.<init>(ChunkProviderOverworld.java:68) ~[ChunkProviderOverworld.class:?] at net.minecraft.world.WorldType.getChunkGenerator(WorldType.java:178) ~[WorldType.class:?] at net.minecraft.world.WorldProvider.createChunkGenerator(WorldProvider.java:78) ~[WorldProvider.class:?] at net.minecraft.world.WorldServer.createChunkProvider(WorldServer.java:894) ~[WorldServer.class:?] at net.minecraft.world.WorldServer.<init>(WorldServer.java:119) ~[WorldServer.class:?] at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:86) ~[integratedServer.class:?] at net.minecraft.server.integrated.IntegratedServer.init(IntegratedServer.java:124) ~[integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:507) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_111] public class ChangeVillageGeneration { @SubscribeEvent public void changeVillageGen (InitMapGenEvent event) { if (event.getType() != null && event.getType() == EventType.VILLAGE){ IvMapGenVillage newGen = (IvMapGenVillage) new IvMapGenVillage(); System.out.println("Genning 2"); event.setNewGen(newGen); - Crashes here I think. } } }
-
I'm getting this crash using the overworld (on a village spawn seed): java.lang.ClassCastException: net.minecraft.world.gen.structure.MapGenVillage cannot be cast to orangeVillager61.ImprovedVillagers.generation.IvMapGenVillage at orangeVillager61.ImprovedVillagers.ChangeVillageGeneration.changeVillageGen(ChangeVillageGeneration.java:14) ~[ChangeVillageGeneration.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_8_ChangeVillageGeneration_changeVillageGen_InitMapGenEvent.invoke(.dynamic) ~[?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) [EventBus.class:?] at net.minecraftforge.event.terraingen.TerrainGen.getModdedMapGen(TerrainGen.java:47) [TerrainGen.class:?]
-
Firstly, I see no evidence that my code was running, so I put a series of System.out.printlns throughout my code and then used a superflat seed and generated a village. I got no printlns. The code that doesn't show any printlns and is the event_bus. public class ChangeVillageGeneration { @SubscribeEvent public void changeVillageGen (InitMapGenEvent event) { if (event.getType() != null && event.getType() == EventType.VILLAGE){ IvMapGenVillage newGen = (IvMapGenVillage) event.getNewGen(); System.out.println("Genning 2"); event.setNewGen(newGen); } } }