diff --git a/src/dark/core/common/PlayerKeyHandler.java b/src/dark/core/common/PlayerKeyHandler.java index 609ef388..7cbc2433 100644 --- a/src/dark/core/common/PlayerKeyHandler.java +++ b/src/dark/core/common/PlayerKeyHandler.java @@ -13,6 +13,7 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler; +import cpw.mods.fml.common.IScheduledTickHandler; import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; import dark.core.network.PacketManagerKeyEvent; @@ -20,10 +21,8 @@ import dark.core.network.PacketManagerKeyEvent; /** This class handles keys already binded to the game so to avoid creating new key bindings * * @author DarkGuardsman */ -public class PlayerKeyHandler implements ITickHandler +public class PlayerKeyHandler implements IScheduledTickHandler { - protected boolean[] keyDown; - protected boolean[] repeatings; @Override public final void tickStart(EnumSet type, Object... tickData) @@ -62,4 +61,10 @@ public class PlayerKeyHandler implements ITickHandler { return "[CoreMachine]KeyBindingCatcher"; } + + @Override + public int nextTickSpacing() + { + return 2; + } } diff --git a/src/dark/core/network/PacketManagerKeyEvent.java b/src/dark/core/network/PacketManagerKeyEvent.java index 5fbc4145..18bea4f1 100644 --- a/src/dark/core/network/PacketManagerKeyEvent.java +++ b/src/dark/core/network/PacketManagerKeyEvent.java @@ -66,7 +66,7 @@ public class PacketManagerKeyEvent implements IPacketManager try { int key = data.readInt(); - for (IControlReceiver receiver : receivers) + for (IControlReceiver receiver : instance().receivers) { receiver.keyTyped((EntityPlayer) player, key); } diff --git a/src/dark/core/prefab/ModPrefab.java b/src/dark/core/prefab/ModPrefab.java index 3454e021..766a079a 100644 --- a/src/dark/core/prefab/ModPrefab.java +++ b/src/dark/core/prefab/ModPrefab.java @@ -106,7 +106,7 @@ public abstract class ModPrefab MinecraftForge.EVENT_BUS.register(new FluidHelper()); MinecraftForge.EVENT_BUS.register(SaveManager.instance()); TickRegistry.registerTickHandler(NetworkUpdateHandler.instance(), Side.SERVER); - TickRegistry.registerTickHandler(new PlayerKeyHandler(), Side.CLIENT); + TickRegistry.registerScheduledTickHandler(new PlayerKeyHandler(), Side.CLIENT); UniversalElectricity.initiate(); Compatibility.initiate(); preInit = true; diff --git a/src/dark/core/prefab/vehicles/EntityDrivable.java b/src/dark/core/prefab/vehicles/EntityDrivable.java index 04ed1faf..129f96be 100644 --- a/src/dark/core/prefab/vehicles/EntityDrivable.java +++ b/src/dark/core/prefab/vehicles/EntityDrivable.java @@ -4,9 +4,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.DamageSource; import net.minecraft.world.World; import cpw.mods.fml.client.FMLClientHandler; +import dark.core.helpers.MathHelper; import dark.core.interfaces.IControlReceiver; import dark.core.network.PacketManagerKeyEvent; import dark.core.prefab.EntityAdvanced; @@ -38,11 +40,13 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver @Override public boolean keyTyped(EntityPlayer player, int keycode) { - if (this.ridingEntity != null && this.ridingEntity.equals(player)) + System.out.println("Key: "+keycode+" P: " + (player != null ? player.username : "null")); + if (player != null && this.riddenByEntity instanceof EntityPlayer && ((EntityPlayer) this.riddenByEntity).username.equalsIgnoreCase(player.username)) { //TODO add auto forward and backwards keys like those in WoT if (keycode == Minecraft.getMinecraft().gameSettings.keyBindForward.keyCode) { + player.sendChatToPlayer(ChatMessageComponent.createFromText("Forward we go!")); this.accelerate(true); } if (keycode == Minecraft.getMinecraft().gameSettings.keyBindBack.keyCode) @@ -51,11 +55,11 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver } if (keycode == Minecraft.getMinecraft().gameSettings.keyBindLeft.keyCode) { - this.rotationYaw += 5; + this.rotationYaw += 6; } if (keycode == Minecraft.getMinecraft().gameSettings.keyBindRight.keyCode) { - this.rotationYaw -= 5; + this.rotationYaw -= 6; } //Power brakes if (keycode == Minecraft.getMinecraft().gameSettings.keyBindJump.keyCode) @@ -92,17 +96,59 @@ public class EntityDrivable extends EntityAdvanced implements IControlReceiver this.worldObj.spawnParticle("mobSpell", this.posX, this.posY, this.posZ, 0, 0, 0); } + if (this.worldObj.isRemote && (this.riddenByEntity == null || !(this.riddenByEntity instanceof EntityPlayer) || !FMLClientHandler.instance().getClient().thePlayer.equals(this.riddenByEntity))) + { + double x, y, z; + if (this.boatPosRotationIncrements > 0) + { + x = this.posX + (this.boatX - this.posX) / this.boatPosRotationIncrements; + y = this.posY + (this.boatY - this.posY) / this.boatPosRotationIncrements; + z = this.posZ + (this.boatZ - this.posZ) / this.boatPosRotationIncrements; + + this.rotationYaw = (float) (this.rotationYaw + MathHelper.wrapAngleTo180_double(this.boatYaw - this.rotationYaw) / this.boatPosRotationIncrements); + this.rotationPitch = (float) (this.rotationPitch + (this.boatPitch - this.rotationPitch) / this.boatPosRotationIncrements); + --this.boatPosRotationIncrements; + this.setPosition(x, y, z); + this.setRotation(this.rotationYaw, this.rotationPitch); + } + else + { + x = this.posX + this.motionX; + y = this.posY + this.motionY; + z = this.posZ + this.motionZ; + if (this.riddenByEntity != null) + { + this.setPosition(x, y, z); + } + + if (this.onGround) + { + this.motionX *= 0.5D; + this.motionY *= 0.5D; + this.motionZ *= 0.5D; + } + + this.motionX *= 0.9900000095367432D; + this.motionY *= 0.949999988079071D; + this.motionZ *= 0.9900000095367432D; + } + return; + } + if (this.isCollidedHorizontally) { + this.speed *= 0.9; this.motionY = 0.1D; } + if (this.worldObj.isRemote) + { + this.motionX = -(this.speed * Math.cos((this.rotationYaw - 90F) * Math.PI / 180.0D)); + this.motionZ = -(this.speed * Math.sin((this.rotationYaw - 90F) * Math.PI / 180.0D)); + this.moveEntity(this.motionX, this.motionY, this.motionZ); + } + this.applyFriction(); - - this.motionX = -(this.speed * Math.cos((this.rotationYaw - 90F) * Math.PI / 180.0D)); - this.motionZ = -(this.speed * Math.sin((this.rotationYaw - 90F) * Math.PI / 180.0D)); - this.moveEntity(this.motionX, this.motionY, this.motionZ); - if (this.speed > this.maxSpeed) { this.speed = this.maxSpeed;