Skip to content

Commit

Permalink
Some code improvements, bug fixes, plus other things I think?
Browse files Browse the repository at this point in the history
  • Loading branch information
sinender committed May 29, 2024
1 parent e674df9 commit a9ead0a
Show file tree
Hide file tree
Showing 30 changed files with 754 additions and 253 deletions.
1 change: 0 additions & 1 deletion src/main/java/llc/redstone/hysentials/Hysentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public class Hysentials {
private final ChatHandler chatHandler = new ChatHandler();

public final GuiDisplayHandler guiDisplayHandler = new GuiDisplayHandler();
public final CosmeticManager cosmeticManager = new CosmeticManager();
public static List<ICommand> commands;

public ModAPIHandler hypixelModAPI;
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/llc/redstone/hysentials/command/ClubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,20 @@ public void dashboard() {
UChat.chat("&cYou must be linked to a Discord account to use this feature.");
return;
}
try {
String s = NetworkUtils.getString(getHYSENTIALS_API() + "/club?uuid="
+ Minecraft.getMinecraft().getSession().getProfile().getId().toString()
+ "&key=" + Socket.serverId);
JsonObject clubData = new JsonParser().parse(s).getAsJsonObject();
if (!clubData.get("success").getAsBoolean()) {
UChat.chat(HysentialsConfig.chatPrefix + " &c" + clubData.get("message").getAsString());
return;
Multithreading.runAsync(() -> {
try {
String s = NetworkUtils.getString(getHYSENTIALS_API() + "/club?uuid="
+ Minecraft.getMinecraft().getSession().getProfile().getId().toString()
+ "&key=" + Socket.serverId);
JsonObject clubData = new JsonParser().parse(s).getAsJsonObject();
if (!clubData.get("success").getAsBoolean()) {
UChat.chat(HysentialsConfig.chatPrefix + " &c" + clubData.get("message").getAsString());
return;
}
new ClubDashboard(clubData).open(Minecraft.getMinecraft().thePlayer);
} catch (Exception e) {
e.printStackTrace();
}
new ClubDashboard(clubData).open(Minecraft.getMinecraft().thePlayer);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package llc.redstone.hysentials.command;

import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.pages.ModConfigPage;
import cc.polyfrost.oneconfig.gui.pages.ModsPage;
import cc.polyfrost.oneconfig.libs.universal.UChat;
import cc.polyfrost.oneconfig.libs.universal.wrappers.message.UTextComponent;
import cc.polyfrost.oneconfig.utils.Multithreading;
import cc.polyfrost.oneconfig.utils.NetworkUtils;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import com.google.gson.JsonArray;
import llc.redstone.hysentials.Hysentials;
import llc.redstone.hysentials.HysentialsUtilsKt;
Expand Down Expand Up @@ -94,7 +98,12 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
}

case "config": {
Hysentials.INSTANCE.getConfig().openGui();
ModConfigPage page = new ModConfigPage(Hysentials.INSTANCE.getConfig().mod.defaultPage);
ModsPage page2 = new ModsPage();
page.parents.add(page2);
page.parents.add(page);

GuiUtils.displayScreen(new OneConfigGui(page));
break;
}

Expand Down Expand Up @@ -255,7 +264,7 @@ public static void handleLeaderboard(String command, String[] args) {
break;
}
default: {
UChat.chat(HysentialsConfig.chatPrefix + " §cUnknown leaderboard type! Use /hysentials leaderboard <level/emeralds/settings> for a list of types.");
UChat.chat(HysentialsConfig.chatPrefix + " §cUnknown leaderboard type! Use /hysentials leaderboard <levels/emeralds/settings> for a list of types.");
break;

}
Expand Down Expand Up @@ -344,7 +353,7 @@ public void helpPage(int page) {
text.appendText("&e/hysentials online &7- &bShows the online players.\n");
text.appendText("&e/hysentials menu &7- &bOpens the Hysentials menu.\n");
text.appendText("&e/hysentials discord &7- &bShows the discord invite link.\n");
text.appendText("&e/hysentials leaderboard <level/emeralds/settings> &7- Leaderboard.\n");
text.appendText("&e/hs leaderboard <levels/emeralds/settings> &7- &bLeaderboard.\n");
text.appendText("§9&m ");
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static java.lang.Thread.sleep;

public abstract class AbstractCosmetic <E extends Entity>{
public static List<Cosmetic> cosmetics = new ArrayList<>();
private final boolean selfOnly;

public AbstractCosmetic(boolean selfOnly) {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/llc/redstone/hysentials/cosmetics/Cosmetic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package llc.redstone.hysentials.cosmetics;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;

import java.util.ArrayList;
import java.util.List;

public interface Cosmetic {
boolean canUse(EntityPlayer player);
ModelBase getModel();
ResourceLocation getTexture();
String getName();

default void renderPreview(int x, int y, int ticks) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (!canUse(player)) return;
Minecraft.getMinecraft().getTextureManager().bindTexture(getTexture());
GlStateManager.pushMatrix();

GlStateManager.rotate(toRadians(ticks /20f), 0f, 1.0F, 0.0F);
// GlStateManager.translate(x, y, 0);
float n = 1;
GlStateManager.scale(n, n, n);

getModel().render(player, 0, 0, 0, 0, 0, n);

GlStateManager.popMatrix();
}

default float toRadians(float degrees) {
return (float) (degrees * (Math.PI / 180));
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
package llc.redstone.hysentials.cosmetics.backpack;

import llc.redstone.hysentials.cosmetic.CosmeticGui;
import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt;
import llc.redstone.hysentials.cosmetic.CosmeticManager;
import llc.redstone.hysentials.cosmetics.AbstractCosmetic;
import llc.redstone.hysentials.cosmetics.Cosmetic;
import llc.redstone.hysentials.cosmetics.hats.cat.CatHat;
import llc.redstone.hysentials.cosmetics.hats.cat.CatModel;
import llc.redstone.hysentials.cosmetic.CosmeticGui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;

import java.util.ArrayList;
import java.util.List;

public class BackpackCosmetic {
public class BackpackCosmetic implements Cosmetic {
public static List<BackpackCosmetic> backpacks = new ArrayList<>();
boolean catpack;
BackpackModel model;
CatPackModel catModel;
String name;
ResourceLocation texture;
public BackpackCosmetic(String name, boolean catpack) {
this.catpack = catpack;
if (catpack) {
catModel = new CatPackModel();
} else {
model = new BackpackModel();
}
this.name = name;
texture = new ResourceLocation("hysentials:backpacks/" + name + ".png");
AbstractCosmetic.cosmetics.add(this);
}
public boolean canUse(EntityPlayer player) {
return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), name)
&& CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), name);
return CosmeticManager.equippedCosmetic(player.getUniqueID(), name)
&& CosmeticManager.hasCosmetic(player.getUniqueID(), name);
}

public ModelBase getModel() {
return catpack ? catModel : model;
}

public ResourceLocation getTexture() {
return texture;
}

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

public static void loadBackpacks() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package llc.redstone.hysentials.cosmetics.capes;

import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt;
import llc.redstone.hysentials.cosmetic.CosmeticManager;
import llc.redstone.hysentials.schema.HysentialsSchema;
import llc.redstone.hysentials.websocket.Socket;
import net.minecraft.client.Minecraft;
Expand All @@ -25,11 +25,11 @@ public void onTickEvent(TickEvent.ClientTickEvent event) {
for (String id : Socket.cachedUsers.keySet()) {
UUID uuid = UUID.fromString(id);
boolean wearingCape = false;
for (HysentialsSchema.Cosmetic cosmetic : CosmeticUtilsKt.getEquippedCosmetics(uuid)) {
for (HysentialsSchema.Cosmetic cosmetic : CosmeticManager.getEquippedCosmetics(uuid)) {
if (cosmetic.getSubType() != null && cosmetic.getSubType().equals("cape")) {
wearingCape = true;
String name = cosmetic.getName();
if (CosmeticUtilsKt.hasCosmetic(uuid, name)) {
if (CosmeticManager.hasCosmetic(uuid, name)) {
ResourceLocation location = new ResourceLocation(cosmetic.getResource());
resourceMap.put(uuid, cosmetic.getResource());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,36 @@

import cc.polyfrost.oneconfig.libs.universal.UChat;
import llc.redstone.hysentials.cosmetic.CosmeticGui;
import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt;
import llc.redstone.hysentials.cosmetic.CosmeticManager;
import llc.redstone.hysentials.cosmetics.AbstractCosmetic;
import llc.redstone.hysentials.cosmetics.Cosmetic;
import llc.redstone.hysentials.util.BUtils;
import llc.redstone.hysentials.websocket.Socket;
import llc.redstone.hysentials.cosmetic.CosmeticGui;
import llc.redstone.hysentials.cosmetics.AbstractCosmetic;
import llc.redstone.hysentials.util.BUtils;
import llc.redstone.hysentials.websocket.Socket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityArmorStand;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class CubitCompanion extends AbstractCosmetic<EntityCubit> {
public class CubitCompanion extends AbstractCosmetic<EntityCubit> implements Cosmetic {
private Map<UUID, EntityCubit> cubits = new HashMap<>();
private CubitModel model = new CubitModel();

public CubitCompanion() {
super(false);
AbstractCosmetic.cosmetics.add(this);
}

@Override
Expand All @@ -34,11 +41,26 @@ public Map<UUID, EntityCubit> getEntities() {

@Override
public boolean canUse(EntityPlayer player) {
return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "cubit")
&& CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "cubit")
return CosmeticManager.equippedCosmetic(player.getUniqueID(), "cubit")
&& CosmeticManager.hasCosmetic(player.getUniqueID(), "cubit")
&& !player.isInvisible();
}

@Override
public ModelBase getModel() {
return model;
}

@Override
public ResourceLocation getTexture() {
return new ResourceLocation("hysentials:pets/cubit.png");
}

@Override
public String getName() {
return "cubit";
}

public static long cooldown = 0;
@Override
public void interact(EntityCubit entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,30 @@
package llc.redstone.hysentials.cosmetics.hamster;

import llc.redstone.hysentials.cosmetic.CosmeticGui;
import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt;
import llc.redstone.hysentials.cosmetic.CosmeticManager;
import llc.redstone.hysentials.cosmetics.AbstractCosmetic;
import llc.redstone.hysentials.cosmetics.Cosmetic;
import llc.redstone.hysentials.event.InvokeEvent;
import llc.redstone.hysentials.cosmetic.CosmeticGui;
import llc.redstone.hysentials.cosmetics.AbstractCosmetic;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityArmorStand;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import java.util.*;

public class HamsterCompanion extends AbstractCosmetic<EntityHamster> {
public class HamsterCompanion extends AbstractCosmetic<EntityHamster> implements Cosmetic {
private Map<UUID, EntityHamster> hamsters = new HashMap<>();
private HamsterModel model = new HamsterModel();

public HamsterCompanion() {
super(false);
AbstractCosmetic.cosmetics.add(this);
}


Expand Down Expand Up @@ -65,11 +70,26 @@ public Map<UUID, EntityHamster> getEntities() {

@Override
public boolean canUse(EntityPlayer player) {
return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "hamster")
&& CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "hamster")
return CosmeticManager.equippedCosmetic(player.getUniqueID(), "hamster")
&& CosmeticManager.hasCosmetic(player.getUniqueID(), "hamster")
&& !player.isInvisible();
}

@Override
public ModelBase getModel() {
return model;
}

@Override
public ResourceLocation getTexture() {
return new ResourceLocation("hysentials:pets/hamsterbrown.png");
}

@Override
public String getName() {
return "hamster";
}

@Override
public void interact(EntityHamster entity) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
package llc.redstone.hysentials.cosmetics.hats.blackcat;

import llc.redstone.hysentials.cosmetic.CosmeticGui;
import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt;
import llc.redstone.hysentials.cosmetic.CosmeticManager;
import llc.redstone.hysentials.cosmetics.AbstractCosmetic;
import llc.redstone.hysentials.cosmetics.Cosmetic;
import llc.redstone.hysentials.cosmetics.hats.technocrown.TechnoCrownModel;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;

public class BlackCat {
public class BlackCat implements Cosmetic {
BlackCatModel model;
public BlackCat() {
model = new BlackCatModel();
AbstractCosmetic.cosmetics.add(this);
}
public boolean canUse(EntityPlayer player) {
return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "black cat")
&& CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "black cat");
return CosmeticManager.equippedCosmetic(player.getUniqueID(), "black cat")
&& CosmeticManager.hasCosmetic(player.getUniqueID(), "black cat");
}

public BlackCatModel getModel() {
return model;
}

public ResourceLocation getTexture() {
return new ResourceLocation("hysentials:hats/blackcat.png");
}

@Override
public String getName() {
return "black cat";
}
}
Loading

0 comments on commit a9ead0a

Please sign in to comment.