Skip to content

Commit

Permalink
Merge pull request #15 from Thorfusion/1.7.10-dev2
Browse files Browse the repository at this point in the history
Update server change and added cape module from titanstorms
  • Loading branch information
maggi373 authored Dec 29, 2020
2 parents dc6220d + beae5c4 commit 1f73c71
Show file tree
Hide file tree
Showing 23 changed files with 950 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ FMP_version=1.2.0.345
CCLIB_version=1.1.3.136
NEI_version=1.0.4.101
CCC_version=1.0.6.39
mod_version=9.10.4
mod_version=9.10.5
159 changes: 159 additions & 0 deletions src/main/java/com/jadarstudios/developercapes/DevCapes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* DeveloperCapes by Jadar
* License: MIT License
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE)
* version 4.0.0.x
*/
package com.jadarstudios.developercapes;

import com.jadarstudios.developercapes.cape.CapeConfig;
import com.jadarstudios.developercapes.cape.CapeConfigManager;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
* DeveloperCapes is a library for Minecraft. It allows developers to quickly add capes for players they specify. DevCapes uses Minecraft Forge.
*
* @author jadar
*/
public class DevCapes {
private static DevCapes instance;

public static final Logger logger = LogManager.getLogger("DevCapes");

protected DevCapes() {
MinecraftForge.EVENT_BUS.register(new RenderEventHandler());
}

public static DevCapes getInstance() {
if (instance == null) {
instance = new DevCapes();
}
return instance;
}

/**
* InputStream.close() needs to be called on this after you're done!
*
* @return {@link InputStream} for the {@link URL}
*/
public InputStream getStreamForURL(URL url) {
InputStream is = null;
try {
URLConnection connection = url.openConnection();
connection.setRequestProperty("User-Agent", System.getProperty("java.version"));
connection.connect();

is = connection.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
return is;
}

/**
* InputStream.close() needs to be called on this after you're done!
*
* @return {@link InputStream} for the {@link File}
*/
public InputStream getStreamForFile(File file) {
InputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return is;
}

@Deprecated
/**
* DEPRECATED: Please use {@link #registerConfig(String jsonUrl)} instead.<p>
* Registers a config with DevCapes.
*
* @param jsonUrl
* The URL as a String that links to the Json file that you want
* to add
* @param identifier
* A unique Identifier, normally your mod id
* @return The id of the registered config
*/
public int registerConfig(String jsonURL, String identifier) {
return this.registerConfig(jsonURL);
}

/**
* Registers a config with DevCapes.
*
* @param jsonUrl The URL as a String that links to the Json file that you want
* to add
* @return The id of the registered config
*/
public int registerConfig(String jsonUrl) {
int id = -1;
try {
URL url = new URL(jsonUrl);
id = this.registerConfig(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return id;
}

@Deprecated
/**
* DEPRECATED: Please use {@link #registerConfig(URL url)} instead.<p>
* Registers a config with DevCapes.
*
* @param jsonUrl
* A {@link URL} that links to the Json file that you want to add
* @param identifier
* A unique Identifier, normally your mod id
* @return The id of the registered config
*/
public int registerConfig(URL url, String identifier) {
return this.registerConfig(url);
}

/**
* Registers a config with DevCapes and returns the ID of the config.
*
* @param jsonUrl A {@link URL} that links to the Json file that you want to add
* @return The id of the registered config
*/
public int registerConfig(URL jsonUrl) {
int id = -1;
InputStream is = this.getStreamForURL(jsonUrl);

if (is == null) {
DevCapes.logger.error(String.format("Unable to establish a connection to the server, %s", jsonUrl.getHost()));
return id;
}

CapeConfig config = CapeConfigManager.getInstance().parse(is);

try {
id = CapeConfigManager.getUniqueId();
CapeConfigManager.getInstance().addConfig(id, config);
} catch (CapeConfigManager.InvalidCapeConfigIdException e) {
e.printStackTrace();
}

silentClose(is);

return id;
}

private static void silentClose(InputStream is) {
try {
is.close();
} catch (IOException ignored) {
}
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/jadarstudios/developercapes/HDImageBuffer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* DeveloperCapes by Jadar
* License: MIT License
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE)
* version 3.3.0.0
*/
package com.jadarstudios.developercapes;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.IImageBuffer;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

/**
* This class is an implementation of {@link IImageBuffer} that allows capes to be in HD
*
* @author Jadar
*/
@SideOnly(Side.CLIENT)
public class HDImageBuffer implements IImageBuffer {
@Override
public BufferedImage parseUserSkin(final BufferedImage texture) {
if (texture == null)
return null;
int imageWidth = texture.getWidth(null) <= 64 ? 64 : texture.getWidth(null);
int imageHeight = texture.getHeight(null) <= 32 ? 32 : texture.getHeight(null);

BufferedImage capeImage = new BufferedImage(imageWidth, imageHeight, 2);

Graphics graphics = capeImage.getGraphics();
graphics.drawImage(texture, 0, 0, null);
graphics.dispose();

return capeImage;
}

@Override
public void func_152634_a() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* DeveloperCapes by Jadar
* License: MIT License
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE)
* version 4.0.0.x
*/
package com.jadarstudios.developercapes;

import com.jadarstudios.developercapes.cape.ICape;
import com.jadarstudios.developercapes.user.User;
import com.jadarstudios.developercapes.user.UserManager;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraftforge.client.event.RenderPlayerEvent;

/**
* This is not the class you are looking for.
*
* @author jadar
*/
public class RenderEventHandler {

@SubscribeEvent
public void renderPlayer(RenderPlayerEvent.Specials.Pre event) {
AbstractClientPlayer player = (AbstractClientPlayer) event.entityPlayer;

UserManager manager = UserManager.getInstance();
User user = manager.getUser(player.getUniqueID().toString());
if (user == null) return;

ICape cape = user.capes.get(0);
if (cape == null) return;

boolean flag = cape.isTextureLoaded(player);
if (!flag) {
cape.loadTexture(player);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* DeveloperCapes by Jadar
* License: MIT License
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE)
* version 4.0.0.x
*/
package com.jadarstudios.developercapes.cape;

import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.util.ResourceLocation;

/**
* Abstract Implementation of ICape used within Dev. Capes
*
* @author jadar
*/
public abstract class AbstractCape implements ICape {
protected String name;
protected ITextureObject texture;
protected ResourceLocation location;

public AbstractCape(String name) {
this.name = name;
}

public AbstractCape() {}

@Override
public String getName() {
return name;
}

@Override
public ITextureObject getTexture() {
return this.texture;
}

@Override
public ResourceLocation getLocation() {
return this.location;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/jadarstudios/developercapes/cape/CapeConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* DeveloperCapes by Jadar
* License: MIT License
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE)
* version 4.0.0.x
*/
package com.jadarstudios.developercapes.cape;

import com.jadarstudios.developercapes.user.Group;
import com.jadarstudios.developercapes.user.User;

import java.util.HashMap;

/**
* The players that need to be outfitted are stored here
*
* @author jadar
*/
public class CapeConfig {
public HashMap<String, Group> groups;
public HashMap<String, User> users;

public CapeConfig() {
groups = new HashMap<String, Group>();
users = new HashMap<String, User>();
}
}
Loading

0 comments on commit 1f73c71

Please sign in to comment.