Jump to content

1.7.2 NEED HELP with entities and events


zacharyjaiden

Recommended Posts

ok so im making it so that my custom entities (and maybe some vanilla entities) can only spawn when condition is met, i have browsed through the forge events and found the event living spawn event, is that suited for this?

 

i am not quite sure how to properly use this event can anybody help out with this?

 

in sudo ive kinda thought of this way

 

 @SubscribeEvent
    public void LivingSpawnEvent(LivingSpawnEvent event) 
{
  	 EntityPlayer player = (EntityPlayer)event.getPlayer();

  	 if(event.entity == EntityCutstomMob && StorageLevel.getPlayer().GetMasterLevel() < 5)
            { setCanceled{True}
             }  	
   
    } 

 

i know this event or a part of this event is cancelable but im not 100% sure how to properly set canceled so if anyone knows that aswell please let me know, but basically i need to know how to do this in the way that ive displayed but obviously not sudo properly with the correct terms and such

 

thanks in advance +1 karma for any answers (that arent just for sake of getting karma) :)

Link to comment
Share on other sites

Hi

 

the code you posted is close, I reckon it will work if you modify it slightly to use the following event:

 

   /**
     * Fires before mob spawn events.
     * 
     * Result is significant:
     *    DEFAULT: use vanilla spawn rules
     *    ALLOW:   allow the spawn
     *    DENY:    deny the spawn
     *
     */
    @HasResult
    public static class CheckSpawn extends LivingSpawnEvent

 

In your handler you should call event.setResult(your result here);

 

-TGG

 

Link to comment
Share on other sites

LivingSpawnEvent event) 
{
  	 EntityPlayer player = (EntityPlayer)event.getPlayer();
if(event.entity == EntityCutstomMob && StorageLevel.getPlayer().GetMasterLevel() < 5)
}

You can't get a EntityPlayer instance from those event. They are for mobs.

 

Your entity check could be

if(event.entity.getClass().equals(EntityCustomMob.class))

Link to comment
Share on other sites

thank you for your amusing arrogance diesieben but i do know basic java. you dont have to try and belittle everyone on this forum i look at quite a few posts on this forum and a great percentage of them have at least one post from you using that little phrase of yours, i have used instanceof before with items and blocks but didnt know that it would apply to an entity since the way i came about that term implied that it was something used for "things" not entities so i never looked into it too much, obviously i was wrong but i and everyone else on this forum dont need comments like those, it may very well hinder peoples ability to learn and progress their skills as you probably make a lot of people uncomfortable and or embarrassed which im sure youre quite aware of... i dont appreciate it.

 

my attempt in thinking if the entity == entityWHATEVER isnt that far fetched..

 

at least gotoLink can provide help without trying to downgrade others (appreciate your help gotolink +1 karma)

 

and its not like i was asking anyone to code the thing for me i had a general idea of what i was doing from the start

Link to comment
Share on other sites

you do need to get off your high horse, just because somebody doesnt understand java yet to the extent that you do does not mean that they dont know "basic java", i learn the java associated with minecraft modding because im using it to MOD MINECRAFT, i learn what i can from tutorials (which im sure you read tutorials when you were starting out too) also from minecraft source code, i dont know all of the applications of the code ive learnt but i know how to use it pretty widely, what i dont know i come to this forum for help, (which is the very purpose of this forum) not for criticism on my knowledge of the language... your contribution consisted of a single word, which i already knew just didnt think to apply it and you find it necessary to downgrade my knowledge and skills when in comparison to you obviously high opinions and views on your own, i am fairly new to java and minecraft modding hence why i seek out support. again get off your high horse mate come to this forum to help people not throw out negative comments. that one word "instanceof" was all i needed not my code written for me as you seem to think

Link to comment
Share on other sites

Zachary,

 

Most of the time when someone around here encourages you to learn more about Java, we are doing so in an effort to help you, and getting upset about it is not very conducive to learning. As we've discussed before, learning Java is a process, and claiming that you already 'know basic Java', while it certainly contains some truth, is also far enough from reality that believing this is simply going to prevent you from taking the steps necessary to expand your knowledge.

 

I've been coding in Java for almost a year now, and while I have a pretty good grasp of most of the fundamentals, I am still always learning new things, even things that most Java programmers would consider extremely basic (such as the difference between 'instanceof' and 'isAssignableFrom(Class)', which I learned about only a month or two ago).

 

So when you ask a question and someone responds with 'please learn basic Java, what you want is {fill in the blank}', instead of getting upset at that person, take the opportunity to do a search for the Java documentation of whatever they said you needed (e.g. instanceof), and you will not only have shown yourself to be a mature and proactive individual, but you will also have learned valuable information that will make modding much easier, especially if you make it a habit to look things up.

 

On the other hand, if you don't care about learning Java except just enough to make a mod, then you can hardly expect people to take you seriously on a forum such as this.

 

