Advertisement
wiresegal

Untitled

Apr 14th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 3.99 KB | None | 0 0
  1. package command.items
  2.  
  3. import com.teamwizardry.librarianlib.features.base.ModCreativeTab
  4. import com.teamwizardry.librarianlib.features.base.item.ItemMod
  5. import com.teamwizardry.librarianlib.features.helpers.ItemNBTHelper
  6. import net.minecraft.entity.Entity
  7. import net.minecraft.entity.player.EntityPlayer
  8. import net.minecraft.init.SoundEvents
  9. import net.minecraft.item.ItemStack
  10. import net.minecraft.util.*
  11. import net.minecraft.util.text.TextComponentTranslation
  12. import net.minecraft.world.World
  13. import net.minecraftforge.fml.common.Mod
  14. import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
  15.  
  16. /**
  17.  * @author WireSegal
  18.  * Created at 5:30 PM on 4/14/17.
  19.  */
  20. @Mod(modid = "commanditem", name = "Modoff Items", version = "1.0", acceptedMinecraftVersions = "[1.11,)", dependencies = "required-after:librarianlib")
  21. class ThisIsAModWhatMoreDoYouWantFromMeMan {
  22.     companion object {
  23.         lateinit var toggleItem: ItemMod
  24.         lateinit var teleportItem: ItemMod
  25.         lateinit var tab: ModCreativeTab
  26.     }
  27.  
  28.     @Mod.EventHandler
  29.     fun preInit(e: FMLPreInitializationEvent) {
  30.         tab = TheTab()
  31.  
  32.         toggleItem = ToggleItem()
  33.         teleportItem = TeleportItem()
  34.     }
  35.  
  36.     class TheTab : ModCreativeTab() {
  37.         init {
  38.             registerDefaultTab()
  39.         }
  40.  
  41.         override val iconStack: ItemStack by lazy {
  42.             ItemStack(toggleItem)
  43.         }
  44.     }
  45.  
  46.     class ToggleItem : ItemMod("toggle", "toggle") {
  47.         init {
  48.             addPropertyOverride(ResourceLocation("on")) { stack, _, entityIn ->
  49.                 if (entityIn == null) 0f else if (ItemNBTHelper.getBoolean(stack, "roadspeed", false)) 1f else 0f
  50.             }
  51.             maxStackSize = 1
  52.             tab.set(this)
  53.         }
  54.  
  55.         override fun onUpdate(stack: ItemStack, worldIn: World, entityIn: Entity, itemSlot: Int, isSelected: Boolean) {
  56.             if (!worldIn.isRemote) ItemNBTHelper.setBoolean(stack, "roadspeed", entityIn.tags.contains("roadspeed"))
  57.         }
  58.  
  59.         override fun onItemRightClick(worldIn: World, playerIn: EntityPlayer, handIn: EnumHand): ActionResult<ItemStack> {
  60.             if (playerIn.isSneaking && !playerIn.world.isRemote) {
  61.                 val tag = playerIn.tags.contains("roadspeed")
  62.                 playerIn.world.playSound(null, playerIn.position, SoundEvents.ENTITY_ARROW_HIT_PLAYER, SoundCategory.PLAYERS, 1f, 1f)
  63.                 if (tag) {
  64.                     playerIn.sendStatusMessage(TextComponentTranslation("commanditem.turnedoff"), true)
  65.                     playerIn.removeTag("roadspeed")
  66.                 } else {
  67.                     playerIn.sendStatusMessage(TextComponentTranslation("commanditem.turnedon"), true)
  68.                     playerIn.addTag("roadspeed")
  69.                 }
  70.                 playerIn.cooldownTracker.setCooldown(this, 5)
  71.             }
  72.             return ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn))
  73.         }
  74.     }
  75.  
  76.     class TeleportItem : ItemMod("teleport", "plot", "stage", "spawn") {
  77.         init {
  78.             maxStackSize = 1
  79.         }
  80.  
  81.         override fun onItemRightClick(worldIn: World, playerIn: EntityPlayer, handIn: EnumHand): ActionResult<ItemStack> {
  82.             val stack = playerIn.getHeldItem(handIn)
  83.             if (!worldIn.isRemote) {
  84.                 if (playerIn.isSneaking) {
  85.                     playerIn.world.playSound(null, playerIn.position, SoundEvents.ENTITY_ARROW_HIT_PLAYER, SoundCategory.PLAYERS, 1f, 1f)
  86.                     stack.itemDamage = (stack.itemDamage + 1) % variants.size
  87.                 } else when (stack.itemDamage) {
  88.                     0 -> playerIn.setPositionAndUpdate(-11.5, 34.5, -20.5)
  89.                     1 -> playerIn.setPositionAndUpdate(1009.5, 96.5, -1016.5)
  90.                     2 -> playerIn.setPositionAndUpdate(-999.5, 12.5, 1000.5)
  91.                 }
  92.                 playerIn.cooldownTracker.setCooldown(this, 5)
  93.             }
  94.             return ActionResult(EnumActionResult.SUCCESS, stack)
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement