Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Update Premise: GUI
Browse files Browse the repository at this point in the history
- Completely redone the keyboard system
- Moving away from commands, added a setup interface to manage the
settings accessible via [/rec] (no oprands)
> the keyboard pane allows the user to enable keyboard control and
set-up the key bindings
> the interface pane allows the user to manage if they ever see the
RecMod bobber
> the integration tab is hiding an awesome feature that will be added at
a later date
- Improved the efficiency of client commands like changing the UI sheet
or toggling the bobber
- Plug the packet leak (thanks to progwml6)
- Removed the need for the redundant self oprand part of the ui branch
of the /rec command
- Removed the ui branch of the /rec command to bobber
  • Loading branch information
fuj1n committed Sep 23, 2014
1 parent c7110e5 commit 3383c7c
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 339 deletions.
Binary file added pub_build/RecStatusMod-v1.4-1.7.10.jar
Binary file not shown.
Binary file added resources/assets/recmod/textures/gui/simple.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/mcmod.info
Expand Up @@ -3,7 +3,7 @@
"modid": "fuj1n.recmod",
"name": "Recording Status Mod",
"description": "Record/Stream status in the players list, /rec <r/s> to toggle",
"version": "v1.3.2",
"version": "v1.4",
"mcversion": "1.7.10",
"url": "",
"updateUrl": "",
Expand Down
84 changes: 50 additions & 34 deletions src/fuj1n/recmod/RecMod.java
@@ -1,36 +1,40 @@
package fuj1n.recmod;

import java.io.*;
import java.util.*;

import cpw.mods.fml.common.*;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
import fuj1n.recmod.client.event.*;
import fuj1n.recmod.client.keybind.KeyHandlerRecMod;
import fuj1n.recmod.command.CommandRec;
import fuj1n.recmod.network.PlayerTracker;
import fuj1n.recmod.network.*;
import fuj1n.recmod.network.packet.*;
import java.io.*;
import java.util.HashMap;
import net.minecraft.command.ServerCommandManager;
import net.minecraft.entity.player.*;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.MinecraftForge;

@Mod(name = "Recording Status Mod", version = "v1.3.2", modid = "fuj1n.recmod", acceptableRemoteVersions="*", canBeDeactivated=false)
@Mod(name = "Recording Status Mod", version = "v1.4", modid = "fuj1n.recmod", acceptableRemoteVersions = "*", canBeDeactivated = false)
public class RecMod {

@Instance("fuj1n.recmod")
public static RecMod instance;

public static final PacketPipeline packetPipeline = new PacketPipeline();

private static HashMap<String, Boolean> recorders = new HashMap<String, Boolean>();
private static HashMap<String, Boolean> streamers = new HashMap<String, Boolean>();

public boolean showSelf = true;
public boolean showUI = false;

//Keyboard stuffs
public boolean enableKeys = false;
public int keyRec = 44;
public int keyStr = 45;

public String sheetLocation = "recmod:textures/sheets/indicators.png";

Expand All @@ -41,33 +45,33 @@ public class RecMod {
@EventHandler
public void preinit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new PlayerTracker());

NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());

configFile = new File(event.getModConfigurationDirectory(), "recmod.ui");

if (event.getSide() == Side.CLIENT) {
readFromFile();
MinecraftForge.EVENT_BUS.register(new EventRenderGame());
MinecraftForge.EVENT_BUS.register(new EventClientEntityLogin());

KeyHandlerRecMod keyh = KeyHandlerRecMod.instantiateSelf();
MinecraftForge.EVENT_BUS.register(keyh);
FMLCommonHandler.instance().bus().register(new EventClientEntityLogin());
FMLCommonHandler.instance().bus().register(new KeyHandlerRecMod());
}
}

@EventHandler
public void init(FMLInitializationEvent event) {
packetPipeline.initialise();

PacketPipeline pp = packetPipeline;
//Packet Registration
pp.registerPacket(PacketUpdatePlayerStatus.class);
pp.registerPacket(PacketRemovePlayer.class);
pp.registerPacket(PacketChangeUISettings.class);
pp.registerPacket(PacketChangeUISheet.class);
pp.registerPacket(PacketClientCommand.class);
}

@EventHandler
public void postinit(FMLPostInitializationEvent event) {
packetPipeline.postInitialise();
packetPipeline.postInitialise();
}

@EventHandler
Expand Down Expand Up @@ -119,6 +123,8 @@ public void onSheetChanged() {

public void readFromFile() {
if (!configFile.exists()) {
writeToFile();

return;
}

Expand All @@ -127,10 +133,16 @@ public void readFromFile() {
String line1 = b.readLine();
String line2 = b.readLine();
String line3 = b.readLine();
String line4 = b.readLine();
String line5 = b.readLine();

showSelfDef = convertToBoolean(line1);
showUI = convertToBoolean(line2);
sheetLocation = line3 != null && !line3.equals("") ? line3 : sheetLocation;
showSelfDef = convertToBoolean(line1, true);
sheetLocation = line2 != null && !line2.equals("") ? line2 : sheetLocation;
enableKeys = convertToBoolean(line3, false);
keyRec = convertToInteger(line4, 44);
keyStr = convertToInteger(line5, 45);

b.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
Expand All @@ -139,12 +151,20 @@ public void readFromFile() {
}
}

public boolean convertToBoolean(String s) {
public int convertToInteger(String s, int def) {
try {
return Integer.parseInt(s);
} catch (Exception e) {
}
return def;
}

public boolean convertToBoolean(String s, boolean def) {
try {
return Boolean.parseBoolean(s);
} catch (Exception e) {
}
return false;
return def;
}

public void writeToFile() {
Expand All @@ -154,21 +174,19 @@ public void writeToFile() {
BufferedWriter b = new BufferedWriter(new FileWriter(configFile));
b.write(Boolean.toString(showSelfDef));
b.newLine();
b.write(Boolean.toString(showUI));
b.newLine();
b.write(sheetLocation);
b.newLine();
b.write(Boolean.toString(enableKeys));
b.newLine();
b.write(Integer.toString(keyRec));
b.newLine();
b.write(Integer.toString(keyStr));
b.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public int calculateNumber() {
ArrayList<String> list = new ArrayList<String>();

return list.size();
}

public void removeUnneededData(String username) {
recorders.remove(username);
streamers.remove(username);
Expand All @@ -186,11 +204,9 @@ public void sendDataToPlayer(EntityPlayer player) {

public void sendPacket(EntityPlayer target, String player, int type, boolean flag) {
PacketUpdatePlayerStatus pckt = new PacketUpdatePlayerStatus(player, type, flag);
if(target instanceof EntityPlayerMP){
System.out.println("target = MP");
packetPipeline.sendTo(pckt, (EntityPlayerMP)target);
}else{
System.out.println("target != MP");
if (target instanceof EntityPlayerMP) {
packetPipeline.sendTo(pckt, (EntityPlayerMP) target);
} else {
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/fuj1n/recmod/client/event/EventClientEntityLogin.java
@@ -1,19 +1,16 @@
package fuj1n.recmod.client.event;

import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import fuj1n.recmod.RecMod;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;

public class EventClientEntityLogin {

@SubscribeEvent
public void onEntityLogin(PlayerLoggedInEvent event){
public void onEntityLogin(PlayerLoggedInEvent event) {
Minecraft mc = Minecraft.getMinecraft().getMinecraft();
RecMod.instance.showSelf = !mc.isSingleplayer() && !RecMod.instance.showSelfDef;
}

}
34 changes: 16 additions & 18 deletions src/fuj1n/recmod/client/event/EventRenderGame.java
@@ -1,39 +1,37 @@
package fuj1n.recmod.client.event;

import java.util.List;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import fuj1n.recmod.RecMod;
import fuj1n.recmod.lib.IndexReference;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.*;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import org.lwjgl.opengl.GL11;

public class EventRenderGame extends Gui {

private String sheetLocation = RecMod.instance.sheetLocation;
private ResourceLocation indicators = new ResourceLocation(sheetLocation);

@SubscribeEvent
public void onRenderGameOverlay(RenderGameOverlayEvent event) {
if(!sheetLocation.equals(RecMod.instance.sheetLocation)){
if (!sheetLocation.equals(RecMod.instance.sheetLocation)) {
sheetLocation = RecMod.instance.sheetLocation;
indicators = new ResourceLocation(sheetLocation);
}

if (event.type != RenderGameOverlayEvent.ElementType.ALL) {
return;
}
Minecraft mc = Minecraft.getMinecraft();
if (mc.gameSettings.keyBindPlayerList.getIsKeyPressed() && (!mc.isIntegratedServerRunning() || mc.thePlayer.sendQueue.playerInfoList.size() > 1 || mc.theWorld.getScoreboard().func_96539_a(0) != null)) {
mc.mcProfiler.startSection("playerList");
NetHandlerPlayClient nethandlerplayclient = mc.thePlayer.sendQueue;
List list = nethandlerplayclient.playerInfoList;
mc.mcProfiler.startSection("playerList");
NetHandlerPlayClient nethandlerplayclient = mc.thePlayer.sendQueue;
List list = nethandlerplayclient.playerInfoList;

int k = event.resolution.getScaledWidth();
int i2;
Expand Down Expand Up @@ -80,22 +78,22 @@ public void onRenderGameOverlay(RenderGameOverlayEvent event) {
mc.getTextureManager().bindTexture(indicators);
int indicatorRecIndex = RecMod.instance.isPlayerRecording(guiplayerinfo.name) ? IndexReference.ICON_RED_INDEX : IndexReference.ICON_GRAY_INDEX;
int indicatorStrIndex = RecMod.instance.isPlayerStreaming(guiplayerinfo.name) ? IndexReference.ICON_GREEN_INDEX : IndexReference.ICON_GRAY_INDEX;
drawTexturedModalRect(i6 - 8 - infooffset, j3, indicatorRecIndex < 32 ? indicatorRecIndex * 8 : indicatorRecIndex * 8 /*Better equation here*/, (int)Math.floor(indicatorRecIndex / 32) * 8, 8, 8);
drawTexturedModalRect(i6 - 8 - (infooffset - 8), j3, indicatorStrIndex * 8, (int)Math.floor(indicatorStrIndex / 32) * 8, 8, 8);

drawTexturedModalRect(i6 - 8 - infooffset, j3, indicatorRecIndex < 32 ? indicatorRecIndex * 8 : indicatorRecIndex * 8 /*Better equation here*/, (int) Math.floor(indicatorRecIndex / 32) * 8, 8, 8);
drawTexturedModalRect(i6 - 8 - (infooffset - 8), j3, indicatorStrIndex * 8, (int) Math.floor(indicatorStrIndex / 32) * 8, 8, 8);
}
}
}
}else if(!mc.gameSettings.keyBindPlayerList.getIsKeyPressed() && RecMod.instance.showSelf && mc.currentScreen == null){
} else if (!mc.gameSettings.keyBindPlayerList.getIsKeyPressed() && RecMod.instance.showSelf && mc.currentScreen == null) {
int x = event.resolution.getScaledWidth() - 32;
int y = 0;

int indicatorRecIndex = RecMod.instance.isPlayerRecording(mc.thePlayer.getCommandSenderName()) ? 1 : 0;
int indicatorStrIndex = RecMod.instance.isPlayerStreaming(mc.thePlayer.getCommandSenderName()) ? 2 : 0;

mc.getTextureManager().bindTexture(indicators);
drawTexturedModalRect(x, y, indicatorRecIndex * 16, (int)Math.floor(indicatorRecIndex / 16) * 16 + IndexReference.RESOLUTION_SPLIT_Y, 16, 16);
drawTexturedModalRect(x + 16, y, indicatorStrIndex * 16, (int)Math.floor(indicatorStrIndex / 16) * 16 + IndexReference.RESOLUTION_SPLIT_Y, 16, 16);
drawTexturedModalRect(x, y, indicatorRecIndex * 16, (int) Math.floor(indicatorRecIndex / 16) * 16 + IndexReference.RESOLUTION_SPLIT_Y, 16, 16);
drawTexturedModalRect(x + 16, y, indicatorStrIndex * 16, (int) Math.floor(indicatorStrIndex / 16) * 16 + IndexReference.RESOLUTION_SPLIT_Y, 16, 16);
}
}

Expand Down

0 comments on commit 3383c7c

Please sign in to comment.