#I want to add an ability to my sword to make it so if it hit a mob the mob gets glowing effect
269 messages · Page 1 of 1 (latest)
?
.
?
yes
so event -> then call LivingEntity#addStatusEffect on the attacked with glowing
i can't find the event to give examples
you got it?
no :_:
am still learning
i made a sword
called the glowing stick
and it has atk damage and atk speed
does it have a custom item class?
net.minecraft.item.Item
has
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker);
that you could override
can i ask what does override meean ;-; am a beginner ;-;
item stack is the item am holding right?
i have a class
where do you register the item
is the seccond one better?
i just had a misssing string
ah, just edit next time.
alr
k
so your GlowingSword class
really should be GlowingSwordToolMaterial or GlowingToolMaterial
why?
because i represents the material, not the sword itself
and you should make a GlowingSwordItem class
but ill have to change alot of code ;-;
alr sec
java has something called anonymous classes
hold.
alr sorry
i'm try to make it so you can change as little as possible
alr
ye
you can also do something like
Item item = new Item(/* settings */) {
@Override
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) {
super.postHit(stack, target, attacker)
}
}
idk what the boolean does.
let me check
looks like it
the ItemStack is the stack of the sword.
every item has an instance, that is registered with minecraft
so how do we tell java that the item stack is th sword
this instance can be used to make itemstacks
which is what players think of when they say item
usually
disregarding weird moments.
the methods in your item class will only be called with an itemstack of your item
so, what point are you at?
si put the boolean method with the ovveride under my register for the sword??
public static final Item glowsword = registerItem("glowsword",
new SwordItem(INSTANCE,new Item.Settings().rarity(Rarity.UNCOMMON).
attributeModifiers(SwordItem.createAttributeModifiers(INSTANCE,5,-2.4F))) {
@Override
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) {
return super.postHit(stack, target, attacker)
}
});
should work
did it work?
no errors
great. ping me if you need me.
so how to tell him to give the entity glowing effect ;-;
him = fabric
him = the attackedEntity?
ye
do you know of the maven docs?
no?
fabric has a documentation.
ye ik
every class has a webpage detailing every feature it has
and every parameter is hyperlinked. you you can see where to get the perameters
can you do ctr + f?
i find that helpfull
alr thanks ill look into it in the mean time i need go thx again
👍 ping me if you need me.
hi are u there?
@fickle fox
so i made a class item
ands used the example from the docs
and now when i right click it spawns lightning
i cant figure out how to do it with posthit tho
hey, im back
what breaks if you just put it in the postHit Method?
wdym
posthit is a boolean
yeah so?
i dont think u can return a livinentity from a boolean
i need to give the entity i hit an effect
how to use it then?
package com.example;
import net.fabricmc.fabric.api.event.Event;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.swing.*;
import java.util.Set;
public class GlowStick extends SwordItem {
public GlowStick(ToolMaterial tl,Settings settings){
super(tl,settings);
}
// eluded due to lacking nitro...
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) {
if (target.getWorld().isClient || attacker.getWorld().isClient)
return true;
BlockPos targetPos = target.getBlockPos();
LightningEntity lightningBolt = new LightningEntity(EntityType.LIGHTNING_BOLT, target.getWorld());
lightningBolt.setPosition(targetPos.toCenterPos());
target.getWorld().spawnEntity(lightningBolt);
return true;
}
}
like that?
@quiet arrow
u busy now?
no sorry iwas doin smt
world cant be accessed in post hit
what version are you in
look right now?
?
what?
i edited it.
no
why
that would end badly
i wanna see if we can get it to work on the client first
NO
sorry
dw
caps was on
btw we dont need to have it spawn lightning
package com.example;
import net.fabricmc.fabric.api.event.Event;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.swing.*;
import java.util.Set;
public class GlowStick extends SwordItem {
public GlowStick(ToolMaterial tl,Settings settings){
super(tl,settings);
}
// eluded due to lacking nitro...
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) {
if (target.getWorld().isClient || attacker.getWorld().isClient)
return true;
BlockPos targetPos = target.getBlockPos();
LightningEntity lightningBolt = new LightningEntity(EntityType.LIGHTNING_BOLT, target.getWorld());
lightningBolt.setPosition(targetPos.toCenterPos());
target.getWorld().spawnEntity(lightningBolt);
return true;
}
}
k
now lets do glowing
k
target.addStatusEffect(new StatusEffectInstance(StatusEffects.GLOWING, 10 * 20, 1))
alr am back
small question
how do u know
that
since i couldnt find it on the wiki
not the wiki
the docs.
the wiki is only usefull for beginers
and apparently i can't spell
let me show you
alr
if you go here
and then here
you have a searchable list of every class minecraft offers
make some sense?
ye
did you get the glowing working?
did the reason not to do it on the client make sense?
because true seems to indicate success
doest it get out of the method if smt is returned?
oh
IT WORKS
if statements can have one statement under them. typically we put a block statement, such as {} but you can also put other types of statements there, such as a return statement
so what happens if the if condition is false?
it just does nothing?
why tho the other code isnt under the if
.
one statement
ah alr thx
no ;-;
@quiet arrow how much java you know generaly? If you want to mod you should try and learn java first, like how classes, inheritance type etc
https://fabricmc.net/wiki/tutorial:side seems applicable
i mean
i don't recomend modding before java.
but it's the way i learned
i mostly know all java
wdym
like from what i know, ik all java
I defenetly do not reccomend that
coding languages you mean?
?
.
@quiet arrow you consider yourself proficient in java?
i mean not exacly
or you know all the java you know because u r modding
i learnt java then i started coding
hmm.
there are many tutorials online, even by youtube channels for minecraft modding that explain the basics and more java knowladge you will need
/\
am using 1.21 so most tutorials are outdated
for modding yes, but not for java coding
not for modding itself, but the java you need to know to get into modding
yeah
if you look at the great minecraft mods
like enderio and extrautilities
like 10% is modding
the rest is java
ik java coding
like you said not exacly
how can i consider my self a proficient
if you mean you do not know java for coding than okay, but if you do not know java in some aspects it will be almost impossible to mod
we're always here to help, but sometimes, it can be hard if the person needing help is missing foundational concepts in java. learning those foundational concepts saves hours of banging your head against the wall. for us and for you
Go to a tutorial, look at the chapters/episodes, or at least their names, if you understand what the names mean and how they work in java then you are probably
alr
good luck.
do i need to know stuff like grid layout
that sounds like javascript? (I rescind My Statement)
letme google
hmm.
i mean u seem not to know it
that is more applied java, not basics of java.
i did a unit on it back when i learned 2+ years ago.
honestly haven't used it sense.
but no
@clever whale how can i say basics of programing (Data Structures) (Iteration Concepts) (Memory Managment) (Threads) (Component Models (Server / Client)) (Functions / Methods) (Constructors)
This is only for interface i believe, anyway this shouldnt be needed for minecraft, more learn the basic syntax, make sure you understand loops, conditionals, clases: inheritance, objects, methods (static, public, private, protected etc) constructors, interfaces: implementation
ik all that
classes and interfaces are most important as they are used throughout java (and minecraft) a lot
then practice is your freind.
you should understand what inheritance and override means etc
lambdas
...... ik lambda but i struggle with it ;-;
is there a good vid that explains it well
GeeksForGeeks generaly has good text tutorials.
idk. like i said, I tought myself from minecraft, so I don't know where to find resources. but yt is probably a good place to start
that too
many sites offer tutorials a few i use when i get stuck with syntax are geeksforgeeks, w3school and baeldung they all explain the uses and works of the syntax and function pretty well