Jump to content

OrangeVillager61

Members
  • Posts

    339
  • Joined

  • Last visited

Everything posted by OrangeVillager61

  1. @Override public Render createRenderFor(RenderManager manager) { return IvVillagerRender(manager); } IvVillagerRender isn't recognized or defined. I'm getting an error with it.
  2. What do you mean by "a render object"?
  3. I overrode the vanilla villager with my custom modded villager and I am trying to change the texture, however, I can't seem to find how to do so. I am trying to implement RenderManager but I can't how to do so. IvVillager render class. @SideOnly(Side.CLIENT) public class IvVillagerRender extends RenderLiving<IvVillager> { private static final ResourceLocation VILLAGER_TEXTURES = new ResourceLocation("iv/textures/entity/villager/villager.png"); private static final ResourceLocation FARMER_VILLAGER_TEXTURES = new ResourceLocation("iv/textures/entity/villager/farmer.png"); private static final ResourceLocation LIBRARIAN_VILLAGER_TEXTURES = new ResourceLocation("iv/textures/entity/villager/librarian.png"); private static final ResourceLocation PRIEST_VILLAGER_TEXTURES = new ResourceLocation("iv/textures/entity/villager/priest.png"); private static final ResourceLocation SMITH_VILLAGER_TEXTURES = new ResourceLocation("iv/textures/entity/villager/smith.png"); private static final ResourceLocation BUTCHER_VILLAGER_TEXTURES = new ResourceLocation("iv/textures/entity/villager/butcher.png"); public IvVillagerRender(RenderManager renderManager) { super(renderManager, new ModelVillager(0.0F), 0.5F); this.addLayer(new LayerCustomHead(this.getMainModel().villagerHead)); } public ModelVillager getMainModel() { return (ModelVillager)super.getMainModel(); } /** * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture. */ protected ResourceLocation getEntityTexture(IvVillager entity) { return entity.getProfessionForge().getSkin(); } /** * Allows the render to do state modifications necessary before the model is rendered. */ protected void preRenderCallback(EntityVillager entitylivingbaseIn, float partialTickTime) { float f = 0.9375F; if (entitylivingbaseIn.getGrowingAge() < 0) { f = (float)((double)f * 0.5D); this.shadowSize = 0.25F; } else { this.shadowSize = 0.5F; } GlStateManager.scale(f, f, f); } } Client Proxy: public class ClientProxy extends CommonProxy{ @Override public void preInit(FMLPreInitializationEvent e) { super.preInit(e); BlockRender.preInit(); RenderingRegistry.registerEntityRenderingHandler(IvVillager.class, new IvVillagerRender()); //I know error is here, but I can't find how to implement RenderManager } @Override public void init(FMLInitializationEvent e) { super.init(e); ItemRender.registerItemRenderer(); BlockRender.registerBlockRenderer(); } @Override public void postInit(FMLPostInitializationEvent e) { super.postInit(e); } } Comment below if you need more information.
  4. I did not put any breakpoints outside of shouldExecute(), I checked the breakpoint tab to confirm this. I did a copy stack and got the error list, Thread [main] (Suspended (exception NullPointerException)) URLClassPath.check(URL) line: not available URLClassPath$Loader.findResource(String, boolean) line: not available URLClassPath.findResource(String, boolean) line: not available URLClassLoader$2.run() line: not available URLClassLoader$2.run() line: not available AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method] LaunchClassLoader(URLClassLoader).findResource(String) line: not available LaunchClassLoader(ClassLoader).getResource(String) line: not available LaunchClassLoader(URLClassLoader).getResourceAsStream(String) line: not available Class<T>.getResourceAsStream(String) line: not available ClassPatchManager.setup(Side) line: 173 FMLSanityChecker.injectData(Map<String,Object>) line: 188 CoreModManager$FMLPluginWrapper.injectIntoClassLoader(LaunchClassLoader) line: 165 Launch.launch(String[]) line: 115 Launch.main(String[]) line: 28 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available Method.invoke(Object, Object...) line: not available GradleStart(GradleStartCommon).launch(String[]) line: 97 GradleStart.main(String[]) line: 26
  5. I get said that nullpoinerexception when starting up MC and at "[14:16:24] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper" I get that error, I press resume and I get that same error and it highlights arg0 and java.net.url = random numbers that go up (76, then 92, etc) everytime I press resume. I'll try to get a screen shot.
  6. I tried to use the debugger but I get "URLClassPath.check(URL)line: not available" error and then the debugger tries to go through all of the null pointer exceptions with that.
  7. Okay, I've made the necessary changes but the villagers don't seem to run away from me when testing after murdering enough villagers next to a bunch of "houses". I made a println after the worldisremote check but it doesn't println anything. public class VillagerAvoidEvilPlayer<T extends Entity> extends EntityAIBase { private final Predicate<Entity> canBeSeenSelector; /** The entity we are attached to */ protected EntityCreature theEntity; private final double farSpeed; private final double nearSpeed; protected EntityPlayer closestLivingEntity; protected Village villageObj; private final float avoidDistance; /** The PathEntity of our entity */ private Path entityPathEntity; /** The PathNavigate of our entity */ private final PathNavigate entityPathNavigate; /** Class of entity this behavior seeks to avoid */ private final Class<EntityPlayer> classToAvoid; private final Predicate <? super T > avoidTargetSelector; public VillagerAvoidEvilPlayer(EntityCreature theEntityIn, float avoidDistanceIn, double farSpeedIn, double nearSpeedIn, Village villageobj) { this(theEntityIn, EntityPlayer.class, Predicates.<T>alwaysTrue(), avoidDistanceIn, farSpeedIn, nearSpeedIn, villageobj); } public VillagerAvoidEvilPlayer(EntityCreature theEntityIn, Class<EntityPlayer> classToAvoidIn, Predicate <? super T > avoidTargetSelectorIn, float avoidDistanceIn, double farSpeedIn, double nearSpeedIn, Village villageobj) { this.canBeSeenSelector = new Predicate<Entity>() { public boolean apply(@Nullable Entity p_apply_1_) { return p_apply_1_.isEntityAlive() && VillagerAvoidEvilPlayer.this.theEntity.getEntitySenses().canSee(p_apply_1_) && !VillagerAvoidEvilPlayer.this.theEntity.isOnSameTeam(p_apply_1_); } }; this.theEntity = theEntityIn; this.classToAvoid = classToAvoidIn; this.avoidTargetSelector = avoidTargetSelectorIn; this.avoidDistance = avoidDistanceIn; this.farSpeed = farSpeedIn; this.villageObj = villageobj; this.nearSpeed = nearSpeedIn; this.entityPathNavigate = theEntityIn.getNavigator(); this.setMutexBits(1); } /** * Returns whether the EntityAIBase should begin execution. */ public boolean shouldExecute() { List<EntityPlayer> list = this.theEntity.world.<EntityPlayer>getEntitiesWithinAABB(this.classToAvoid, this.theEntity.getEntityBoundingBox().expand((double)this.avoidDistance, 3.0D, (double)this.avoidDistance), Predicates.and(new Predicate[] {EntitySelectors.CAN_AI_TARGET, this.canBeSeenSelector, this.avoidTargetSelector})); if (list.isEmpty()) { return false; } else { if (this.theEntity.world.isRemote == false){ System.out.println(this.villageObj.getPlayerReputation(this.classToAvoid.getName())); //This does not print. if (this.villageObj.getPlayerReputation(this.classToAvoid.getName()) < -8){ this.closestLivingEntity = list.get(0); Vec3d vec3d = RandomPositionGenerator.findRandomTargetBlockAwayFrom(this.theEntity, 16, 7, new Vec3d(this.closestLivingEntity.posX, this.closestLivingEntity.posY, this.closestLivingEntity.posZ)); if (vec3d == null) { return false; } else if (this.closestLivingEntity.getDistanceSq(vec3d.xCoord, vec3d.yCoord, vec3d.zCoord) < this.closestLivingEntity.getDistanceSqToEntity(this.theEntity)) { return false; } else { this.entityPathEntity = this.entityPathNavigate.getPathToXYZ(vec3d.xCoord, vec3d.yCoord, vec3d.zCoord); return this.entityPathEntity != null; } } else{ return false; } } else { return false; } } } /** * Returns whether an in-progress EntityAIBase should continue executing */ public boolean continueExecuting() { return !this.entityPathNavigate.noPath(); } /** * Execute a one shot task or start executing a continuous task */ public void startExecuting() { this.entityPathNavigate.setPath(this.entityPathEntity, this.farSpeed); } /** * Resets the task */ public void resetTask() { this.closestLivingEntity = null; } /** * Updates the task */ public void updateTask() { if (this.theEntity.getDistanceSqToEntity(this.closestLivingEntity) < 49.0D) { this.theEntity.getNavigator().setSpeed(this.nearSpeed); } else { this.theEntity.getNavigator().setSpeed(this.farSpeed); } } }
  8. I am working on a way to get villagers to run away from players that have a villager rep lower than negative 5. Currently, I am using a variation of entityAIAvoidEntity class, I've almost everything done except on how to recognize said hostile player. I get an error if I use <T>getEntitiesWithinAABB as the original code has and I can't find an alternative. Secondly, how to get a players name to compare with the villageObj's rep? import com.google.common.base.Predicate; import com.google.common.base.Predicates; import java.util.List; import javax.annotation.Nullable; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityCreature; import net.minecraft.entity.ai.EntityAIBase; import net.minecraft.entity.ai.RandomPositionGenerator; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.pathfinding.Path; import net.minecraft.pathfinding.PathNavigate; import net.minecraft.util.EntitySelectors; import net.minecraft.util.math.Vec3d; import net.minecraft.village.Village; public class VillagerAvoidEvilPlayer<T extends Entity> extends EntityAIBase { private final Predicate<Entity> canBeSeenSelector; /** The entity we are attached to */ protected EntityCreature theEntity; private final double farSpeed; private final double nearSpeed; protected T closestLivingEntity; protected Village villageObj; private final float avoidDistance; /** The PathEntity of our entity */ private Path entityPathEntity; /** The PathNavigate of our entity */ private final PathNavigate entityPathNavigate; /** Class of entity this behavior seeks to avoid */ private final Class<EntityPlayer> classToAvoid; private final Predicate <? super T > avoidTargetSelector; public VillagerAvoidEvilPlayer(EntityCreature theEntityIn, float avoidDistanceIn, double farSpeedIn, double nearSpeedIn, Village villageobj) { this(theEntityIn, EntityPlayer.class, Predicates.<T>alwaysTrue(), avoidDistanceIn, farSpeedIn, nearSpeedIn, villageobj); } public VillagerAvoidEvilPlayer(EntityCreature theEntityIn, Class<EntityPlayer> classToAvoidIn, Predicate <? super T > avoidTargetSelectorIn, float avoidDistanceIn, double farSpeedIn, double nearSpeedIn, Village villageobj) { this.canBeSeenSelector = new Predicate<Entity>() { public boolean apply(@Nullable Entity p_apply_1_) { return p_apply_1_.isEntityAlive() && VillagerAvoidEvilPlayer.this.theEntity.getEntitySenses().canSee(p_apply_1_) && !VillagerAvoidEvilPlayer.this.theEntity.isOnSameTeam(p_apply_1_); } }; this.theEntity = theEntityIn; this.classToAvoid = classToAvoidIn; this.avoidTargetSelector = avoidTargetSelectorIn; this.avoidDistance = avoidDistanceIn; this.farSpeed = farSpeedIn; this.villageObj = villageobj; this.nearSpeed = nearSpeedIn; this.entityPathNavigate = theEntityIn.getNavigator(); this.setMutexBits(1); } /** * Returns whether the EntityAIBase should begin execution. */ public boolean shouldExecute() { List<T> list = this.theEntity.world.<T>getEntitiesWithinAABB(this.classToAvoid, this.theEntity.getEntityBoundingBox().expand((double)this.avoidDistance, 3.0D, (double)this.avoidDistance), Predicates.and(new Predicate[] {EntitySelectors.CAN_AI_TARGET, this.canBeSeenSelector, this.avoidTargetSelector})); //Issue here if (this.villageObj.getPlayerReputation(this.classToAvoid.) < -5){ //Issue here if (list.isEmpty()) { return false; } else { this.closestLivingEntity = list.get(0); Vec3d vec3d = RandomPositionGenerator.findRandomTargetBlockAwayFrom(this.theEntity, 16, 7, new Vec3d(this.closestLivingEntity.posX, this.closestLivingEntity.posY, this.closestLivingEntity.posZ)); if (vec3d == null) { return false; } else if (this.closestLivingEntity.getDistanceSq(vec3d.xCoord, vec3d.yCoord, vec3d.zCoord) < this.closestLivingEntity.getDistanceSqToEntity(this.theEntity)) { return false; } else { this.entityPathEntity = this.entityPathNavigate.getPathToXYZ(vec3d.xCoord, vec3d.yCoord, vec3d.zCoord); return this.entityPathEntity != null; } } } else { return false; } } /** * Returns whether an in-progress EntityAIBase should continue executing */ public boolean continueExecuting() { return !this.entityPathNavigate.noPath(); } /** * Execute a one shot task or start executing a continuous task */ public void startExecuting() { this.entityPathNavigate.setPath(this.entityPathEntity, this.farSpeed); } /** * Resets the task */ public void resetTask() { this.closestLivingEntity = null; } /** * Updates the task */ public void updateTask() { if (this.theEntity.getDistanceSqToEntity(this.closestLivingEntity) < 49.0D) { this.theEntity.getNavigator().setSpeed(this.nearSpeed); } else { this.theEntity.getNavigator().setSpeed(this.farSpeed); } } }
  9. In some versions of minecraft, mods were compatible with other versions and could set accepted versions to that(like 1.9.4 & 1.10.x) so is this the case for 1.11 and 1.11.2?
  10. Thanks for the help, separating the field and the custom name tag fixed it, the issue must have been in the writing and reading the nbt, thanks!
  11. So if I use setCustomNameTag to show the name from the variable, I would want a field then?
  12. Which would you recommend? The original reason why I used a DataParameter is because it took a reload for those values to applied with the first method I did (mainly the villagers didn't get named until said reload).
  13. Good catch, that fixes the profession issue (no clue why I put it there right before my hiatus). I had issues with proxies in the past with stuff being in the wrong proxy, so I put that there in bugged situations. Yeah, probably, as stated in the first post, I did some weird stuff right before I left. I should switch from printlns to breakpoints, I am not very good with the latter but it does seem to work better according to most debuggers.
  14. Looking at the code, I think the issue may be in the write/read nbt, I'm going to use printlns to confirm this.
  15. After further testing, I've discovered that professions (they are reset to farmers) are also deleted when I use this code. Also, when the game is reloaded, the names for each villager is set to "None" then to one of the random names. But this is not seen, instead, the game permanently shows "None".
  16. After a long hiatus from modding, I am debuging my code and update my mod. However, an issue I had right before my hiatus was that my data parameters were not working correctly and always showed the value from the register. My original goal was to give each villager a name and gender when spawned, however, the code according to printlns does assign names but the villagers have "None" over them. Below, there is a time when the code assigns names and printlns "Something went wrong with gender, please report." but this never appears in the printlns. Custom Mob(Some unrelated stuff was removed and changes that fix some of the original issues are in it): public class IvVillager extends EntityVillager{ protected Village villageObj; public String name; public int gender; protected boolean isWillingToMate; protected int wealth; protected MerchantRecipeList buyingList; protected static final DataParameter<String> Name = EntityDataManager.<String>createKey(IvVillager.class, DataSerializers.STRING); protected static final DataParameter<Integer> Gender = EntityDataManager.<Integer>createKey(IvVillager.class, DataSerializers.VARINT); private int careerId; private int careerLevel; private boolean isLookingForHome; private boolean areAdditionalTasksSet; protected 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) { super(world); this.villagerInventory = new InventoryBasic("Items", false, 20); } public IvVillager(World world, int professionId) { super(world, professionId); this.setProfession(professionId); this.villagerInventory = new InventoryBasic("Items", false, 20); } public InventoryBasic getVillagerInventory() { return this.villagerInventory; } @Override protected void entityInit() { super.entityInit(); this.getDataManager().register(Gender, Integer.valueOf(0)); this.getDataManager().register(Name, String.valueOf("None")); } public int getGender() { return ((Integer)this.getDataManager().get(Gender)).intValue(); } public void setGender(int value) { this.getDataManager().set(Gender, Integer.valueOf(value)); } public String getName() { return ((String)this.getDataManager().get(Name)); } public void setName(String value) { this.getDataManager().set(Name, String.valueOf(value)); } @Override public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); if (world.isRemote == false){ 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 (world.isRemote == false){ if (this.getGender() != 1 || this.getGender() != 2){ this.gender = r.nextInt(2) + 1; } compound.setInteger("Gender", this.gender); if (this.getName() == null || this.getName() == "None"){ if (this.gender == 1){ this.name = male_list[r.nextInt(male_list.length)]; System.out.println("Male Name"); } else if (this.gender == 2){ this.name = female_list[r.nextInt(male_list.length)]; System.out.println("Female Name"); } else if (this.gender != 1|| this.gender != 2){ this.name = "None"; System.out.println("Something went wrong with gender, please report."); System.out.println("No Name"); } compound.setString("Name", this.name); this.setGender(this.gender); this.setName(this.name); System.out.println(this.getName()); } } } @Override public void readEntityFromNBT(NBTTagCompound compound){ super.readEntityFromNBT(compound); if (world.isRemote == false){ this.gender = compound.getInteger("Gender"); this.name = compound.getString("Name"); this.getGender(); this.getName(); this.setCustomNameTag(this.getName()); } 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(); } } Common Proxy (Some unrelated stuff was removed): public class CommonProxy { @EventHandler public void preInit(FMLPreInitializationEvent e) { ResourceLocation resourceLocation1 = new ResourceLocation("iv", "villager"); EntityRegistry.registerModEntity(resourceLocation1, IvVillager.class, "IvVillager", 0, Iv.instance, 32, 1, true); } @EventHandler public void init(FMLInitializationEvent e) { } @EventHandler public void postInit(FMLPostInitializationEvent e) { } } Please comment if you need more information, it has been a while so I am still figuring out some of the buginess,
  17. Okay, so I fixed much of my issues, but the game only displays "None" instead of a name. The game does correctly set names in the WriteNBT but those names don't seem to persist in reloads or actually show. I determined this using printlns. public class IvVillager extends EntityVillager{ protected Village villageObj; public String name; public int gender; protected boolean isWillingToMate; protected int wealth; protected MerchantRecipeList buyingList; protected static final DataParameter<String> Name = EntityDataManager.<String>createKey(IvVillager.class, DataSerializers.STRING); protected static final DataParameter<Integer> Gender = EntityDataManager.<Integer>createKey(IvVillager.class, DataSerializers.VARINT); private int careerId; private int careerLevel; private boolean isLookingForHome; private boolean areAdditionalTasksSet; protected 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) { super(world); this.villagerInventory = new InventoryBasic("Items", false, 20); } public IvVillager(World world, int professionId) { super(world, professionId); this.setProfession(professionId); this.villagerInventory = new InventoryBasic("Items", false, 20); } public InventoryBasic getVillagerInventory() { return this.villagerInventory; } @Override protected void entityInit() { super.entityInit(); this.getDataManager().register(Gender, Integer.valueOf(0)); this.getDataManager().register(Name, String.valueOf("None")); } @Override protected void initEntityAI() { this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D)); this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityEvoker.class, 12.0F, 0.8D, 0.8D)); this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVindicator.class, 8.0F, 0.8D, 0.8D)); this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVex.class, 8.0F, 0.6D, 0.6D)); this.tasks.addTask(1, new EntityAITradePlayer(this)); this.tasks.addTask(2, new EntityAILookAtTradePlayer(this)); this.tasks.addTask(2, new EntityAIMoveIndoors(this)); this.tasks.addTask(3, new EntityAIRestrictOpenDoor(this)); this.tasks.addTask(4, new EntityAITempt(this, 1.25D, Items.EMERALD, false)); this.tasks.addTask(4, new EntityAIOpenDoor(this, true)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 0.6D)); this.tasks.addTask(6, new VilsPerDoor(this)); this.tasks.addTask(7, new EntityAIFollowGolem(this)); this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F)); this.tasks.addTask(9, new EntityAIVillagerInteract(this)); this.tasks.addTask(9, new EntityAIWanderAvoidWater(this, 0.6D)); this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F)); } public int getGender() { return ((Integer)this.getDataManager().get(Gender)).intValue(); } public void setGender(int value) { this.getDataManager().set(Gender, Integer.valueOf(value)); } public String getName() { return ((String)this.getDataManager().get(Name)); } public void setName(String value) { this.getDataManager().set(Name, String.valueOf(value)); } 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 (world.isRemote == false){ if (this.getGender() != 1 || this.getGender() != 2){ this.gender = r.nextInt(2) + 1; } compound.setInteger("Gender", this.gender); if (this.getName() == null || this.getName() == "None"){ if (this.gender == 1){ this.name = male_list[r.nextInt(male_list.length)]; System.out.println("Male Name"); } else if (this.gender == 2){ this.name = female_list[r.nextInt(male_list.length)]; System.out.println("Female Name"); } else if (this.gender != 1|| this.gender != 2){ this.name = "None"; System.out.println("Something went wrong with gender, please report."); System.out.println("No Name"); } compound.setString("Name", this.name); this.setGender(this.gender); this.setName(this.name); } } } @Override public void readEntityFromNBT(NBTTagCompound compound){ super.writeEntityToNBT(compound); if (world.isRemote == false){ this.gender = compound.getInteger("Gender"); this.name = compound.getString("Name"); this.getGender(); this.getName(); this.setCustomNameTag(this.getName()); } 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){ if (world.isRemote == false){ BlockPos blockpos = new BlockPos(this); this.villageObj = this.world.getVillageCollection().getNearestVillage(blockpos, 32); } ItemStack itemstack = player.getHeldItem(hand); if (itemstack.getItem() == IvItems.thieving_nose && !this.isChild()){ itemstack.damageItem(1, player); this.setHealth(this.getHealth() - 2); this.playHurtSound(getLastDamageSource()); if (rand.nextInt(10) + 1 < 6){ } if (rand.nextInt(10) + 1 < 9 && rand.nextInt(10) + 1 > 5){ this.entityDropItem(new ItemStack(Items.EMERALD, r.nextInt(2) + 1), 0); } if (rand.nextInt(10) + 1 < 10 && rand.nextInt(10) + 1 > 8){ this.entityDropItem(new ItemStack(Items.EMERALD, r.nextInt(2) + 1), 0); } if (world.isRemote == 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); } } }
  18. I would normally use a capability but is it possible to use a capability and have the game show the name without reloading?
  19. Okay, sorry. I mean that when I spawn a villager with the code above, the villagers gets removed and has this a NullPointerException:
  20. Alright, but this causes the villager to be removed... public class IvVillager extends EntityVillager{ public IvVillager(World world) { super(world); this.villagerInventory = new InventoryBasic("Items", false, 20); } public IvVillager(World world, int professionId) { super(world, professionId); this.setProfession(professionId); this.villagerInventory = new InventoryBasic("Items", false, 20); } public InventoryBasic getVillagerInventory() { return this.villagerInventory; } @Override protected void entityInit() { super.entityInit(); this.getDataManager().register(Gender, Integer.valueOf(0)); this.setGender(); this.getDataManager().register(Name, String.valueOf("None")); this.setName(); } @Override protected void initEntityAI() { this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D)); this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityEvoker.class, 12.0F, 0.8D, 0.8D)); this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVindicator.class, 8.0F, 0.8D, 0.8D)); this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVex.class, 8.0F, 0.6D, 0.6D)); this.tasks.addTask(1, new EntityAITradePlayer(this)); this.tasks.addTask(2, new EntityAILookAtTradePlayer(this)); this.tasks.addTask(2, new EntityAIMoveIndoors(this)); this.tasks.addTask(3, new EntityAIRestrictOpenDoor(this)); this.tasks.addTask(4, new EntityAITempt(this, 1.25D, Items.EMERALD, false)); this.tasks.addTask(4, new EntityAIOpenDoor(this, true)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 0.6D)); this.tasks.addTask(6, new VilsPerDoor(this)); this.tasks.addTask(7, new EntityAIFollowGolem(this)); this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F)); this.tasks.addTask(9, new EntityAIVillagerInteract(this)); this.tasks.addTask(9, new EntityAIWanderAvoidWater(this, 0.6D)); this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F)); } public int getGender() { return ((Integer)this.getDataManager().get(Gender)).intValue(); } public void setGender() { IVillagerStorage villagerN = this.getCapability(VillagerProvider.VIL_CAP, null); if (this.gender == 0 || this.gender == 1){ villagerN.setGender(this.gender); } this.getDataManager().set(Gender, Integer.valueOf(this.gender)); } public String getName() { return ((String)this.getDataManager().get(Name)); } public void setName() { IVillagerStorage villagerN = this.getCapability(VillagerProvider.VIL_CAP, null); if (this.name != null){ villagerN.setName(this.name); } this.getDataManager().set(Name, String.valueOf(this.name)); } 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 (world.isRemote == false){ this.setGender(); this.setName(); } } @Override public void readEntityFromNBT(NBTTagCompound compound){ super.writeEntityToNBT(compound); if (world.isRemote == false){ this.getGender(); this.getName(); this.setCustomNameTag(this.getName()); } 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){ if (world.isRemote == false){ BlockPos blockpos = new BlockPos(this); this.villageObj = this.world.getVillageCollection().getNearestVillage(blockpos, 32); } ItemStack itemstack = player.getHeldItem(hand); if (itemstack.getItem() == IvItems.thieving_nose && !this.isChild()){ itemstack.damageItem(1, player); this.setHealth(this.getHealth() - 2); this.playHurtSound(getLastDamageSource()); if (rand.nextInt(10) + 1 < 6){ } if (rand.nextInt(10) + 1 < 9 && rand.nextInt(10) + 1 > 5){ this.entityDropItem(new ItemStack(Items.EMERALD, r.nextInt(2) + 1), 0); } if (rand.nextInt(10) + 1 < 10 && rand.nextInt(10) + 1 > 8){ this.entityDropItem(new ItemStack(Items.EMERALD, r.nextInt(2) + 1), 0); } if (world.isRemote == 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); } } }
  21. I mean I leave all of the strings as strings and not DataParamater<String>.
  22. So, in the IvVillager file, I use DataParameter , but in the capabilities I use the same code as before?
  23. 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) { super(world); this.villagerInventory = new InventoryBasic("Items", false, 8); } public IvVillager(World world, int professionId) { super(world, professionId); this.setProfession(professionId); this.villagerInventory = new InventoryBasic("Items", false, 8); } public InventoryBasic getVillagerInventory() { return this.villagerInventory; } @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 (world.isRemote == false){ IVillagerStorage villagerN = this.getCapability(VillagerProvider.VIL_CAP, null); villagerN.setGender(this.Gender); villagerN.setName(this.name); } } @Override public void readEntityFromNBT(NBTTagCompound compound){ super.writeEntityToNBT(compound); if (world.isRemote == false){ IVillagerStorage villagerN = this.getCapability(VillagerProvider.VIL_CAP, null); this.name = villagerN.getName(); this.Gender = villagerN.getGender(); this.setCustomNameTag(this.name); } 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); } } } } }
  24. So, how to not need a reload for the villagers to gain names?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.