Sorry for the rant, but please understand that help comes in many forms, and the best kind of help is the kind that helps you help yourself. As the saying goes, 'Give a man a fish, you feed him for a day; teach a man to fish, you feed him for a lifetime.'

 

Regards,

coolAlias

Link to comment
Share on other sites

Zachary,

 

Most of the time when someone around here encourages you to learn more about Java, we are doing so in an effort to help you, and getting upset about it is not very conducive to learning. As we've discussed before, learning Java is a process, and claiming that you already 'know basic Java', while it certainly contains some truth, is also far enough from reality that believing this is simply going to prevent you from taking the steps necessary to expand your knowledge.

 

I've been coding in Java for almost a year now, and while I have a pretty good grasp of most of the fundamentals, I am still always learning new things, even things that most Java programmers would consider extremely basic (such as the difference between 'instanceof' and 'isAssignableFrom(Class)', which I learned about only a month or two ago).

 

So when you ask a question and someone responds with 'please learn basic Java, what you want is {fill in the blank}', instead of getting upset at that person, take the opportunity to do a search for the Java documentation of whatever they said you needed (e.g. instanceof), and you will not only have shown yourself to be a mature and proactive individual, but you will also have learned valuable information that will make modding much easier, especially if you make it a habit to look things up.

 

On the other hand, if you don't care about learning Java except just enough to make a mod, then you can hardly expect people to take you seriously on a forum such as this.

 

Sorry for the rant, but please understand that help comes in many forms, and the best kind of help is the kind that helps you help yourself. As the saying goes, 'Give a man a fish, you feed him for a day; teach a man to fish, you feed him for a lifetime.'

 

Regards,

coolAlias

 

Ok, i get what youre saying cool alias and i guess youre right, its just im dedicating hours of my time to read java documentation, minecraft tutorials and browsing the forums, when im getting responses of "Learn basic java" its really annoying me BIG time as i am very new to this and i am like i said dedicating quite a large portion of my time to learning all the fundamentals of java and learning the way minecraft is coded, i feel like those comments shot straight out of nowhere get to me.

 

i owe you a bit of an apology diesie, i shouldnt of gotten angry at you, i do in fact appreciate your help, ive known the basics of java and modding minecraft for quite a while although havent done it for a couple years so i have forgotten quite a few things... i never needed to expand my knowledge of java cause i didnt need to know anything new but ive been trying to venture into new territories in modding and faced a lot of java problems and in doing so, ive spent hours recapping over the java i already knew, and have spent hours reading up on new java information when relevant issue arise, i may ask some dumb questions but like i said im new, i absolutely do not want anybody to write the mod for me but i do appreciate helpful information something like "google switch statements mate that might help" rather than "Learn basic java. use (this word) instead of (thatword)" helps a lot more and would be appreciated 100 times more

 

if im asking a question on here its because i probably dont know what area of java to look up for the class im trying to create :/

Link to comment
Share on other sites

While diesenben's comments are often terse you shouldn't take them as being on a high horse or belittling.  He spends time to correct a lot of us, and being corrected can feel like being criticized but diesenben is usually right on the mark with his comments.

 

Confusion about ==, .equals() and instanceof is a failure to understand basic java.  (I'm also new to Java and have similar failures all the time, for example I'm always trying to compare strings with == which is a no-no).  You can see that GoToLink (another highly respected commenter here) suggested .equals() and diesenben even had improvement over that in understanding the performance impact of instanceof.

 

