Jump to content

NovaViper

Forge Modder
  • Posts

    1061
  • Joined

  • Last visited

Posts posted by NovaViper

  1. I'm not sure why, but whenver I run the command ./gradlew setDecompWorkspace, I get this error:
    ERROR: JAVA_HOME is set to an invalid directory: C:\Program 
    Files\Java\jdk1.8.0_191\bin
    
    Please set the JAVA_HOME variable in your environment to match the
    location of your Java installation.

    I've added the JAVA_HOME variable under my System Environment Variables as this: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_191\, my system path contains this: C:\Program Files\Java\jdk1.8.0_191\bin;C:\Program Files\Java\jdk1.8.0_191

  2. Hey, I'm trying to figure out how to add a recipe for an item that has subitems (throw stick and throw bone). Each item have its own state, dry and drooled on. The issue I'm running into is that whenever I place either item into the crafting table, I end up getting a different one instead (i.e. if I placed the drool bone, I end up getting a dry stick instead of a dry bone). The damage ids are 0 (throw bone dry), 1 (throw bone wet), 2 (throw stick wet), 3 (throw stick wet). Just to warn, I did not make the code myself, I'm merely contributing to the current project.

     

    The issue: https://github.com/percivalalb/DoggyTalents/issues/114

    The recipes:

    Item Registery: https://github.com/percivalalb/DoggyTalents/blob/master/src-mc-1.12.2/doggytalents/ModItems.java

  3. Good news! The primary developer came on earlier today and spotted the issue. It turns out that out the updateBoundingBox() method was at fault. It had the code that was really meant for the setDogSize() method, and because that was constantly being executed, it caused the bounding box of the dog to change, which caused the dog to move unintentionally. He has prompted fixed the bug and everything is working like it was before. More detail on the change is here

  4. I'm not sure if this is a good place to ask this, but here goes.

     

    So for about a year now, there has been this big bug that me and another developer haven't been able (nor had to time) to tackle. I've done some digging around the code to at least figure out when the bug started occurring. The latest version of the mod (Doggy Talents) is 1.14.2.321 for 1.12.2; the version that didn't have the bug was 1.14.1.240 for 1.12.2. Every succeeding version (all the way up until the latest) since 1.14.1.240 has had the bug. I made a Git Compare in order to show the various changes that occured since that release all the way up to now. If anyone can give any sort of input as to why this happening, it would be highly appreciated.

  5. Hi, I'm trying to figure out how I can check for a player holding a certain item either in the main hand or in the offhand; and if that player has that item, the method will return a number to execute a certain task for the entity im making this for. So far I have only checked for the active hand, but not the offhand.

     

    My original code is this:

        public int masterOrder() {
        	int order = 0;
        	
            EntityPlayer player = (EntityPlayer)this.getOwner();
        	
            if(player != null) {
                float distanceAway = player.getDistance(this);
                ItemStack itemstack = player.inventory.getCurrentItem();
                
                
                if(itemstack != null && (itemstack.getItem() instanceof ItemTool) && distanceAway <= 20F)
                    order = 1;
    
                if(itemstack != null && ((itemstack.getItem() instanceof ItemSword) || (itemstack.getItem() instanceof ItemBow)))
                    order = 2;
    
                if(itemstack != null && itemstack.getItem() == Items.WHEAT) //Round up Talent
                    order = 3;
                
                if(itemstack != null && itemstack.getItem() == Items.BONE) //Roar Talent
                	order = 4;
            }
    
            return order;
        }

     

  6. 16 minutes ago, jabelar said:

    Well, Minecraft is just Java so all the file I/O libraries are available. So you could just come up with your own file format. But you could also hook into some of the built-in formats to help you. For example, if you have the data in NBT already then there are already methods for writing and reading NBT.

     

    But do you really need to store these in a separate file? Because you can also put all this stuff into a world save data instance and have that saved together with the regular game saves. Thanks to diesieben07 for this tip.

     

    There is are built in classes for saving data: WorldSavedData. How you do it depends if you want to store it per-dimension (different data for e.g. nether and overworld, these are two World instances in the code) or per save-file (same data for all dimensions).  For the former use world.perWorldStorage, otherwise use world.mapStorage.

    Warning: Be sure to always call markDirty() on your data when you change a value, otherwise Minecraft will not save it.
     

    You can see diesieben07's simple example here: WorldSaveData example cod

    I feel the best way to store the data per-dimension basis.

  7. I'm trying to figure out how to get a player's Doggy Talents dogs and have all of their information saved on a separate file on the machine; and finally, when the player use the whistle item to call their dogs, it should (basically) recreate the dog using the data that was saved previously and have the 'new' dog spawn around the either the dog's owner or whoever used the whistle. However, there is some issues i need addressed, which are the following below:

    • What would be the best and most reasonable way of doing this
    • How can I actually save what is inside the dog's inventory, as the dogs do possess the ability to carry things (if they have the talent of course), in the same manner as the vanilla Donkey/Horse does.
    • How often this should save, as to avoid data lost in case a player accidentally calls the dog before the data was saved or if the dog despawns
    • How should this method deal with non-owner players (those whom do not own the dog, but the owner has allowed the dog to be manipulated by others.

    I did in a previous attempt make a way to call the dogs, but it did not account for despawning due to the chunk where the dog is located at being despawned. Here is the repo in 1.12.2: https://github.com/ProPercivalalb/DoggyTalents/tree/master/src-mc-universal

  8. The title itself sounds a bit confusion but here's a more explained version of it. Basically, I added in code that would give the dogs in the DoggyTalents mod genders. I have all of that working however, I want to have it togglable, in case some people do not like having genders in the game, so I added a configuration to it aswell. I have the configurations and checking system working.. but when I switch off the setting, the dogs that have a gender do not "lose" their gender, they still maintain it, as well as if I go and turn the switch on, the dogs that didn't have a gender at all does not get a gender at all. So far, what I have done to get the gender randomization system going was a simple if statement that would check to see if configuration for allowing genders was set to true, then check if datatracker had any gender names in. If it was empty (it's empty when the entity first spawns in), it will randomly pick between male and female. It looks like this:

    	private void randomizeGender() {
    		if(Constants.DOG_GENDER == true) {
            	if (this.getGender() == "") {
            		if (rand.nextInt(2) == 0) {
            			this.setGender("male");
            		}
            		else {
            			this.setGender("female");
            		}
            	}
            }else{
            	this.setGender("");
            }
    	}

     

    The entirety of the class right now looks like this

  9. I added the enablePersistence() in the entityInt() since obtaining the dog is acutally done when you feed a tamed wolf dog treats, it automatically spawns a tamed dog with data from the wolf.

     

    I do have one other question relating to this actually, but it relates to another piece of code I'm adding in (not relating to the topic). I'm going to create another topic about it to avoid confusion

  10. 28 minutes ago, jabelar said:

    Did you try making the entities persistent with the setPersistent() method when they are tamed?

     

    If you look at EntityLiving there are some related fields/methods:

    - canDespawn() which defaults to true

    - despawnEntity() which looks at a couple things including distance, the canDespawn() and also

    - isPersistenceRequired which can be set with the enablePersistence() method, and this also is returned for the isNoDespawnRequired() method.

     

    If you look at the despawnEntity() method and trace the logic, you'll see that simply setting the persistence with enablePersistence() method will prevent despawning.

     

    That should help a fair bit because entities despawn even when chunks are loaded without persistence.

     

    Now I don't think persistence really helps if the chunk is actually unloaded. But it might so maybe Draco18s or diesieben07 know more details about that. You could force the entities to stay loaded by handling the chunk unload event and directly manipulating the world unloadedEntitiesList, but I think that would be a problem to have entities loaded without the chunk. But again others might know better.

     

    I would start by ensuring your entities are persistent. If there is still an issue, then what I would do is create a capability for the player that contains a List of the EntityDogs that have been tamed. I think you would actually just keep some information about the dogs and when you want to whistle them you would find the ones in the world and bring them, and then all the ones that are missing you'd have to re-construct. But I'm guessing at this point.

    Enabling that method seemed to do to the trick! :D Hm.. how can I make that as soon as it is spawned? There are multiple ways the dogs can be spawned in the world and tamed (via giving a wolf a treat, spawning them directly with an item, retaming them after untaming them and so on). Would I put that within the entityInt() method to accomplish the same thing?

  11. I mean like what jabelar had suggested

    20 hours ago, jabelar said:

    I prefer the idea of using a list to keep track of your tamed animals, rather than scanning all entities in the world to see if they are the right type and then further checking to see if they are tamed, because that is very inefficient -- less than 0.1% of entities in the world are likely to be tamed at any given time. However, you can do it by scanning if you want as the world has a list of loaded entities which you can loop through (or use contains() type methods if the data structure is amenable).

     

  12. 25 minutes ago, jabelar said:

    Are the dogs in the list, or they are not even in the list? You should use print statements to print out the list to see what is in it.

     

    When I get too far away, they seem to not appear in the list. Seems that going outside of the 102.50 z range seems to cause it to no longer show up in the list

     

    [19:35:02] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-259.50, y=66.00, z=83.50]]
    [19:35:06] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:12] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:13] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:13] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:14] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:14] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:14] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:14] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:14] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:15] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:15] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:15] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:15] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:16] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:16] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:35:17] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/61, l='New World', x=-439.50, y=81.00, z=-102.50]]
    [19:44:03] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: []
    [19:44:04] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: []
    [19:44:04] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: []
    [19:46:10] [Server thread/INFO] [STDOUT]: [doggytalents.item.ItemWhistle:onItemRightClick:36]: [EntityDog['Dog'/11235, l='New World', x=-439.50, y=81.00, z=-102.50]]

     

  13. 4 minutes ago, jabelar said:

    What do you mean it "would stop working"? Is there an error?

     

    If you mean that some of the dogs have disappeared due to being unloaded, that is a separate problem. As I already mentioned you need to set persistence on your tamed dogs if you want them to not be unloaded. 

    The dogs won't teleport to me anymore, there isn't any sort of error with it either

  14. 3 hours ago, jabelar said:

    Here's how I suggest going about it. This is how I figure things out.

     

    So your original question was how to "scan" the entities in the world. So I would go to the World class and look at what fields and methods are available, literally scroll through them to see if anything looks interesting. In Eclipse you can use the Type Hierarchy for the World class (and generally a good idea to enable all inherited stuff with little button at top of the list of methods).

     

    If you scroll through that you will see there is a field called loadedEntityList. If you right click and pick "Declaration" you can go to where it is declared in the code. There you will see that it is public scope meaning that it is available for you to use in your classes -- cool. Sometimes in modding the names of the fields and methods don't match what you expect, so it is a good idea to confirm this is what you want by looking at the Call Hierarchy for that field. If you do you'll see how it is used by Minecraft and in this case it looks like a useful thing.

     

    Now the type of field is a simple Java List<Entity>. So basically you can do everything you would want to do with a List. If you don't know Java well you should look it up, but Lists can be iterated in a loop so you can just loop through and find all the entries that are instanceof EntityDog (or whatever you're looking for) and so on.

     

    That is how you "scan the entire world for a specific entity"...

    That's actually the same method I was using before; but I burrowed some code from an experimental 1.12.2 branch of DragonMounts, it seemed to do the job but it would stop working if the dogs got unloaded.

     

    I made a few changes to the code, but I haven't given it a test (yet) -- Gave it a test, still the same results as before

    List<EntityDog> dogsList = world.getLoadedEntityList().stream().filter(dog -> dog instanceof EntityDog).map(dog -> (EntityDog) dog).collect(Collectors.toList());
    			for(EntityDog dog : dogsList) {
    				int xPos = MathHelper.floor(player.posX);
    				int zPos = MathHelper.floor(player.posZ);
    				int yPos = MathHelper.floor(player.getEntityBoundingBox().minY);
    				
    				if (dog.isTamed() && dog.isOwner(player) && (!dog.isSitting() || player.isSneaking())) {
    					for (int x = -2; x <= 2; x++) {
    						for (int z = -2; z <= 2; z++) {
    							if(DogUtil.isTeleportFriendlyBlock(dog, world, xPos, zPos, yPos, x, z)) {
    								dog.setSitting(false);
    								dog.getAISit().setSitting(false);
    								dog.setLocationAndAngles(xPos + x + 0.5, yPos, zPos + z + 0.5, dog.rotationYaw, dog.rotationPitch);
    								dog.getNavigator().clearPath();
    								dog.setAttackTarget(null);
    							}
    						}
    					}
    				}
    			}

     

  15. 10 hours ago, jabelar said:

    This brings up another issue of entity persistence as well. In regular Minecraft, entities can literally "despawn" if they are far away for long enough and I think that is probably forced during chunk unloads. This works okay for general animals (who really cares if a sheep is still there later) but for some things like structure-generated mobs (like in mansions) and maybe things like tamed animals you might want to make sure they are persistent.

     

    I prefer the idea of using a list to keep track of your tamed animals, rather than scanning all entities in the world to see if they are the right type and then further checking to see if they are tamed, because that is very inefficient -- less than 0.1% of entities in the world are likely to be tamed at any given time. However, you can do it by scanning if you want as the world has a list of loaded entities which you can loop through (or use contains() type methods if the data structure is amenable).

    Well, which ever method is easiest is the one I want to go with.. However.. I've haven't done this sort before (as in actually put in code). I don't want a direct copy-paste of code, rather I want to learn it so next time I would be able to apply this skill in any other part of the code with no problem.

×
×
  • Create New...

Important Information

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