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

Commit

Permalink
Clean up command & make fake player renderer cosmetic #2 #4 #8 #9 #17
Browse files Browse the repository at this point in the history
  • Loading branch information
boomboompower committed Mar 28, 2020
1 parent ed28dca commit c621f20
Show file tree
Hide file tree
Showing 13 changed files with 484 additions and 198 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ sourceSets {
// Which is why I've excluded it here. If you need help settings
// this up don't hesitate to message me anywhere.
java {
exclude '**/DevelopmentMixins.java'
exclude '**/priv'
}

// Groovy does not like that refMap is referred to as a string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@

import me.do_you_like.mods.skinchanger.SkinChangerMod;
import me.do_you_like.mods.skinchanger.gui.SkinChangerMenu;
import me.do_you_like.mods.skinchanger.utils.installing.InternetConnection;
import me.do_you_like.mods.skinchanger.utils.game.ChatColor;
import me.do_you_like.mods.skinchanger.utils.command.ModCommand;
import me.do_you_like.mods.skinchanger.utils.game.ChatColor;

import net.minecraft.command.ICommandSender;

/**
* NOTE: This class is temporary & it's methods will eventually be tuned into a new gui.
*/
public class SkinCommand extends ModCommand {
public static boolean IS_SLIM_SKIN = false;

// Cached main menu, saves memory and options.
private SkinChangerMenu mainMenu = null;

public SkinCommand(SkinChangerMod modIn) {
Expand All @@ -58,12 +57,6 @@ public void onCommand(ICommandSender sender, String[] args) {
org.lwjgl.opengl.Display.setResizable(false);
org.lwjgl.opengl.Display.setResizable(true);

return;
} else if (args[0].equalsIgnoreCase("slim")) {
IS_SLIM_SKIN = !IS_SLIM_SKIN;

sendMessage(ChatColor.AQUA + "Your skin is now " + (IS_SLIM_SKIN ? "slim" : "normal"));

return;
} else if (args[0].equalsIgnoreCase("reload")) {
this.mainMenu = new SkinChangerMenu();
Expand All @@ -72,32 +65,16 @@ public void onCommand(ICommandSender sender, String[] args) {
}
}

if (args.length > 0) {
if (args[0].equalsIgnoreCase("null") || args[0].equalsIgnoreCase("reset")) {
IS_SLIM_SKIN = false;

sendMessage(ChatColor.AQUA + "Your skin has been reset!");
} else {
if (!InternetConnection.hasInternetConnection()) {
sendMessage(ChatColor.RED + "Could not connect to the internet. " + ChatColor.RED + "Make sure you have a stable internet connection!");
return;
}
SkinChangerMenu menu = getMenu(args.length > 0 ? args[0] : null);

String id = this.mod.getMojangHooker().getRealNameFromName(args[0]);
// Something went wrong or an argument was incorrect.
if (menu == null) {
sendMessage(ChatColor.RED + "Invalid command arguments, try without arguments.");

if (id == null) {
id = args[0];
}

IS_SLIM_SKIN = this.mod.getMojangHooker().hasSlimSkin(id);

sendMessage(ChatColor.AQUA + "Set skin to " + id + "\'s skin!");

return;
}
return;
}

getMenu(args.length > 0 ? args[0] : "").display();
menu.display();
}

@Override
Expand All @@ -110,13 +87,24 @@ public boolean isUsernameIndex(String[] args, int index) {
return index == 0;
}

private SkinChangerMenu getMenu(String playerName) {
/**
* Gets the cached SkinChanger menu
*
* @param incomingInput the name of the player or a URL
*
* @return the cached SkinChanger menu if one exists, or a new one.
*/
private SkinChangerMenu getMenu(String incomingInput) {
// Check if a cached menu exists.
if (this.mainMenu == null) {
this.mainMenu = new SkinChangerMenu();
}

if (playerName != null) {
this.mainMenu.handleIncomingInput(playerName);
// If the player has specified an input it should be handled
if (incomingInput != null && !incomingInput.isEmpty()) {
if (!this.mainMenu.handleIncomingInput(incomingInput)) {
return null;
}
}

return this.mainMenu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lombok.Getter;

import me.do_you_like.mods.skinchanger.SkinChangerMod;
import me.do_you_like.mods.skinchanger.cosmetic.impl.fakeplayer.FakePlayerRender;
import me.do_you_like.mods.skinchanger.cosmetic.impl.ShaderPatch;

import net.minecraft.util.ResourceLocation;
Expand All @@ -37,13 +38,29 @@ public class CosmeticFactory {
@Getter
private final ShaderPatch blurShader;

private FakePlayerRender fakePlayerRender;

/** SkinChanger mod instance */
@Getter
private final SkinChangerMod mod;

public CosmeticFactory(SkinChangerMod mod) {
this.mod = mod;

// Blur shader magic
this.blurShader = new ShaderPatch(new ResourceLocation("skinchanger", "shaders/post/customblur.json"));
}

/**
* Returns the FakePlayer rendering class
*
* @return the fake player renderer
*/
public FakePlayerRender getFakePlayerRender() {
if (this.fakePlayerRender == null) {
this.fakePlayerRender = new FakePlayerRender(this);
}

return this.fakePlayerRender;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.do_you_like.mods.skinchanger.utils.gui.player;
package me.do_you_like.mods.skinchanger.cosmetic.impl.fakeplayer;

import com.mojang.authlib.GameProfile;

Expand All @@ -29,6 +29,7 @@
import net.minecraft.stats.StatBase;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

Expand All @@ -52,7 +53,7 @@ public FakePlayer() {
}

public FakePlayer(AbstractClientPlayer player) {
this(Minecraft.getMinecraft().thePlayer.worldObj);
this(player.worldObj);

getPlayerInfo().setLocationSkin(player.getLocationSkin());
getPlayerInfo().setLocationCape(player.getLocationCape());
Expand Down Expand Up @@ -133,6 +134,19 @@ public void copyFrom(AbstractClientPlayer player) {
getPlayerInfo().setLocationCape(player.getLocationCape());
getPlayerInfo().setSkinType(player.getSkinType());
}

/**
* Copies resources from an external source
*
* @param skin the skin resource
* @param cape the cape resource
* @param skinType the skin type
*/
public void copyFrom(ResourceLocation skin, ResourceLocation cape, String skinType) {
getPlayerInfo().setLocationSkin(skin);
getPlayerInfo().setLocationCape(cape);
getPlayerInfo().setSkinType((skinType == null || skinType.trim().isEmpty()) ? "default" : skinType);
}

public GameProfile getFakeGameProfile() {
return FAKE_GAME_PROFILE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.do_you_like.mods.skinchanger.utils.gui.player;
package me.do_you_like.mods.skinchanger.cosmetic.impl.fakeplayer;

import com.google.common.base.Objects;

Expand Down Expand Up @@ -86,6 +86,10 @@ public String getSkinType() {
}

public void setSkinType(String skinType) {
if (skinType == null || skinType.trim().isEmpty()) {
skinType = "default";
}

this.skinType = skinType;
}

Expand Down
Loading

0 comments on commit c621f20

Please sign in to comment.