Last active
August 29, 2015 14:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Say, feel free to type in the code to make the arrow translations work no matter what the player orientation. :-)