Skip to content

Instantly share code, notes, and snippets.

@dcbriccetti
Last active August 29, 2015 14:13
Show Gist options
  • Save dcbriccetti/da05c00e4ae6d9afdef7 to your computer and use it in GitHub Desktop.
Save dcbriccetti/da05c00e4ae6d9afdef7 to your computer and use it in GitHub Desktop.
An excerpt from Dave Briccetti’s first non-trivial Minecraft mod, inspired by Devoxx4kids Sharp Snowballs: https://github.com/devoxx4kids/materials/tree/master/workshops/minecraft
class SharpSnowballArray {
@SubscribeEvent
def replaceSnowballWithArrow(event: EntityJoinWorldEvent) {
val entity = event.entity
val world = entity.worldObj
entity match {
case snowball: EntitySnowball if ! world.isRemote =>
-2 to 2 foreach(xOff => {
-2 to 2 foreach (yOff => {
world.spawnEntityInWorld(makeArrow(world, snowball, xOff, yOff))
})
})
snowball.setDead()
case _ =>
}
}
private def makeArrow(world: World, snowball: EntitySnowball, xOff: Int, yOff: Int) =
new EntityArrow(world) {
setLocationAndAngles(snowball.posX + xOff, snowball.posY + yOff, snowball.posZ, 0, 0)
motionX = snowball.motionX
motionY = snowball.motionY
motionZ = snowball.motionZ
}
}
@dcbriccetti
Copy link
Author

Say, feel free to type in the code to make the arrow translations work no matter what the player orientation. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment