Let the games... Begin!
This commit is contained in:
commit
71f5ab9758
13 changed files with 531 additions and 0 deletions
6
common/tan/ClientProxy.java
Normal file
6
common/tan/ClientProxy.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package tan;
|
||||
|
||||
public class ClientProxy extends CommonProxy
|
||||
{
|
||||
|
||||
}
|
6
common/tan/CommonProxy.java
Normal file
6
common/tan/CommonProxy.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package tan;
|
||||
|
||||
public class CommonProxy
|
||||
{
|
||||
|
||||
}
|
51
common/tan/ToughAsNails.java
Normal file
51
common/tan/ToughAsNails.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package tan;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import tan.handler.ConnectionHandler;
|
||||
import tan.handler.RenderOverlayEventHandler;
|
||||
import tan.handler.TickHandlerServer;
|
||||
import tan.network.PacketHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.registry.TickRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
@Mod(modid = "ToughAsNails", name = "Tough As Nails", version="0.0.1")
|
||||
@NetworkMod(channels = { "ToughAsNails" }, packetHandler = PacketHandler.class, clientSideRequired = true, serverSideRequired = false)
|
||||
public class ToughAsNails
|
||||
{
|
||||
@Instance("ToughAsNails")
|
||||
public static ToughAsNails instance;
|
||||
|
||||
@SidedProxy(clientSide="tan.ClientProxy", serverSide="tan.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
TickRegistry.registerTickHandler(new TickHandlerServer(), Side.SERVER);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new RenderOverlayEventHandler());
|
||||
|
||||
NetworkRegistry.instance().registerConnectionHandler(new ConnectionHandler());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
6
common/tan/api/TemperatureRegistry.java
Normal file
6
common/tan/api/TemperatureRegistry.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package tan.api;
|
||||
|
||||
public class TemperatureRegistry
|
||||
{
|
||||
|
||||
}
|
66
common/tan/core/TANPlayerStats.java
Normal file
66
common/tan/core/TANPlayerStats.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
package tan.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import tan.network.PacketTypeHandler;
|
||||
import tan.network.packet.PacketSendStats;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TANPlayerStats
|
||||
{
|
||||
public static void update(World world, EntityPlayerMP player)
|
||||
{
|
||||
NBTTagCompound tanData = player.getEntityData().getCompoundTag("ToughAsNails");
|
||||
|
||||
setDefaults(tanData, player);
|
||||
|
||||
float originalTemperature = tanData.getFloat("Temp");
|
||||
float temperature = originalTemperature;
|
||||
|
||||
if (world.rand.nextInt(25) == 0)
|
||||
{
|
||||
temperature--;
|
||||
}
|
||||
|
||||
if (temperature != originalTemperature)
|
||||
{
|
||||
tanData.setFloat("Temp", MathHelper.clamp_float(temperature, -50F, 50F));
|
||||
|
||||
updatePlayerData(tanData, player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void updatePlayerData(NBTTagCompound tanData, EntityPlayerMP player)
|
||||
{
|
||||
player.getEntityData().setCompoundTag("ToughAsNails", tanData);
|
||||
PacketDispatcher.sendPacketToPlayer(PacketTypeHandler.populatePacket(new PacketSendStats(tanData)), (Player)player);
|
||||
}
|
||||
|
||||
public static void setDefaults(NBTTagCompound tanData, EntityPlayerMP player)
|
||||
{
|
||||
setDefaultFloat(tanData, player, "Temp", 20F);
|
||||
}
|
||||
|
||||
private static void setDefaultInt(NBTTagCompound tanData, EntityPlayerMP player, String key, int value)
|
||||
{
|
||||
if (!tanData.hasKey(key))
|
||||
{
|
||||
tanData.setInteger(key, value);
|
||||
updatePlayerData(tanData, player);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setDefaultFloat(NBTTagCompound tanData, EntityPlayerMP player, String key, float value)
|
||||
{
|
||||
if (!tanData.hasKey(key))
|
||||
{
|
||||
tanData.setFloat(key, value);
|
||||
updatePlayerData(tanData, player);
|
||||
}
|
||||
}
|
||||
}
|
55
common/tan/handler/ConnectionHandler.java
Normal file
55
common/tan/handler/ConnectionHandler.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package tan.handler;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
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 tan.network.PacketTypeHandler;
|
||||
import tan.network.packet.PacketSendStats;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.IConnectionHandler;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class ConnectionHandler implements IConnectionHandler
|
||||
{
|
||||
@Override
|
||||
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
||||
{
|
||||
EntityPlayer entityPlayer = (EntityPlayer)player;
|
||||
|
||||
PacketDispatcher.sendPacketToPlayer(PacketTypeHandler.populatePacket(new PacketSendStats(entityPlayer.getEntityData().getCompoundTag("ToughAsNails"))), (Player)player);
|
||||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
}
|
||||
}
|
91
common/tan/handler/RenderOverlayEventHandler.java
Normal file
91
common/tan/handler/RenderOverlayEventHandler.java
Normal file
|
@ -0,0 +1,91 @@
|
|||
package tan.handler;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
||||
public class RenderOverlayEventHandler
|
||||
{
|
||||
public ResourceLocation overlayLocation = new ResourceLocation("toughasnails:textures/overlay/overlay.png");
|
||||
|
||||
@ForgeSubscribe
|
||||
public void render(RenderGameOverlayEvent.Pre event)
|
||||
{
|
||||
ScaledResolution scaledRes = event.resolution;
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
FontRenderer fontRenderer = minecraft.fontRenderer;
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
bindTexture(overlayLocation);
|
||||
{
|
||||
NBTTagCompound tanData = minecraft.thePlayer.getEntityData().getCompoundTag("ToughAsNails");
|
||||
|
||||
int temperature = MathHelper.floor_float(tanData.getFloat("Temp"));
|
||||
|
||||
int temperatureXPos = scaledRes.getScaledWidth() / 2 - 8;
|
||||
int temperatureYPos = scaledRes.getScaledHeight() - 52;
|
||||
|
||||
minecraft.mcProfiler.startSection("temperatureBall");
|
||||
{
|
||||
this.drawTexturedModalRect(temperatureXPos, temperatureYPos, 16, 0, 16, 16);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, temperature / 100F + 0.5F);
|
||||
this.drawTexturedModalRect(temperatureXPos, temperatureYPos, 0, 0, 16, 16);
|
||||
}
|
||||
minecraft.mcProfiler.endSection();
|
||||
|
||||
minecraft.mcProfiler.startSection("temperatureLevel");
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
{
|
||||
String text = temperature + "°C";
|
||||
|
||||
GL11.glTranslatef((float)(temperatureXPos - (fontRenderer.getStringWidth(text) / 2) + 12), (float)(temperatureYPos + 6), 0.0F);
|
||||
GL11.glScalef(0.65F, 0.65F, 0.0F);
|
||||
|
||||
drawStringWithBorder(fontRenderer, text, 0, 0, 0, 16777215);
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
minecraft.mcProfiler.endSection();
|
||||
}
|
||||
bindTexture(new ResourceLocation("minecraft:textures/gui/icons.png"));
|
||||
}
|
||||
|
||||
public static void bindTexture(ResourceLocation resourceLocation)
|
||||
{
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(resourceLocation);
|
||||
}
|
||||
|
||||
public void drawStringWithBorder(FontRenderer fontrenderer, String string, int x, int y, int borderColour, int colour)
|
||||
{
|
||||
fontrenderer.drawString(string, x + 1, y, borderColour);
|
||||
fontrenderer.drawString(string, x - 1, y, borderColour);
|
||||
fontrenderer.drawString(string, x, y + 1, borderColour);
|
||||
fontrenderer.drawString(string, x, y - 1, borderColour);
|
||||
fontrenderer.drawString(string, x, y, colour);
|
||||
}
|
||||
|
||||
public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height)
|
||||
{
|
||||
float f = 0.00390625F;
|
||||
float f1 = 0.00390625F;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertexWithUV(x + 0, y + height, 0.0, (u + 0) * f, (v + height) * f1);
|
||||
tessellator.addVertexWithUV(x + width, y + height, 0.0, (u + width) * f, (v + height) * f1);
|
||||
tessellator.addVertexWithUV(x + width, y + 0, 0.0, (u + width) * f, (v + 0) * f1);
|
||||
tessellator.addVertexWithUV(x + 0, y + 0, 0.0, (u + 0) * f, (v + 0) * f1);
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
43
common/tan/handler/TickHandlerServer.java
Normal file
43
common/tan/handler/TickHandlerServer.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
package tan.handler;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import tan.core.TANPlayerStats;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
public class TickHandlerServer implements ITickHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
onPlayerTick((World)((EntityPlayer)tickData[0]).worldObj, (EntityPlayerMP)tickData[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<TickType> ticks()
|
||||
{
|
||||
return EnumSet.of(TickType.PLAYER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel()
|
||||
{
|
||||
return "TANTickHandlerServer";
|
||||
}
|
||||
|
||||
public static void onPlayerTick(World world, EntityPlayerMP player)
|
||||
{
|
||||
TANPlayerStats.update(world, player);
|
||||
}
|
||||
}
|
18
common/tan/network/PacketHandler.java
Normal file
18
common/tan/network/PacketHandler.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package tan.network;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import tan.network.packet.PacketTAN;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketHandler implements IPacketHandler
|
||||
{
|
||||
@Override
|
||||
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
PacketTAN packetTAN = PacketTypeHandler.buildPacket(packet.data);
|
||||
|
||||
packetTAN.execute(manager, player);
|
||||
}
|
||||
}
|
71
common/tan/network/PacketTypeHandler.java
Normal file
71
common/tan/network/PacketTypeHandler.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
package tan.network;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import tan.network.packet.PacketSendStats;
|
||||
import tan.network.packet.PacketTAN;
|
||||
|
||||
public enum PacketTypeHandler
|
||||
{
|
||||
sendStats(PacketSendStats.class);
|
||||
|
||||
private Class<? extends PacketTAN> clazz;
|
||||
|
||||
PacketTypeHandler(Class<? extends PacketTAN> clazz)
|
||||
{
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public static PacketTAN buildPacket(byte[] data)
|
||||
{
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(data);
|
||||
int selector = bis.read();
|
||||
DataInputStream dis = new DataInputStream(bis);
|
||||
|
||||
PacketTAN packet = null;
|
||||
|
||||
try
|
||||
{
|
||||
packet = values()[selector].clazz.newInstance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
packet.readPopulate(dis);
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static PacketTAN buildPacket(PacketTypeHandler type)
|
||||
{
|
||||
PacketTAN packet = null;
|
||||
|
||||
try
|
||||
{
|
||||
packet = values()[type.ordinal()].clazz.newInstance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static Packet populatePacket(PacketTAN PacketTAN)
|
||||
{
|
||||
byte[] data = PacketTAN.populate();
|
||||
|
||||
Packet250CustomPayload packet250 = new Packet250CustomPayload();
|
||||
packet250.channel = "ToughAsNails";
|
||||
packet250.data = data;
|
||||
packet250.length = data.length;
|
||||
|
||||
return packet250;
|
||||
}
|
||||
}
|
54
common/tan/network/packet/PacketSendStats.java
Normal file
54
common/tan/network/packet/PacketSendStats.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package tan.network.packet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import tan.network.PacketTypeHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketSendStats extends PacketTAN
|
||||
{
|
||||
float temperature;
|
||||
|
||||
public PacketSendStats()
|
||||
{
|
||||
super(PacketTypeHandler.sendStats);
|
||||
}
|
||||
|
||||
public PacketSendStats(NBTTagCompound tanCompound)
|
||||
{
|
||||
super(PacketTypeHandler.sendStats);
|
||||
|
||||
temperature = tanCompound.getFloat("Temp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException
|
||||
{
|
||||
temperature = data.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException
|
||||
{
|
||||
data.writeFloat(temperature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(INetworkManager network, Player player)
|
||||
{
|
||||
EntityPlayer entityPlayer = (EntityPlayer)player;
|
||||
|
||||
NBTTagCompound tanCompound = entityPlayer.getEntityData().getCompoundTag("ToughAsNails");
|
||||
|
||||
tanCompound.setFloat("Temp", temperature);
|
||||
|
||||
System.out.println(temperature);
|
||||
|
||||
entityPlayer.getEntityData().setCompoundTag("ToughAsNails", tanCompound);
|
||||
}
|
||||
}
|
64
common/tan/network/packet/PacketTAN.java
Normal file
64
common/tan/network/packet/PacketTAN.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
package tan.network.packet;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import tan.network.PacketTypeHandler;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketTAN
|
||||
{
|
||||
public PacketTypeHandler packetType;
|
||||
|
||||
public PacketTAN(PacketTypeHandler packetType)
|
||||
{
|
||||
this.packetType = packetType;
|
||||
}
|
||||
|
||||
public byte[] populate()
|
||||
{
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
|
||||
try
|
||||
{
|
||||
dos.writeByte(packetType.ordinal());
|
||||
this.writeData(dos);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
public void readPopulate(DataInputStream data)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.readData(data);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
public void readData(DataInputStream data) throws IOException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void writeData(DataOutputStream dos) throws IOException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void execute(INetworkManager network, Player player)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
BIN
resources/assets/toughasnails/textures/overlay/overlay.png
Normal file
BIN
resources/assets/toughasnails/textures/overlay/overlay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Loading…
Reference in a new issue