Hey there!
I'm pretty new to modding in minecraft ( I have some experience with lua ):
I'm trying to make a Jetpack like mod/script which makes my player fly up (addVelocity 0,0.075,0) which worked pretty good using a keybind.
Problem is when I fall down, or jump of a tree and thrust up so I land on the ground with almost no speed I still get tons of damage.
I tried setting fallDistance to 0 while I hold the key and when I release the key which had (I think) no effect. I've set fallDistance clientside, which is in my guess the problem. But since I just started modding and have no idea (and searched a long while to find out how to do binds) I don't know how to set it serverside.
I'm just gonna give you the code I wrote in the proxy:
Base File: chatbinds.common.Chatbinds.java
package chatbinds.common;
import net.minecraft.src.BaseMod;
import net.minecraft.src.ModLoader;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
@Mod(modid = "dt855_chatbinds", name = "Chatbinds", version = "0.1")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Chatbinds
{
@SidedProxy(clientSide="chatbinds.client.ClientProxy", serverSide="chatbinds.common.CommonProxy")
public static CommonProxy proxy;
@Init
public void load(FMLInitializationEvent event)
{
proxy.registerKeybinds();
}
}
chatbinds.client.ClientProxy.java
package chatbinds.client;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
import net.minecraft.client.settings.KeyBinding;
import chatbinds.common.CommonProxy;
public class ClientProxy extends CommonProxy
{
@Override
public void registerKeybinds()
{
KeyBindingRegistry.registerKeyBinding(new MyKeyHandlerFly());
}
}
chatbinds.client.MyKeyHandlerFly.java
package chatbinds.client;
import java.util.EnumSet;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.src.ModLoader;
import org.lwjgl.input.Keyboard;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;
public class MyKeyHandlerFly extends KeyHandler {
static KeyBinding myBinding = new KeyBinding("Jetpack", Keyboard.KEY_T);
public MyKeyHandlerFly() {
//the first value is an array of KeyBindings, the second is whether or not the call
//keyDown should repeat as long as the key is down
super(new KeyBinding[]{myBinding}, new boolean[]{true});
}
@Override
public String getLabel() {
return "mykeybindings";
}
@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb,
boolean tickEnd, boolean isRepeat) {
if (FMLClientHandler.instance().getClient().currentScreen == null) {
EntityClientPlayerMP localPlayer = ModLoader.getMinecraftInstance().thePlayer;
localPlayer.addVelocity(0,0.075,0);
localPlayer.fallDistance = 0;
}
}
@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {
//do whatever
EntityClientPlayerMP localPlayer = ModLoader.getMinecraftInstance().thePlayer;
localPlayer.fallDistance = 0;
}
@Override
public EnumSet<TickType> ticks() {
return EnumSet.of(TickType.CLIENT);
//I am unsure if any different TickTypes have any different effects.
}
}
Serverside Proxy: chatbinds.common.CommonProxy.java
package chatbinds.common;
import chatbinds.client.MyKeyHandler;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
public class CommonProxy {
public void registerKeybinds()
{
}
}
P.S.: I have no idea what I'm doing, I followed some tutorials and searched around the web to find parts and put everything together. So if you have a solution for my problem I'd be very appreciated if you could describe what the code means.