The beginnings of a voice server
This commit is contained in:
parent
0d7b2414ce
commit
34f1053354
7 changed files with 182 additions and 38 deletions
|
@ -368,6 +368,7 @@ public class ClientProxy extends CommonProxy
|
|||
TickRegistry.registerTickHandler(new RenderTickHandler(), Side.CLIENT);
|
||||
|
||||
NetworkRegistry.instance().registerConnectionHandler(new ClientConnectionHandler());
|
||||
NetworkRegistry.instance().registerConnectionHandler(new VoiceClientManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
package mekanism.common;
|
||||
package mekanism.client;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.NetLoginHandler;
|
||||
|
@ -8,16 +11,20 @@ import net.minecraft.server.MinecraftServer;
|
|||
import cpw.mods.fml.common.network.IConnectionHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class ConnectionHandler implements IConnectionHandler
|
||||
public class VoiceClientManager implements IConnectionHandler
|
||||
{
|
||||
public Socket socket;
|
||||
|
||||
@Override
|
||||
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
|
||||
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
|
||||
try {
|
||||
socket = new Socket(manager.getSocketAddress().toString(), 36123);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
|
||||
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -25,24 +32,33 @@ public class ConnectionHandler implements IConnectionHandler
|
|||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager)
|
||||
{
|
||||
|
||||
//connecting to foreign server
|
||||
try {
|
||||
socket = new Socket(server, 36123);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager)
|
||||
{
|
||||
|
||||
//connecting to LAN server on same instance
|
||||
try {
|
||||
socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 36123);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClosed(INetworkManager manager)
|
||||
{
|
||||
|
||||
try {
|
||||
socket.close();
|
||||
socket = null;
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
|
||||
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -12,8 +12,10 @@ import net.minecraft.client.renderer.OpenGlHelper;
|
|||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Timer;
|
||||
|
@ -21,6 +23,7 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
@ -177,6 +180,41 @@ public class MekanismRenderer
|
|||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleaned-up snip of ItemRenderer.renderItem() -- meant to render 2D items as equipped.
|
||||
* @param item - ItemStack to render
|
||||
*/
|
||||
public static void renderItem(ItemStack item)
|
||||
{
|
||||
Icon icon = item.getItem().getIconIndex(item);
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
|
||||
if(icon == null)
|
||||
{
|
||||
GL11.glPopMatrix();
|
||||
return;
|
||||
}
|
||||
|
||||
texturemanager.bindTexture(texturemanager.getResourceLocation(item.getItemSpriteNumber()));
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
float f = icon.getMinU();
|
||||
float f1 = icon.getMaxU();
|
||||
float f2 = icon.getMinV();
|
||||
float f3 = icon.getMaxV();
|
||||
float f4 = 0.0F;
|
||||
float f5 = 0.3F;
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glTranslatef(-f4, -f5, 0.0F);
|
||||
float f6 = 1.5F;
|
||||
GL11.glScalef(f6, f6, f6);
|
||||
GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
|
||||
GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
|
||||
RenderManager.instance.itemRenderer.renderItemIn2D(tessellator, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 0.0625F);
|
||||
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleaned-up snip of RenderBlocks.renderBlockAsItem() -- used for rendering an item as an entity,
|
||||
* in a player's inventory, and in a player's hand.
|
||||
|
|
|
@ -16,6 +16,7 @@ import mekanism.common.util.MekanismUtils.ResourceType;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.ModelChest;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
|
@ -71,33 +72,7 @@ public class ItemRenderingHandler implements IItemRenderer
|
|||
}
|
||||
else if(item.getItem() instanceof ItemWalkieTalkie)
|
||||
{
|
||||
Icon icon = item.getItem().getIconIndex(item);
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
|
||||
if (icon == null)
|
||||
{
|
||||
GL11.glPopMatrix();
|
||||
return;
|
||||
}
|
||||
|
||||
texturemanager.bindTexture(texturemanager.getResourceLocation(item.getItemSpriteNumber()));
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
float f = icon.getMinU();
|
||||
float f1 = icon.getMaxU();
|
||||
float f2 = icon.getMinV();
|
||||
float f3 = icon.getMaxV();
|
||||
float f4 = 0.0F;
|
||||
float f5 = 0.3F;
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glTranslatef(-f4, -f5, 0.0F);
|
||||
float f6 = 1.5F;
|
||||
GL11.glScalef(f6, f6, f6);
|
||||
GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
|
||||
GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
|
||||
RenderManager.instance.itemRenderer.renderItemIn2D(tessellator, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 0.0625F);
|
||||
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
MekanismRenderer.renderItem(item);
|
||||
}
|
||||
else if(item.getItem() instanceof ItemBlockMachine && item.getItemDamage() == MachineType.ELECTRIC_CHEST.meta)
|
||||
{
|
||||
|
|
|
@ -168,6 +168,9 @@ public class Mekanism
|
|||
/** The main SoundHandler instance that is used by all audio sources */
|
||||
public static SoundHandler audioHandler;
|
||||
|
||||
/** The VoiceServer manager for walkie talkies */
|
||||
public static VoiceServerManager voiceManager;
|
||||
|
||||
/** A list of the usernames of players who have donated to Mekanism. */
|
||||
public static List<String> donators = new ArrayList<String>();
|
||||
|
||||
|
@ -1040,12 +1043,14 @@ public class Mekanism
|
|||
@EventHandler
|
||||
public void serverStarting(FMLServerStartingEvent event)
|
||||
{
|
||||
voiceManager.start();
|
||||
event.registerServerCommand(new CommandMekanism());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void serverStopping(FMLServerStoppingEvent event)
|
||||
{
|
||||
voiceManager.stop();
|
||||
teleporters.clear();
|
||||
dynamicInventories.clear();
|
||||
}
|
||||
|
@ -1104,7 +1109,9 @@ public class Mekanism
|
|||
//Register to receive subscribed events
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
NetworkRegistry.instance().registerConnectionHandler(new ConnectionHandler());
|
||||
//Set up VoiceServerManager
|
||||
voiceManager = new VoiceServerManager();
|
||||
NetworkRegistry.instance().registerConnectionHandler(voiceManager);
|
||||
|
||||
//Register with TransmitterNetworkRegistry
|
||||
TransmitterNetworkRegistry.initiate();
|
||||
|
|
13
common/mekanism/common/VoiceConnection.java
Normal file
13
common/mekanism/common/VoiceConnection.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package mekanism.common;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
public class VoiceConnection
|
||||
{
|
||||
public Socket socket;
|
||||
|
||||
public VoiceConnection(Socket s)
|
||||
{
|
||||
socket = s;
|
||||
}
|
||||
}
|
94
common/mekanism/common/VoiceServerManager.java
Normal file
94
common/mekanism/common/VoiceServerManager.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
package mekanism.common;
|
||||
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.NetLoginHandler;
|
||||
import net.minecraft.network.packet.NetHandler;
|
||||
import net.minecraft.network.packet.Packet1Login;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import cpw.mods.fml.common.network.IConnectionHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class VoiceServerManager implements IConnectionHandler
|
||||
{
|
||||
public Set<VoiceConnection> connections = new HashSet<VoiceConnection>();
|
||||
|
||||
public ServerSocket serverSocket;
|
||||
|
||||
public boolean running;
|
||||
|
||||
public void start()
|
||||
{
|
||||
try {
|
||||
serverSocket = new ServerSocket(36123);
|
||||
|
||||
new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while(running)
|
||||
{
|
||||
try {
|
||||
Socket s = serverSocket.accept();
|
||||
VoiceConnection connection = new VoiceConnection(s);
|
||||
connections.add(connection);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
} catch(Exception e) {}
|
||||
|
||||
running = true;
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
try {
|
||||
serverSocket.close();
|
||||
serverSocket = null;
|
||||
} catch(Exception e) {}
|
||||
|
||||
running = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClosed(INetworkManager manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue