This tutorial will use the original diamond sword as an example to create a throw of a diamond sword model
First, let's register a throw:
Customitemprojectileevents.regization (event => {{{{Event.create ("Testproj: Diamond_proj"))
})
Then set its size
Customitemprojectileevents.regization (event => {{{{Event.create ("Testproj: Diamond_proj"))
.Size (0.4, 0.4) // The default is (0.5, 0.5) You can modify his size (width, height) by yourself
})
Set the attacking entity
Customitemprojectileevents.regization (event => {{{{Event.create ("Testproj: Diamond_proj"))
.Size (0.4,0.4) // The default is (0.5,0.5) You can modify his size (width, height) by yourself
.Canhitentity ((Proj, Entity) => {
Return Proj.oldcanhitentity (Entity) && Entity.gettype () == "Minecraft: zombie" // Proj.oldcanHitentity (Entity) means that if the default method is not added, it means completely rewritten Canhiten. tity method
}) // On the basis of the default, you can only attack zombies
})
Set the behavior of hitting blocks and hitting entities
Customitemprojectileevents.regization (event => {{{{Event.create ("Testproj: Diamond_proj"))
.Size (0.4,0.4) // The default is (0.5,0.5) You can modify his BOX size (width, height)
.Canhitentity ((Proj, Entity) => {
Return Proj.oldcanhitentity (Entity) && Entity.gettype () == "Minecraft: zombie" // Proj.oldcanHitentity (Entity) means that if the default method is not added, it means completely rewritten Canhiten. tity method
}) // On the basis of the default, you can only attack zombies
.Onhitentity ((Proj, Hitresult) => {
Hitresult.entity.attack (10) // Causes 10 damage to the hit entity})
.Onhitblock ((proj, hertresult) => {{
Proj.setsoundevent ("item.trident.hit_ground") // Set sound
Proj.oldonhitBlock (Hitresult) // Use the default hit method
})
})
Set the method of engraving
Customitemprojectileevents.regization (event => {{{{Event.create ("Testproj: Diamond_proj"))
.Size (0.4,0.4) // The default is (0.5,0.5) You can modify his size (width, height) by yourself
.Canhitentity ((Proj, Entity) => {
Return Proj.oldcanhitentity (Entity) && Entity.gettype () == "Minecraft: zombie" // Proj.oldcanHitentity (Entity) means that if the default method is not added, it means completely rewritten Canhiten. tity method
}) // On the basis of the default, you can only attack zombies
.Onhitentity ((Proj, Hitresult) => {
Hitresult.entity.attack (10) // Causes 10 damage to the hit entity
})
.Onhitblock ((proj, hertresult) => {{
Proj.setsoundevent ("item.trident.hit_ground") // Set sound
Proj.oldonhitBlock (Hitresult) // Use the default hit method
})
.Ontick (proj => {{{
Proj.oldtick () // Use the default method
Proj.Level.spawnparticles ("Minecraft: Snowflake", TRUE, Proj.x, Proj.y, PROJ.Z, 0, 0, 1, 0)}) every moment of particles})
})
The main part of the rendering effect has been completed how to generate this throw.
First, load the class.
const $ customitemprojectile = java.loadClass ("Chen1335.CustomIteMProjectile.World.Projectile.CUSTMITEMPROJ ectile ")
Then...
const $ customitemprojectile = java.loadClass ("Chen1335.CustomIteMProjectile.World.Projectile.CUSTMITEMPROJ ectile ")Itemevents.richtclicked ("Minecraft: Diamond_sword", event => {{{{
Var CustomITEMPROJECTILE = New $ CustomiteMProjectile ("Testproj: Diamond_Proj", Event.Level) // Create a physical object
Customitemprojectile.Setowner (event.player) // Set the owner
CUSTMPROJELELE.SetITEMSTACK ("Minecraft: Diamond_sword") // Set Itemstack
CustomiteMProjectile.Setposition (event.player.x, event.player.y+event.player.eyehead, event.player.z) // Set location position
Customitemprojectile.shootfromrotation (event.player, event.player.getxrot (), event.player.getyrot (), 0, 2, 1) // Set the initial motion status
CUSTMPROJECTILE.HITINFLATEX = 0.5 // Set the increase in the determination of the judgment box (this one can be set without setting, the original calculation is a bit problematic.
Event.Leveel.addfreshentity (CustomItemprojectile) // Generation
})
The general part has been completed and the test is now successful!
If you just want to make a throw of a flying knife, you don't need to look at the following.
Set Customrende (mainly adjustment of Posstack), if it is not performed, use the default render (flying knife)
We can set the temporary render method in the game
Itemevents.RightClicked ("Minecraft: Diamond_sword", event => {{{{Var CustomITEMPROJECTILE = New $ CustomiteMProjectile ("Testproj: Diamond_Proj", Event.Level) // Create a physical object
Customitemprojectile.Setowner (event.player) // Set the owner
Customitemprojectile.setItemstack ("Minecraft: Diamond_sword") // Set itemstack (can be enchanting)
CustomiteMProjectile.Setposition (event.player.x, event.player.y+event.player.eyehead, event.player.z) // Set location position
Customitemprojectile.shootfromrotation (event.player, event.player.getxrot (), event.player.getyrot (), 0, 2, 1) // Set the initial motion status
CUSTMPROJECTILE.HITINFLATEX = 0.5 // Set the increase in the determination of the judgment box (this one can be set without setting, the original calculation is a bit problematic.
Customitemprojectile.setCustomrender (context => {{
Context.posestack
// Too much trouble I won't be: (((((
})
Event.Leveel.addfreshentity (CustomItemprojectile) // Generation
})
After the adjustment is completed, you need to write it into the registered throwing object
Customitemprojectileevents.regization (event => {{{{Event.create ("Testproj: Diamond_proj"))
.Size (0.4,0.4) // The default is (0.5,0.5) You can modify his size (width, height) by yourself
.Canhitentity ((Proj, Entity) => {
Return Proj.oldcanHitentity (Entity) && Entity.gettype () == "MineCraft: zombie" // Proj.oldcanhitentity (Entity) means that if you do not add this method, it means completely rewriting Canhits. iTy method}) // in the defaultBased on the basis, you can only attack zombies
.Onhitentity ((Proj, Hitresult) => {
Hitresult.entity.attack (10) // Causes 10 damage to the hit entity
})
.Onhitblock ((proj, hertresult) => {{
Proj.setsoundevent ("item.trident.hit_ground") // Set sound
Proj.oldonhitBlock (Hitresult) // Use the default hit method
})
.Ontick (proj => {{{
Proj.oldtick () // Use the default method
Proj.Level.spawnparticles ("Minecraft: Snowflake", TRUE, Proj.x, Proj.y, Proj.z, 0, 0, 1, 0) //
})
.Customrender (context => {{
// ...
}) // Custom Render
})