Skip to content

Instantly share code, notes, and snippets.

@yrsegal
Created January 22, 2018 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yrsegal/3d90ba3e16331f6ee540c313f8e31e60 to your computer and use it in GitHub Desktop.
Save yrsegal/3d90ba3e16331f6ee540c313f8e31e60 to your computer and use it in GitHub Desktop.
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 com.teamwizardry.librarianlib.features.helpers.nonnullListOf
import com.teamwizardry.librarianlib.features.kotlin.nbt
import com.teamwizardry.librarianlib.features.utilities.client.TooltipHelper
import net.minecraft.entity.Entity
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.init.Items
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.2", 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() {
override val iconStack: ItemStack by lazy {
ItemStack(toggleItem).apply { this.nbt["roadspeed"] = true }
}
}
class ToggleItem : ItemMod("toggle") {
init {
addPropertyOverride(ResourceLocation("on")) { stack, _, entityIn ->
if (entityIn == null) 0f else if (ItemNBTHelper.getBoolean(stack, "roadspeed", false)) 1f else 0f
}
maxStackSize = 1
}
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 addInformation(stack: ItemStack, playerIn: EntityPlayer?, tooltip: MutableList<String>, advanced: Boolean) {
val unloc = stack.unlocalizedName
TooltipHelper.addToTooltip(tooltip, unloc + ".desc")
TooltipHelper.addToTooltip(tooltip, unloc + ".desc1", TooltipHelper.local(unloc + if (ItemNBTHelper.getBoolean(stack, "roadspeed", false)) ".on" else ".off"))
}
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", "creative") {
init {
maxStackSize = 1
}
override fun addInformation(stack: ItemStack, playerIn: EntityPlayer?, tooltip: MutableList<String>, advanced: Boolean) {
val unloc = ItemStack(this, 1, variants.size).unlocalizedName
TooltipHelper.addToTooltip(tooltip, unloc + ".desc")
TooltipHelper.addToTooltip(tooltip, unloc + ".desc1")
}
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 {
if (playerIn.isRiding)
playerIn.dismountRidingEntity()
if (playerIn.isBeingRidden)
playerIn.passengers.forEach(Entity::dismountRidingEntity)
if (playerIn.dimension != 0) playerIn.changeDimension(0)
when (stack.itemDamage) {
0 -> {
playerIn.rotationYaw = 0f
playerIn.rotationPitch = 0f
playerIn.setPositionAndUpdate(-11.5, 34.5, -20.5)
}
1 -> {
playerIn.rotationYaw = -180f
playerIn.rotationPitch = 0f
playerIn.setPositionAndUpdate(1009.5, 96.5, 1016.5)
}
2 -> {
playerIn.rotationYaw = -180f
playerIn.rotationPitch = -25f
playerIn.setPositionAndUpdate(-999.5, 12.5, 1000.5)
}
3 -> {
playerIn.rotationYaw = -90f
playerIn.rotationPitch = 10f
playerIn.setPositionAndUpdate(-999.5, 16.5, -999.5)
}
}
}
playerIn.cooldownTracker.setCooldown(this, 5)
}
return ActionResult(EnumActionResult.SUCCESS, stack)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment