Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package command.items
- import com.teamwizardry.librarianlib.features.base.ModCreativeTab
- import com.teamwizardry.librarianlib.features.base.item.ItemMod
- import com.teamwizardry.librarianlib.features.helpers.ItemNBTHelper
- import net.minecraft.entity.Entity
- import net.minecraft.entity.player.EntityPlayer
- import net.minecraft.init.SoundEvents
- import net.minecraft.item.ItemStack
- import net.minecraft.util.*
- import net.minecraft.util.text.TextComponentTranslation
- import net.minecraft.world.World
- import net.minecraftforge.fml.common.Mod
- import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
- /**
- * @author WireSegal
- * Created at 5:30 PM on 4/14/17.
- */
- @Mod(modid = "commanditem", name = "Modoff Items", version = "1.0", acceptedMinecraftVersions = "[1.11,)", dependencies = "required-after:librarianlib")
- class ThisIsAModWhatMoreDoYouWantFromMeMan {
- companion object {
- lateinit var toggleItem: ItemMod
- lateinit var teleportItem: ItemMod
- lateinit var tab: ModCreativeTab
- }
- @Mod.EventHandler
- fun preInit(e: FMLPreInitializationEvent) {
- tab = TheTab()
- toggleItem = ToggleItem()
- teleportItem = TeleportItem()
- }
- class TheTab : ModCreativeTab() {
- init {
- registerDefaultTab()
- }
- override val iconStack: ItemStack by lazy {
- ItemStack(toggleItem)
- }
- }
- class ToggleItem : ItemMod("toggle", "toggle") {
- init {
- addPropertyOverride(ResourceLocation("on")) { stack, _, entityIn ->
- if (entityIn == null) 0f else if (ItemNBTHelper.getBoolean(stack, "roadspeed", false)) 1f else 0f
- }
- maxStackSize = 1
- tab.set(this)
- }
- override fun onUpdate(stack: ItemStack, worldIn: World, entityIn: Entity, itemSlot: Int, isSelected: Boolean) {
- if (!worldIn.isRemote) ItemNBTHelper.setBoolean(stack, "roadspeed", entityIn.tags.contains("roadspeed"))
- }
- override fun onItemRightClick(worldIn: World, playerIn: EntityPlayer, handIn: EnumHand): ActionResult<ItemStack> {
- if (playerIn.isSneaking && !playerIn.world.isRemote) {
- val tag = playerIn.tags.contains("roadspeed")
- playerIn.world.playSound(null, playerIn.position, SoundEvents.ENTITY_ARROW_HIT_PLAYER, SoundCategory.PLAYERS, 1f, 1f)
- if (tag) {
- playerIn.sendStatusMessage(TextComponentTranslation("commanditem.turnedoff"), true)
- playerIn.removeTag("roadspeed")
- } else {
- playerIn.sendStatusMessage(TextComponentTranslation("commanditem.turnedon"), true)
- playerIn.addTag("roadspeed")
- }
- playerIn.cooldownTracker.setCooldown(this, 5)
- }
- return ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn))
- }
- }
- class TeleportItem : ItemMod("teleport", "plot", "stage", "spawn") {
- init {
- maxStackSize = 1
- }
- override fun onItemRightClick(worldIn: World, playerIn: EntityPlayer, handIn: EnumHand): ActionResult<ItemStack> {
- val stack = playerIn.getHeldItem(handIn)
- if (!worldIn.isRemote) {
- if (playerIn.isSneaking) {
- playerIn.world.playSound(null, playerIn.position, SoundEvents.ENTITY_ARROW_HIT_PLAYER, SoundCategory.PLAYERS, 1f, 1f)
- stack.itemDamage = (stack.itemDamage + 1) % variants.size
- } else when (stack.itemDamage) {
- 0 -> playerIn.setPositionAndUpdate(-11.5, 34.5, -20.5)
- 1 -> playerIn.setPositionAndUpdate(1009.5, 96.5, -1016.5)
- 2 -> playerIn.setPositionAndUpdate(-999.5, 12.5, 1000.5)
- }
- playerIn.cooldownTracker.setCooldown(this, 5)
- }
- return ActionResult(EnumActionResult.SUCCESS, stack)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement