mirror of
https://github.com/chylex/Better-Sprinting.git
synced 2025-04-09 18:15:41 +02:00
Second part of the rewrite \o/ beginning of packets
This commit is contained in:
parent
2b7dc2651b
commit
3aa7bd5748
src/main/java/chylex/bettersprinting
BetterSprintingConfig.java
client
server
system
@ -3,6 +3,7 @@ import java.io.File;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class BetterSprintingConfig{
|
||||
@ -10,6 +11,7 @@ public class BetterSprintingConfig{
|
||||
private String currentCategory = "unknown";
|
||||
|
||||
BetterSprintingConfig(File file){
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
config = new Configuration(file);
|
||||
reload();
|
||||
}
|
||||
@ -39,4 +41,12 @@ public class BetterSprintingConfig{
|
||||
public Property getInt(String name, int defValue, String comment){
|
||||
return config.get(currentCategory,name,defValue,comment);
|
||||
}
|
||||
|
||||
public void setBool(String name, boolean value){
|
||||
config.get(currentCategory,name,value).set(value);
|
||||
}
|
||||
|
||||
public void setInt(String name, int value){
|
||||
config.get(currentCategory,name,value).set(value);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,17 @@
|
||||
package chylex.bettersprinting.client;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiControls;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
|
||||
import chylex.bettersprinting.BetterSprintingMod;
|
||||
import chylex.bettersprinting.client.compatibility.OldNotificationPacket;
|
||||
import chylex.bettersprinting.client.gui.GuiControlsCustom;
|
||||
import chylex.bettersprinting.client.update.UpdateThread;
|
||||
import chylex.bettersprinting.system.PacketPipeline;
|
||||
|
||||
public final class ClientEventHandler{
|
||||
public static void register(){
|
||||
@ -28,6 +32,20 @@ public final class ClientEventHandler{
|
||||
new UpdateThread(BetterSprintingMod.modVersion).start();
|
||||
}
|
||||
}
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
if (!mc.isIntegratedServerRunning() && mc.getCurrentServerData() != null && !ClientSettings.disableMod){
|
||||
ClientModManager.svFlyingBoost = ClientModManager.svRunInAllDirs = false;
|
||||
PacketPipeline.sendToServer(ClientNetwork.writeModNotification());
|
||||
OldNotificationPacket.sendServerNotification();
|
||||
}
|
||||
else ClientModManager.svFlyingBoost = ClientModManager.svRunInAllDirs = true;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLoggedOut(PlayerLoggedOutEvent e){
|
||||
ClientModManager.svFlyingBoost = ClientModManager.svRunInAllDirs = false;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -0,0 +1,19 @@
|
||||
package chylex.bettersprinting.client;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import chylex.bettersprinting.system.PacketPipeline;
|
||||
import chylex.bettersprinting.system.PacketPipeline.INetworkHandler;
|
||||
|
||||
public class ClientNetwork implements INetworkHandler{
|
||||
public static PacketBuffer writeModNotification(){
|
||||
PacketBuffer buffer = PacketPipeline.buf();
|
||||
buffer.writeByte(0);
|
||||
buffer.writeByte(10);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacket(Side side, ByteBuf data, EntityPlayer player){}
|
||||
}
|
@ -9,16 +9,18 @@ import api.player.client.ClientPlayerAPI;
|
||||
import chylex.bettersprinting.BetterSprintingConfig;
|
||||
import chylex.bettersprinting.BetterSprintingProxy;
|
||||
import chylex.bettersprinting.client.player.PlayerBase;
|
||||
import chylex.bettersprinting.system.PacketPipeline;
|
||||
|
||||
public class ClientProxy extends BetterSprintingProxy{
|
||||
@Override
|
||||
public void loadSidedConfig(BetterSprintingConfig config){
|
||||
ClientSettings.load(config);
|
||||
ClientSettings.refresh(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreInit(FMLPreInitializationEvent e){
|
||||
ClientEventHandler.register();
|
||||
PacketPipeline.initialize(new ClientNetwork());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,7 +6,7 @@ public class ClientSettings{
|
||||
public static int keyCodeSprintHold = 29;
|
||||
public static int keyCodeSprintToggle = 34;
|
||||
public static int keyCodeSneakToggle = 21;
|
||||
public static int keyCodeSprintMenu = 24;
|
||||
public static int keyCodeOptionsMenu = 24;
|
||||
|
||||
public static byte flySpeedBoost = 3;
|
||||
public static boolean enableDoubleTap = false;
|
||||
@ -15,18 +15,31 @@ public class ClientSettings{
|
||||
|
||||
public static boolean enableUpdateNotifications = true;
|
||||
public static boolean enableBuildCheck = true;
|
||||
|
||||
public static boolean showedSneakWarning = false;
|
||||
|
||||
public static void load(BetterSprintingConfig config){
|
||||
public static void refresh(BetterSprintingConfig config){
|
||||
config.setCategory("client");
|
||||
OldClientConfig.loadAndDeleteOldConfig();
|
||||
|
||||
// TODO load
|
||||
keyCodeSprintHold = config.getInt("keySprintHold",keyCodeSprintHold,"").setShowInGui(false).getInt();
|
||||
keyCodeSprintToggle = config.getInt("keySprintToggle",keyCodeSprintToggle,"").setShowInGui(false).getInt();
|
||||
keyCodeSneakToggle = config.getInt("keySneakToggle",keyCodeSneakToggle,"").setShowInGui(false).getInt();
|
||||
keyCodeOptionsMenu = config.getInt("keyOptionsMenu",keyCodeOptionsMenu,"").setShowInGui(false).getInt();
|
||||
|
||||
flySpeedBoost = (byte)config.getInt("flySpeedBoost",flySpeedBoost,"").setShowInGui(false).getInt();
|
||||
enableDoubleTap = config.getBool("enableDoubleTap",enableDoubleTap,"").setShowInGui(false).getBoolean();
|
||||
enableAllDirs = config.getBool("enableAllDirs",enableAllDirs,"").setShowInGui(false).getBoolean();
|
||||
disableMod = config.getBool("disableMod",disableMod,"").setShowInGui(false).getBoolean();
|
||||
|
||||
enableUpdateNotifications = config.getBool("enableUpdateNotifications",enableUpdateNotifications,"").getBoolean();
|
||||
enableBuildCheck = config.getBool("enableBuildCheck",enableBuildCheck,"").getBoolean();
|
||||
showedSneakWarning = config.getBool("showedSneakWarning",showedSneakWarning,"").setShowInGui(false).getBoolean();
|
||||
|
||||
ClientModManager.keyBindSprintHold.setKeyCode(keyCodeSprintHold);
|
||||
ClientModManager.keyBindSprintToggle.setKeyCode(keyCodeSprintToggle);
|
||||
ClientModManager.keyBindSneakToggle.setKeyCode(keyCodeSneakToggle);
|
||||
ClientModManager.keyBindSprintMenu.setKeyCode(keyCodeSprintMenu);
|
||||
ClientModManager.keyBindSprintMenu.setKeyCode(keyCodeOptionsMenu);
|
||||
|
||||
config.forceSave();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
package chylex.bettersprinting.client.compatibility;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@ -16,7 +15,7 @@ public class OldClientConfig{
|
||||
try{
|
||||
NBTTagCompound tag = CompressedStreamTools.readCompressed(new FileInputStream(file)).getCompoundTag("Data");
|
||||
|
||||
ClientSettings.keyCodeSprintMenu = tag.getInteger("keyMenu");
|
||||
ClientSettings.keyCodeOptionsMenu = tag.getInteger("keyMenu");
|
||||
ClientSettings.keyCodeSprintHold = tag.getInteger("keySprint");
|
||||
ClientSettings.keyCodeSprintToggle = tag.getInteger("keySprintToggle");
|
||||
ClientSettings.keyCodeSneakToggle = tag.getInteger("keySneakToggle");
|
||||
|
@ -0,0 +1,13 @@
|
||||
package chylex.bettersprinting.client.compatibility;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.client.C17PacketCustomPayload;
|
||||
|
||||
public class OldNotificationPacket{
|
||||
public static void sendServerNotification(){
|
||||
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
|
||||
buffer.writeByte(5);
|
||||
Minecraft.getMinecraft().thePlayer.sendQueue.addToSendQueue(new C17PacketCustomPayload("BSprint",buffer));
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ public class GuiControlsCustom extends GuiControls{
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException{
|
||||
if (button.id==205)mc.displayGuiScreen(new GuiSprint(this));
|
||||
if (button.id == 205)mc.displayGuiScreen(new GuiSprint(this));
|
||||
else super.actionPerformed(button);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import chylex.bettersprinting.client.ClientModManager;
|
||||
import chylex.bettersprinting.client.ClientSettings;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiSprint extends GuiScreen{
|
||||
@ -17,7 +18,7 @@ public class GuiSprint extends GuiScreen{
|
||||
private int buttonId = -1;
|
||||
private GuiButton btnDoubleTap,btnFlyBoost,btnAllDirs,btnDisableMod,btnUpdateNotifications;
|
||||
protected KeyBinding[] sprintBindings = new KeyBinding[]{
|
||||
ClientModManager.keyBindSprint, ClientModManager.keyBindSprintToggle, ClientModManager.keyBindSneakToggle, ClientModManager.keyBindSprintMenu
|
||||
ClientModManager.keyBindSprintHold, ClientModManager.keyBindSprintToggle, ClientModManager.keyBindSneakToggle, ClientModManager.keyBindSprintMenu
|
||||
};
|
||||
|
||||
public GuiSprint(GuiScreen parentScreen){
|
||||
@ -35,12 +36,12 @@ public class GuiSprint extends GuiScreen{
|
||||
ypos=height/6+24*(a>>1);
|
||||
GuiOptionButton btn=new GuiOptionButton(a,left+a%2*160,ypos,70,20,getKeyCodeString(a));
|
||||
buttonList.add(btn);
|
||||
if ((a==1||a==2)&&ClientModManager.disableModFunctionality)btn.enabled=false;
|
||||
if ((a==1||a==2)&&ClientSettings.disableMod)btn.enabled=false;
|
||||
}
|
||||
|
||||
ypos+=48;
|
||||
btnDoubleTap=new GuiButton(199,left,ypos,70,20,""); buttonList.add(btnDoubleTap);
|
||||
if (ClientModManager.disableModFunctionality)btnDoubleTap.enabled=false;
|
||||
if (ClientSettings.disableMod)btnDoubleTap.enabled=false;
|
||||
|
||||
btnAllDirs=new GuiButton(198,left+160,ypos,70,20,""); buttonList.add(btnAllDirs);
|
||||
if (!ClientModManager.canRunInAllDirs(mc))btnAllDirs.enabled=false;
|
||||
@ -61,10 +62,10 @@ public class GuiSprint extends GuiScreen{
|
||||
}
|
||||
|
||||
private void updateButtons(){
|
||||
btnDoubleTap.displayString=ClientModManager.disableModFunctionality?"Unavailable":(ClientModManager.allowDoubleTap?"Enabled":"Disabled");
|
||||
btnDoubleTap.displayString=ClientSettings.disableMod?"Unavailable":(ClientModManager.allowDoubleTap?"Enabled":"Disabled");
|
||||
btnFlyBoost.displayString=ClientModManager.canBoostFlying(mc)?(ClientModManager.flyingBoost==0?"Disabled":(ClientModManager.flyingBoost+1)+"x"):"Unavailable";
|
||||
btnAllDirs.displayString=ClientModManager.canRunInAllDirs(mc)?(ClientModManager.allowAllDirs?"Enabled":"Disabled"):"Unavailable";
|
||||
btnDisableMod.displayString=ClientModManager.disableModFunctionality?"Yes":"No";
|
||||
btnDisableMod.displayString=ClientSettings.disableMod?"Yes":"No";
|
||||
btnUpdateNotifications.displayString=ClientModManager.enableUpdateNotifications?"Yes":"No";
|
||||
}
|
||||
|
||||
@ -86,7 +87,7 @@ public class GuiSprint extends GuiScreen{
|
||||
|
||||
case 196:
|
||||
if (mc.thePlayer==null&&mc.theWorld==null){
|
||||
ClientModManager.disableModFunctionality=!ClientModManager.disableModFunctionality;
|
||||
ClientSettings.disableMod=!ClientSettings.disableMod;
|
||||
initGui();
|
||||
}
|
||||
break;
|
||||
@ -100,7 +101,7 @@ public class GuiSprint extends GuiScreen{
|
||||
break;
|
||||
|
||||
case 199:
|
||||
if (!ClientModManager.disableModFunctionality)ClientModManager.allowDoubleTap=!ClientModManager.allowDoubleTap;
|
||||
if (!ClientSettings.disableMod)ClientModManager.allowDoubleTap=!ClientModManager.allowDoubleTap;
|
||||
break;
|
||||
|
||||
case 200:
|
||||
|
@ -3,6 +3,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.util.MovementInputFromOptions;
|
||||
import chylex.bettersprinting.client.ClientModManager;
|
||||
import chylex.bettersprinting.client.ClientSettings;
|
||||
|
||||
public class CustomMovementInput{
|
||||
public boolean sprint, sprintToggle, sneakToggle, hasToggledSprint, hasToggledSneak;
|
||||
@ -21,10 +22,10 @@ public class CustomMovementInput{
|
||||
options.jump = settings.keyBindJump.isKeyDown();
|
||||
options.sneak = settings.keyBindSneak.isKeyDown();
|
||||
|
||||
sprint = ClientModManager.keyBindSprint.isKeyDown();
|
||||
sprint = ClientModManager.keyBindSprintHold.isKeyDown();
|
||||
|
||||
if (!sprint){
|
||||
if (!ClientModManager.disableModFunctionality && ClientModManager.keyBindSprintToggle.isKeyDown()){
|
||||
if (!ClientSettings.disableMod && ClientModManager.keyBindSprintToggle.isKeyDown()){
|
||||
if (!hasToggledSprint){
|
||||
sprintToggle = !sprintToggle;
|
||||
hasToggledSprint = true;
|
||||
@ -40,7 +41,7 @@ public class CustomMovementInput{
|
||||
options.sneak = settings.keyBindSneak.isKeyDown();
|
||||
|
||||
if (!options.sneak){
|
||||
if (!ClientModManager.disableModFunctionality && ClientModManager.keyBindSneakToggle.isKeyDown()){
|
||||
if (!ClientSettings.disableMod && ClientModManager.keyBindSneakToggle.isKeyDown()){
|
||||
if (!hasToggledSneak){
|
||||
sneakToggle = !sneakToggle;
|
||||
hasToggledSneak = true;
|
||||
|
@ -1,32 +1,29 @@
|
||||
package chylex.bettersprinting.client.player;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.GuiGameOver;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.client.C0BPacketEntityAction;
|
||||
import net.minecraft.network.play.client.C17PacketCustomPayload;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.MovementInputFromOptions;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import api.player.client.ClientPlayerAPI;
|
||||
import api.player.client.ClientPlayerBase;
|
||||
import chylex.bettersprinting.BetterSprintingMod;
|
||||
import chylex.bettersprinting.client.ClientModManager;
|
||||
import chylex.bettersprinting.client.ClientSettings;
|
||||
import chylex.bettersprinting.client.gui.GuiSprint;
|
||||
|
||||
public class PlayerBase extends ClientPlayerBase{
|
||||
private static boolean shouldRestoreSneakToggle = false;
|
||||
private static String connectedServer = "";
|
||||
private static byte behaviorCheckTimer = 10;
|
||||
|
||||
private Minecraft mc;
|
||||
private CustomMovementInput customMovementInput;
|
||||
|
||||
public PlayerBase(ClientPlayerAPI api){
|
||||
super(api);
|
||||
mc=Minecraft.getMinecraft();
|
||||
customMovementInput=new CustomMovementInput();
|
||||
mc = Minecraft.getMinecraft();
|
||||
customMovementInput = new CustomMovementInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,7 +31,7 @@ public class PlayerBase extends ClientPlayerBase{
|
||||
if (player.sprintingTicksLeft > 0 && --player.sprintingTicksLeft == 0)player.setSprinting(false);
|
||||
if (player.sprintToggleTimer > 0)--player.sprintToggleTimer;
|
||||
|
||||
player.prevTimeInPortal=player.timeInPortal;
|
||||
player.prevTimeInPortal = player.timeInPortal;
|
||||
|
||||
if (player.inPortal){
|
||||
if (mc.currentScreen != null && !mc.currentScreen.doesGuiPauseGame())mc.displayGuiScreen(null);
|
||||
@ -79,13 +76,13 @@ public class PlayerBase extends ClientPlayerBase{
|
||||
boolean enoughHunger = player.getFoodStats().getFoodLevel() > 6F || player.capabilities.allowFlying;
|
||||
|
||||
// CHANGE
|
||||
if (ClientModManager.disableModFunctionality){
|
||||
if (ClientSettings.disableMod){
|
||||
if (player.onGround && !isMovingForward && player.movementInput.moveForward >= minSpeed && !player.isSprinting() && enoughHunger && !player.isUsingItem() && !player.isPotionActive(Potion.blindness)){
|
||||
if (player.sprintToggleTimer <= 0 && !ClientModManager.keyBindSprint.isKeyDown())player.sprintToggleTimer = 7;
|
||||
if (player.sprintToggleTimer <= 0 && !ClientModManager.keyBindSprintHold.isKeyDown())player.sprintToggleTimer = 7;
|
||||
else player.setSprinting(true);
|
||||
}
|
||||
|
||||
if (!player.isSprinting() && player.movementInput.moveForward >= minSpeed && enoughHunger && !player.isUsingItem() && !player.isPotionActive(Potion.blindness) && ClientModManager.keyBindSprint.isKeyDown()){
|
||||
if (!player.isSprinting() && player.movementInput.moveForward >= minSpeed && enoughHunger && !player.isUsingItem() && !player.isPotionActive(Potion.blindness) && ClientModManager.keyBindSprintHold.isKeyDown()){
|
||||
player.setSprinting(true);
|
||||
}
|
||||
}
|
||||
@ -93,7 +90,7 @@ public class PlayerBase extends ClientPlayerBase{
|
||||
updateBehavior();
|
||||
boolean lastheld = ClientModManager.held;
|
||||
boolean state = customMovementInput.sprint;
|
||||
boolean doubletap = ClientModManager.allowDoubleTap || ClientModManager.disableModFunctionality;
|
||||
boolean doubletap = ClientSettings.enableDoubleTap || ClientSettings.disableMod;
|
||||
|
||||
if (!player.capabilities.isFlying && ((MovementInputFromOptions)player.movementInput).sneak)state = false;
|
||||
|
||||
@ -121,15 +118,15 @@ public class PlayerBase extends ClientPlayerBase{
|
||||
}
|
||||
}
|
||||
|
||||
if (ClientModManager.flyingBoost > 0){
|
||||
if (ClientSettings.flySpeedBoost > 0){
|
||||
if (state && player.capabilities.isFlying && ClientModManager.canBoostFlying(mc)){
|
||||
player.capabilities.setFlySpeed(0.05F*(1+ClientModManager.flyingBoost));
|
||||
player.capabilities.setFlySpeed(0.05F*(1+ClientSettings.flySpeedBoost));
|
||||
if (player.movementInput.sneak){
|
||||
player.motionY -= 0.15D*ClientModManager.flyingBoost;
|
||||
player.motionY -= 0.15D*ClientSettings.flySpeedBoost;
|
||||
}
|
||||
|
||||
if (player.movementInput.jump){
|
||||
player.motionY += 0.15D*ClientModManager.flyingBoost;
|
||||
player.motionY += 0.15D*ClientSettings.flySpeedBoost;
|
||||
}
|
||||
}
|
||||
else player.capabilities.setFlySpeed(0.05F);
|
||||
@ -142,7 +139,7 @@ public class PlayerBase extends ClientPlayerBase{
|
||||
// END
|
||||
|
||||
if (player.isSprinting() && (player.movementInput.moveForward < minSpeed || player.isCollidedHorizontally || !enoughHunger)){
|
||||
if ((ClientModManager.canRunInAllDirs(mc) && ClientModManager.allowAllDirs) == false || (player.movementInput.moveForward == 0F && player.movementInput.moveStrafe == 0F))player.setSprinting(false); // CHANGED LINE
|
||||
if ((ClientModManager.canRunInAllDirs(mc) && ClientSettings.enableAllDirs) == false || (player.movementInput.moveForward == 0F && player.movementInput.moveStrafe == 0F))player.setSprinting(false); // CHANGED LINE
|
||||
}
|
||||
|
||||
if (player.capabilities.allowFlying){
|
||||
@ -207,12 +204,12 @@ public class PlayerBase extends ClientPlayerBase{
|
||||
private void updateBehavior(){
|
||||
if (mc.currentScreen != null && player != null && player.isSneaking()){
|
||||
if (customMovementInput.sneakToggle && !(mc.currentScreen instanceof GuiGameOver)){
|
||||
if (!ClientModManager.showedToggleSneakWarning){
|
||||
if (!ClientSettings.showedSneakWarning){
|
||||
player.addChatMessage(new ChatComponentText("First-time warning: You can open inventories and menus while sneaking, however you will not be sneaking for the time it is open. Once you close the menu, sneaking will be restored."));
|
||||
mc.displayGuiScreen(null);
|
||||
mc.setIngameFocus();
|
||||
ClientModManager.showedToggleSneakWarning = true;
|
||||
ClientModManager.saveSprint(mc);
|
||||
ClientSettings.showedSneakWarning = true;
|
||||
ClientSettings.refresh(BetterSprintingMod.config);
|
||||
}
|
||||
else{
|
||||
shouldRestoreSneakToggle = true;
|
||||
@ -225,32 +222,5 @@ public class PlayerBase extends ClientPlayerBase{
|
||||
customMovementInput.sneakToggle = true;
|
||||
shouldRestoreSneakToggle = false;
|
||||
}
|
||||
|
||||
if (behaviorCheckTimer > 0){
|
||||
--behaviorCheckTimer;
|
||||
return;
|
||||
}
|
||||
|
||||
behaviorCheckTimer = 10;
|
||||
|
||||
if (mc.thePlayer == null){
|
||||
connectedServer = "";
|
||||
ClientModManager.svFlyingBoost = ClientModManager.svRunInAllDirs = false;
|
||||
}
|
||||
else if (!mc.isIntegratedServerRunning() && mc.getCurrentServerData() != null && !ClientModManager.disableModFunctionality){
|
||||
String serverIP = mc.getCurrentServerData().serverIP;
|
||||
|
||||
if (!connectedServer.equals(serverIP)){
|
||||
ClientModManager.svFlyingBoost = ClientModManager.svRunInAllDirs = false;
|
||||
connectedServer = new String(serverIP);
|
||||
|
||||
if ((connectedServer.startsWith("127.0.0.1") || connectedServer.equals("localhost")) == false){
|
||||
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
|
||||
buffer.writeByte(4);
|
||||
mc.thePlayer.sendQueue.addToSendQueue(new C17PacketCustomPayload("BSprint",buffer));
|
||||
}
|
||||
else ClientModManager.svFlyingBoost = ClientModManager.svRunInAllDirs = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package chylex.bettersprinting.server;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import chylex.bettersprinting.system.PacketPipeline.INetworkHandler;
|
||||
|
||||
public class ServerNetwork implements INetworkHandler{
|
||||
/*
|
||||
* INCOMING PACKETS
|
||||
* ================
|
||||
* Payload packet on "BSprint" channel
|
||||
* * byte 4 - old protocol, no custom functionality
|
||||
* * byte 5 - new protocol, if you updated your handling code then ignore people who send this one and wait for BSM
|
||||
*
|
||||
* Payload packet on "BSM" channel
|
||||
* * byte 0, byte X - new protocol, X is the protocol version (currently 10)
|
||||
* - you are free to use new functionality
|
||||
*
|
||||
* OUTCOMING PACKETS
|
||||
* =================
|
||||
* Payload packet on "BSM" channel
|
||||
* * byte 0, boolean enableSurvivalFlyBoost, boolean enableAllDirs - custom settings, both are false by default
|
||||
* * byte 1 - disables the mod on client-side
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onPacket(Side side, ByteBuf data, EntityPlayer player){
|
||||
byte type = data.readByte();
|
||||
// TODO
|
||||
}
|
||||
}
|
@ -3,13 +3,16 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import chylex.bettersprinting.BetterSprintingConfig;
|
||||
import chylex.bettersprinting.BetterSprintingProxy;
|
||||
import chylex.bettersprinting.system.PacketPipeline;
|
||||
|
||||
public class ServerProxy extends BetterSprintingProxy{
|
||||
@Override
|
||||
public void loadSidedConfig(BetterSprintingConfig config){}
|
||||
|
||||
@Override
|
||||
public void onPreInit(FMLPreInitializationEvent e){}
|
||||
public void onPreInit(FMLPreInitializationEvent e){
|
||||
PacketPipeline.initialize(new ServerNetwork());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit(FMLInitializationEvent e){}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package chylex.bettersprinting.system;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLEventChannel;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class PacketPipeline{
|
||||
private static final String channelName = "BSM";
|
||||
private static PacketPipeline instance;
|
||||
|
||||
public static void initialize(INetworkHandler handler){
|
||||
if (instance != null)throw new RuntimeException("Packet pipeline has already been registered!");
|
||||
instance = new PacketPipeline(handler);
|
||||
}
|
||||
|
||||
private final FMLEventChannel channel;
|
||||
private final INetworkHandler handler;
|
||||
|
||||
private PacketPipeline(INetworkHandler handler){
|
||||
channel = NetworkRegistry.INSTANCE.newEventDrivenChannel(channelName);
|
||||
channel.register(this);
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientPacket(ClientCustomPacketEvent e){
|
||||
handler.onPacket(Side.CLIENT,e.packet.payload(),getClientPlayer());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerPacket(ServerCustomPacketEvent e){
|
||||
handler.onPacket(Side.SERVER,e.packet.payload(),((NetHandlerPlayServer)e.handler).playerEntity);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private EntityPlayer getClientPlayer(){
|
||||
return Minecraft.getMinecraft().thePlayer;
|
||||
}
|
||||
|
||||
public static PacketBuffer buf(){
|
||||
return new PacketBuffer(Unpooled.buffer());
|
||||
}
|
||||
|
||||
public static void sendToAll(PacketBuffer buffer){
|
||||
instance.channel.sendToAll(new FMLProxyPacket(buffer,channelName));
|
||||
}
|
||||
|
||||
public static void sendToPlayer(PacketBuffer buffer, EntityPlayer player){
|
||||
instance.channel.sendTo(new FMLProxyPacket(buffer,channelName),(EntityPlayerMP)player);
|
||||
}
|
||||
|
||||
public static void sendToServer(PacketBuffer buffer){
|
||||
instance.channel.sendToServer(new FMLProxyPacket(buffer,channelName));
|
||||
}
|
||||
|
||||
public static interface INetworkHandler{
|
||||
void onPacket(Side side, ByteBuf data, EntityPlayer player);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user