Kriptikz
Members-
Posts
81 -
Joined
-
Last visited
Everything posted by Kriptikz
-
if getEntityFromUuid() return null when you use it in readNBT(), then don't use it there, do what I recommended above. The only thing you would need to change from how I do it in my code would be instead of: caster = this.world.getPlayerEntityByUUID(this.casterId); you would do something like: caster = this.world.getMinecraftServer().getEntityFromUuid(this.casterId); I didn't test this out so no idea if you need isRemote() before using this or honestly if this is how you would actually get WorldServer in order to use getEntityFromUuid() but this is what I would try.
-
I don't think you're actually setting attachEntity to anything right there. Also idk if that works with other entities but you cant set the entity in readNBT if its a player
-
In my mod I have my spells store who the spellcaster is by uuid and I store the player entity in a weak reference so you don't have to get the entity by uuid every time you want to use it and it's a weak reference, instead of a normal EntityLivingBase, to prevent possible memory leaks. Here is where I read/write the uuid to nbt: https://github.com/Kriptikz/Archmage/blob/1.11.2-Refactor/src/main/java/kriptikz/archmage/entity/EntitySpellBase.java#L302-L326 Then anytime you need to do something based on the entity you can either use, also make sure to check for null if using this directly: https://github.com/Kriptikz/Archmage/blob/1.11.2-Refactor/src/main/java/kriptikz/archmage/entity/EntitySpellBase.java#L235-L248 Or you can do what I do, which is every time onUpdate runs I store the caster in a local EntityLivingBase and if the caster is offline getCaster() will return null so I just set my entity to dead and return: https://github.com/Kriptikz/Archmage/blob/1.11.2-Refactor/src/main/java/kriptikz/archmage/entity/EntitySpellBase.java#L118-L124
-
I'm pretty new to modding Minecraft so no idea if I'm actually doing this properly, but I call super.renderParticle() in my custom particle to let the vanilla code handle the rendering, mainly because I don't know how to properly use opengl and also I don't think writing the rendering myself is necessary for basic particles. Here is my custom fire particle and where I call super.renderParticle(): https://github.com/Kriptikz/Archmage/blob/1.11.2-Refactor/src/main/java/kriptikz/archmage/client/particle/ParticleFire.java#L43-L48 The only custom code in my ParticleFire#renderParticle() is to change the scale of the particle over time so it shrinks. Then I just call super.renderParticle to do the actually rendering. Also, in order to use the custom texture here: https://github.com/Kriptikz/Archmage/blob/1.11.2-Refactor/src/main/java/kriptikz/archmage/client/particle/ParticleFire.java#L39 I register it here, in the TextureStitchEvent: https://github.com/Kriptikz/Archmage/blob/1.11.2-Refactor/src/main/java/kriptikz/archmage/client/TextureStitcher.java Also, remember you have to register the class using TextureStitchEvent, I do that in ClientProxy here: https://github.com/Kriptikz/Archmage/blob/1.11.2-Refactor/src/main/java/kriptikz/archmage/proxy/ClientProxy.java#L24
-
You can try offsetting it by a couple blocks and see what happens, it may be colliding with the thrower. Also if your using most of EntityThrowable code why not just extend from it and override/add stuff. Minecraft also has an EntityFireball class that you could check out. But yeah, working Git repo will make helping you out now and possibly in the future much easier.
-
Show your EntityOpalShot class
-
lol yea, but it still works I edited my comment to reflect what little changes there were.
-
This is the tutorial I followed by the man himself. It is old, but still works as the general concepts are the same. I don't think you have to create the debug configurations anymore, as they were already there for me for 1.11. I did have to remove the VM arguments in order for it to work though. Also you shouldn't have to change anything in the build.gradle file except for Hope this helps. https://www.youtube.com/watch?v=xp2jmt47yTQ
-
You can easily share modpacks using curse voice.
-
Take a closer look at EntityArrows onUpdate() method, your missing a lot of stuff in yours, for example that would be where you call onHit() after doing some raytracing and/or calling findEntityOnPath(). You should also check out EntityFireball, mainly how onUpdate() is written in there and how its different than EntityArrows onUpdate(). You could also just extend EntityThrowable and change some stuff in it to suit your needs, like getGravityVelocity to something smaller and override onImpact() to handle what it does on impact.
-
I shouldn't have said creating an object, I mean by creating the reference the computer has to allocate more memory to store that reference. I was thinking why recreate another reference every tick if I can just have one main reference. It seems I may be misunderstanding a fundamental programming concept, as allocating memory for the reference is probably too negligible to really matter. Every reference does allocate more memory though, right? Interesting, now I'm torn between 3 possible implementations lol. 1. When the player logs off the spells energy source is then gone so the spell vanishes doing nothing. 2. When the player logs off the spell continues going and does its effects but the player will not get xp from it. 3. Have the player gain xp when the spell is initially spawned. Probably going to test all 3 and see how it goes. This is all pretty much off topic now though, so thanks for all the help I really appreciate you sticking with me and helping me wrap my head around this stuff.
-
In my mod the player has spells. Each spell has a level and xp associated with it. So taking the fireball spell for example, if the player casts a fireball spell and it hits an entity it will damage the entity relative to the level of the spell, higher level spell does more damage. I also want the players SpellData capability to increase the xp for the fireball spell so the spell can level up and get stronger. Why I wanted to access the capability after the player logged out is because if the player casts the fireball spell, which will spawn an EntitySpell for the fireball, and then the player logs out I wanted the fireball to continue going until it impacts something. When it impacts an entity I need the SpellData capability to get the fireball spells level so it knows how much damage to do. Also, when it impacts an entity, I need to get the players SpellData capability and increase the fireball spells xp. The problem is the player is logged out, so I was wondering if I could modify the capability when the player was logged out so this would still work. It seems I probably shouldn't do it this way, but I was curious if it was possible. What I'm going to do instead is if the player is logged off the spell will die. I wanted to store the player in a strong reference because I don't like the idea of creating an EntityLivingBase and ISpellData object every tick because it seems like overkill but I guess it is necessary: @Override public void onUpdate() { EntityLivingBase caster = getCaster(); if (caster == null) { this.setDead(); return; } ISpellData spellData = caster.getCapability(SpellDataProvider.SPELL_DATA, null); // Do spell movement updates and logic
-
My EntitySpell should only last about 10-20 seconds max and then it gets setDead(). So the player spawns the EntitySpell and then logs out. The EntitySpell is referencing the player entity, which means the player entity cannot be GC'd. The EntitySpell keeps existing for 10 more seconds, then gets setDead(). Now that EntitySpell is dead, its strong reference to the player entity should be removed when EntitySpell is GC'd, thus allowing player entity to also be GC'd, is this correct? Also, back to the capability, if I have a strong reference to the players capability in EntitySpell and the player logs out the EntitySpell will still be holding that reference, right? So if I change some of the players capability data in EntitySpell using its strong reference to the players capability, when the player is logged out, will that actually effect the players capability data? Will that change in the capability data when the player was logged out hold true when the player logs back in?
-
Awesome Thanks! I'm still trying to wrap my head around why using a WeakReference is necessary though. So why I'm using a WeakReference variable in the entity rather than a StrongReference, such as, private EntityLivingBase caster; Is because of possible memory leak. Does this mean that even if the entity is setDead() and in World::updateEntities() , I believe this is where the entity is removed if Entity::isDead, the entity is removed but may not be set up so it can be GC'd? Another way to put this is, shouldn't any variables/references inside the entity, weak or strong, and the entity itself be set to be GC'd when it is removed?
-
So if I want to cache the entity I will use a weak reference like this? : From what I understand so far, using a weak reference can get GC'd at any moment correct? So anytime I use caster I would need to check if it is null and if it is use: this.caster = new WeakReference<EntityLivingBase>(caster); Correct? OR, Should I put the weak reference inside the entities onUpdate() method as well as the doSpell() method because these are the two places where the caster is referenced. I'm still worried about it getting GC'd in the middle of using it though, can it get GC'd in the middle of a method that it was created in? Here is the code, the WeakReference isn't implemented but this is what I'm working with: https://github.com/Kriptikz/Archmage/blob/1.11.2/src/main/java/kriptikz/archmage/entity/EntitySpellBase.java
-
So I shouldn't have: private EntityLivingBase caster; In my entity class at all, and should instead use either PlayerList::getPlayerByUUID or World::GetPlayerEntityByUUID anytime I reference the caster? PlayerList::getPlayerByUUID also seems to return null if the player isn't online though, So I think I'm going to go with setting the entity to dead if PlayerList::getPlayerByUUID or World::GetPlayerEntityByUUID returns null. No idea how to use a WeakReference but I'll look into it. Why use a WeakReference over private EntityLivingBase caster
-
I'm having trouble with the readingNBT method of an entity. Here is the code: When it gets to the line: this.setSpellData(this.caster) this.caster is null so I get an error trying to get the capability. I was thinking of having the entity keep going after cast, even if the player logs off and still level up the spell in the players capability if it hits an entity. I think i'm just going to have the entity die if the player logs off.
-
When spawning an entity from an items onPlayerStoppedUsing method, the entity works server side but it seems it's not getting spawned client side. Here is my item class: https://github.com/Kriptikz/Archmage/blob/1.11.2/src/main/java/kriptikz/archmage/item/ItemWand.java#L55 From what I understand, an entity should only be spawned server side and the server will tell the client to spawn the entity, but it's not spawning it on the client. This worked for me previously before I changed my spell class hierarchy to something I thought would work better for me. Basically I have it set up so my ItemWand class will be cleaner, previously I had this: Some spells are projectiles and some are not. So in the new version I have ISpellBase interface which has only two methods, isProjectile() and doSpell(). From here I have another base class called EntitySpellBase. If the spell is a projectile I extend EntitySpellBase, if not it just implements ISpellBase. I use isProjectile() to determine if the spell is a projectile, if it is I spawn it, if its not I just doSpell(). My goal with the change was to make the code cleaner and make it easier to implement different models for different spell projectiles as well as allow handling a spell easily whether it is suppose to be a projectile or not. So in the switch statement any spell could be initialized like this, whether it is suppose to be an entity or not: Where SpellFireball is replaced by the corresponding spell. This seemed like it could work nicely, but maybe it's a bad design. I'm pretty new to programming in general so any criticism is welcome. I do have other designs in mind but I liked this one the most.
-
[1.11.2] Can you use an obj for an entity model?
Kriptikz replied to Kriptikz's topic in Modder Support
Welp, looks like this out of my league lol. I'm currently in the process of learning openGL and it looks like I will need openGL to write my own render, So this project will be put on hold. Thanks for the help!