2013-05-20 17:09:57 +10:00
|
|
|
package codechicken.multipart
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler
|
|
|
|
|
import net.minecraft.client.settings.KeyBinding
|
|
|
|
|
import org.lwjgl.input.Keyboard
|
|
|
|
|
import cpw.mods.fml.common.registry.LanguageRegistry
|
|
|
|
|
import java.util.EnumSet
|
|
|
|
|
import cpw.mods.fml.common.TickType
|
|
|
|
|
import net.minecraft.client.Minecraft
|
2013-07-24 15:32:46 +10:00
|
|
|
import codechicken.lib.packet.PacketCustom
|
2013-05-20 17:09:57 +10:00
|
|
|
import codechicken.multipart.handler.MultipartCPH
|
|
|
|
|
import scala.collection.mutable.HashMap
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer
|
|
|
|
|
|
2013-09-25 12:56:40 +10:00
|
|
|
/**
|
|
|
|
|
* A class that maintains a map server<->client of which players are holding the control (or placement modifier key) much like sneaking.
|
|
|
|
|
*/
|
2013-05-20 17:09:57 +10:00
|
|
|
object ControlKeyModifer
|
|
|
|
|
{
|
|
|
|
|
implicit def playerControlValue(p:EntityPlayer) = new ControlKeyValue(p)
|
|
|
|
|
|
|
|
|
|
class ControlKeyValue(p:EntityPlayer)
|
|
|
|
|
{
|
|
|
|
|
def isControlDown() = map(p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val map = HashMap[EntityPlayer, Boolean]().withDefaultValue(false)
|
2013-09-25 12:56:40 +10:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implicit static for Java users.
|
|
|
|
|
*/
|
|
|
|
|
def isControlDown(p:EntityPlayer) = p.isControlDown
|
2013-05-20 17:09:57 +10:00
|
|
|
}
|
|
|
|
|
|
2013-09-25 12:56:40 +10:00
|
|
|
/**
|
|
|
|
|
* Key Handler implementation
|
|
|
|
|
*/
|
2013-05-20 17:09:57 +10:00
|
|
|
object ControlKeyHandler extends KeyHandler (
|
|
|
|
|
Array(new KeyBinding("key.control", Keyboard.KEY_LCONTROL)),
|
|
|
|
|
Array(false))
|
|
|
|
|
{
|
|
|
|
|
import ControlKeyModifer._
|
|
|
|
|
|
|
|
|
|
LanguageRegistry.instance.addStringLocalization("key.control", "Placement Modifier");
|
|
|
|
|
|
|
|
|
|
def keyDown(types:EnumSet[TickType], kb:KeyBinding, tickEnd:Boolean, isRepeat:Boolean)
|
|
|
|
|
{
|
|
|
|
|
if(!tickEnd && Minecraft.getMinecraft.getNetHandler != null)
|
|
|
|
|
{
|
|
|
|
|
map.put(Minecraft.getMinecraft.thePlayer, true)
|
|
|
|
|
val packet = new PacketCustom(MultipartCPH.channel, 1)
|
|
|
|
|
packet.writeBoolean(true)
|
|
|
|
|
packet.sendToServer()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def keyUp(types:EnumSet[TickType], kb:KeyBinding, tickEnd:Boolean)
|
|
|
|
|
{
|
|
|
|
|
if(!tickEnd && Minecraft.getMinecraft.getNetHandler != null)
|
|
|
|
|
{
|
|
|
|
|
map.put(Minecraft.getMinecraft.thePlayer, false)
|
|
|
|
|
val packet = new PacketCustom(MultipartCPH.channel, 1)
|
|
|
|
|
packet.writeBoolean(false)
|
|
|
|
|
packet.sendToServer()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getLabel() = "Control Key Modifer";
|
|
|
|
|
|
|
|
|
|
def ticks() = EnumSet.of(TickType.CLIENT)
|
|
|
|
|
}
|