I would treat diesenben like a tough martial arts instructor.  Just the fact that he is commenting on your thread shows that he cares about you and his comments have a point you should consider carefully.  It's tough love.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Pretty much, although all the recipes im planning to make on it are shapeless. The idea is that the chamber uses energy to "fuse" the items in each of the center slots together, in this case an ingot. The two slots at the sides are fuel. (A special kind of wood in this case). Here is an image of the interface just for reference (The center slot is the output)   As for the code- Can you elaborate a little bit on it? Seeing three different record classes has confused me a lot. (Elaborate as in why make them in three different records. I understand the code itself more or less)
    • Hello im trying to make a mod and the past few days GSON has almost killed me, when i export the mod and then launch it through minecraft launcher i get java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)Lcom/google/gson/JsonElement; i have literally tried everything here is my build config   dependencies { minecraft("com.mojang:minecraft:1.8.9") mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") compileOnly("cc.polyfrost:oneconfig-1.8.9-forge:0.2.2-alpha+") shadowImpl("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+") { isTransitive = false exclude(module = "gson") } shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") { isTransitive = false exclude(module = "gson") } annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT") shadowImpl("org.javassist:javassist:3.15.0-GA") { isTransitive = false exclude(module = "gson") } shadowImpl("com.neovisionaries:nv-i18n:1.28") { isTransitive = false exclude(module = "gson") } shadowImpl("org.apache.commons:commons-lang3:3.4") { isTransitive = false exclude(module = "gson") } shadowImpl("org.apache.httpcomponents:httpcore:4.4.5") { isTransitive = false exclude(module = "gson") } compileOnly("com.google.code.gson:gson:2.8.6") { isTransitive = false } configurations.all { resolutionStrategy { force("com.google.code.gson:gson:2.8.6") } } shadowImpl(fileTree( mapOf( "dir" to "libs", "include" to listOf("*.jar"), "exclude" to listOf( "asm", "asm-commons", "asm-tree", "gson", "unspecified", "nv-i18n" ) ) )) }  
    • @chxr Looks like you're making some sort of a crafting table / furnace hybrid? Are the inputs needing arranging like a shaped recipe, or is it shapeless? I'll assume it's shapeless since that just adds a lot more complexity. In that case I'd probably do something like this { "type": "relativedimensions:particle_rebound", "inputs": [ { "ingredient": { "item": "relativedimensions:aberrant_shard" }, "count": 8 } ], "fuel": { "tag": "relativedimensions:block/aberrant_fuel" }, "output": { "Count": 1, "id": "relativedimensions:aberrant_ingot" } } inputs: A list of ingredients and how many are needed. The count among each input adds up to 8. Since there's only 1 ingredient, the count is set to 8. fuel: Same thing as before but remove the list and just make it an object with a tag. output: Kept the same.   In this case the Codec I would make is public record ParticleReboundIngredient(Ingredient ingredient, int count) { public static final Codec<ParticleReboundIngredient> CODEC = RecordCodecBuilder.create( builder -> builder.group( Ingredient.CODEC.fieldOf("ingredient").forGetter((i) -> i.ingredient), Codec.INT.fieldOf("count").forGetter(i -> i.count) ).apply(builder, ParticleReboundIngredient::new) ); } public record ParticleReboundFuel(String tag) { public static final Codec<ParticleReboundFuel> CODEC = RecordCodecBuilder.create( builder -> builder.group(Codec.STRING.fieldOf("tag").forGetter(f -> f.tag)).apply(builder, ParticleReboundFuel::new) ); public boolean isFuel(ItemStack stack) { // TODO: Check if fuel item matches the tag } } public record ParticleReboundRecipe(List<ParticleReboundIngredient> inputs, ParticleReboundFuel fuel, ItemStack output) { public static final Codec<ParticleReboundRecipe> CODEC = RecordCodecBuilder.create( builder -> builder.group( ParticleReboundIngredient.CODEC.listOf().fieldOf("inputs").forGetter(r -> r.inputs), ParticleReboundFuel.CODEC.fieldOf("fuel").forGetter(r -> r.fuel), ItemStack.CODEC.fieldOf("output").forGetter(r -> r.output) ).apply(builder, ParticleReboundRecipe::new) ); }   There might be a more proper Codec for the fuel and the tag that's built into minecraft / forge, but I didn't look
    • Tested with 5900X, 64GB 3200 MHz, 3070 Ti, driver 551.86 GPU clock range: 200 - 1950 MHz, usually 210 MHz with 10-30% utilisation on desktop idle use Render settings: Vsync ON, Framerate unlimited, Render distance 32, Fullscreen ON (60hz monitor, so 60 fps with vsync) Vanilla minecraft: Main menu: 210mhz idle clock always, ingame clock around 400 - 1000 mhz with ~30% utilisation and after alt+tab stays at same. Modded install with curseforge app, only said forge added: Main menu: 210 mhz idle clock always, ingame clock around 400 - 1000 mhz with ~30% utilisation, but after alt+tab gpu clock shoots up to 1950 mhz and utilisation is at 50-60% After disabling all render and chunk related stuff in config, after alt+tab it goes up to 1500 mhz. So game turns gpu into space heater when its not even seen. GPU usage returns to expected when game comes back on top. If instead of unlimited fps, fps is set to ~60, then during alt+tab gpu stays at same range as vanilla, but minecraft has horrible limit logic and framerate limit causes lot of tearing, so its not an option. So it seems that when alt+tabbing, for some reason logic no longer takes vsync toggle into account. So expected behaviour would be for it to work like vanilla does. keep rendering in same manner, no matter if its seen and use same amount of resources. Essentially noticed this behaviour while playing Supersymmetry and after elimination testing, result was that only Forge was enough to cause it. And also confirmed it by doing fresh pack with only Forge added, so no other mods even in disabled state. Also happened with both singleplayer and remote multiplayer. Other offender was "Universal Tweaks" which introduced same effect to main menu with its # Removes the hardcoded 30 FPS limit in screens like the main menu B:"Uncap FPS"=true setting, meaning when game was on top, it still worked in limits of vsync cap, but after alt+tabbing even in main menu gpu usage shot up to max.
    • Add crash-reports with sites like https://paste.ee/ and paste the link to it here Make a test without the mod auditory
  • Topics

×
×
  • Create New...

Important Information

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