Skip to content

Commit

Permalink
Update 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Mar 15, 2023
1 parent e486823 commit 801508d
Show file tree
Hide file tree
Showing 19 changed files with 288 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.fox2code.foxloader.client.gui;

import net.minecraft.src.client.gui.FontRenderer;
import net.minecraft.src.client.gui.GuiButton;
import net.minecraft.src.client.gui.GuiScreen;
import net.minecraft.src.client.gui.StringTranslate;

public class GuiModList extends GuiScreen {
private final GuiScreen parent;
private GuiModListContainer modListContainer;

public GuiModList(GuiScreen parent) {
this.parent = parent;
}

@Override
public void initGui() {
super.initGui();
this.modListContainer = new GuiModListContainer(this);
this.modListContainer.registerScrollButtons(this.controlList, 4, 5);
this.controlList.add(new GuiButton(0,
this.width / 2 + 4, this.height - 28, 150, 20,
StringTranslate.getInstance().translateKey("gui.cancel")));
}

@Override
public void drawScreen(int var1, int var2, float deltaTicks) {
this.modListContainer.drawScreen(var1, var2, deltaTicks);
super.drawScreen(var1, var2, deltaTicks);
}

@Override
protected void actionPerformed(GuiButton var1) {
if (var1.id == 0) {
this.mc.displayGuiScreen(this.parent);
return;
}
this.modListContainer.actionPerformed(var1);
}

public FontRenderer getFontRenderer() {
return this.fontRenderer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.fox2code.foxloader.client.gui;

import com.fox2code.foxloader.loader.ModContainer;
import com.fox2code.foxloader.loader.ModLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.src.client.gui.GuiSlot;
import net.minecraft.src.client.renderer.Tessellator;

public class GuiModListContainer extends GuiSlot {
private final GuiModList guiModList;
private final ModContainer[] mods;
private int selected = 0;

public GuiModListContainer(GuiModList guiModList) {
super(Minecraft.theMinecraft,
guiModList.width,
guiModList.height, 32,
guiModList.height - 64, 36);
this.guiModList = guiModList;
this.mods = ModLoader.getModContainers().toArray(new ModContainer[0]);
}

@Override
protected int getSize() {
return this.mods.length;
}

@Override
protected void elementClicked(int i, boolean b) {
this.selected = i;
}

@Override
protected boolean isSelected(int i) {
return this.selected == i;
}

@Override
protected void drawBackground() {
this.guiModList.drawDefaultBackground();
}

@Override
protected void drawSlot(int i, int i1, int i2, int i3, Tessellator tessellator) {
ModContainer modContainer = this.mods[i];

String name = modContainer.name + " " + modContainer.version;
String id = modContainer.description;
String file = modContainer.getFileName() + " (id: " + modContainer.id + ")";

this.guiModList.drawString(this.guiModList.getFontRenderer(), name, i1 + 2, i2 + 1, 16777215);
this.guiModList.drawString(this.guiModList.getFontRenderer(), id, i1 + 2, i2 + 12, 8421504);
this.guiModList.drawString(this.guiModList.getFontRenderer(), file, i1 + 2, i2 + 12 + 10, 8421504);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.fox2code.foxloader.client.mixins;

import com.fox2code.foxloader.loader.ClientModLoader;
import net.minecraft.src.client.renderer.EntityRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EntityRenderer.class)
public class MixinEntityRenderer {
@Inject(method = "updateCameraAndRender", at = @At("RETURN"))
public void onCameraAndRenderUpdated(float partialTick, CallbackInfo ci) {
ClientModLoader.Internal.notifyCameraAndRenderUpdated(partialTick);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package com.fox2code.foxloader.client.mixins;

import com.fox2code.foxloader.client.gui.GuiModList;
import com.fox2code.foxloader.launcher.BuildConfig;
import net.minecraft.src.client.gui.GuiMainMenu;
import net.minecraft.src.client.gui.GuiScreen;
import net.minecraft.src.client.gui.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GuiMainMenu.class)
public abstract class MixinGuiMainMenu extends GuiScreen {
@Inject(method = "initGui", at = @At(value = "RETURN"))
public void onInitGui(CallbackInfo ci) {
this.controlList.add(new GuiSmallButton(500, this.width - 61, 25, 60, 20, "Mods"));
}

@Inject(method = "actionPerformed", at = @At(value = "HEAD"), cancellable = true)
public void onActionPerformed(GuiButton var1, CallbackInfo ci) {
if (var1.id == 500) {
this.mc.displayGuiScreen(new GuiModList(this));
ci.cancel();
}
}

@Inject(method = "drawScreen", at = @At(value = "INVOKE",
target = "Lnet/minecraft/src/client/gui/GuiScreen;drawScreen(IIF)V"))
public void onDrawGuiScreen(int n, int n2, float deltaTicks, CallbackInfo ci) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,11 @@ public static void notifyRun() {
// StatList.initStats();
PlayerCommandHandler.instance.reloadCommands();
}

public static void notifyCameraAndRenderUpdated(float partialTick) {
for (ModContainer modContainer : ModLoader.modContainers.values()) {
modContainer.notifyCameraAndRenderUpdated(partialTick);
}
}
}
}
1 change: 1 addition & 0 deletions client/src/main/resources/foxloader.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"MixinContainerCreative",
"MixinEntityClientPlayerMP",
"MixinEntityPlayerSP",
"MixinEntityRenderer",
"MixinGuiChat",
"MixinGuiContainer",
"MixinGuiDebug",
Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static void generateBuildConfig0(File buildConfigSrc, Project project) {
project['foxloader.lastReIndevTransformerChanges']
final String FOXLOADER_VERSION = project['foxloader.version']
final String SPARK_DEPENDENCY = project['spark.dependency']
final String SPARK_VERSION = project['spark.version']
final String REINDEV_VERSION = project['reindev.version']
final String CLIENT_URL = project['reindev.clientUrl']
final String SERVER_URL = project['reindev.serverUrl']
Expand All @@ -46,6 +47,7 @@ static void generateBuildConfig0(File buildConfigSrc, Project project) {
FOXLOADER_TRANSFORMER_VERSION + "\";")
printStream.println(" public static final String FOXLOADER_VERSION = \"" + FOXLOADER_VERSION + "\";")
printStream.println(" public static final String SPARK_DEPENDENCY = \"" + SPARK_DEPENDENCY + "\";")
printStream.println(" public static final String SPARK_VERSION = \"" + SPARK_VERSION + "\";")
printStream.println(" public static final String REINDEV_VERSION = \"" + REINDEV_VERSION + "\";")
printStream.println(" public static final String CLIENT_URL = \"" + CLIENT_URL + "\";")
printStream.println(" public static final String SERVER_URL = \"" + SERVER_URL + "\";")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fox2code.foxloader.launcher.utils;

import com.fox2code.foxloader.launcher.FoxLauncher;

import java.io.File;
import java.net.URISyntaxException;

Expand All @@ -13,4 +15,12 @@ public static File getSourceFile(Class<?> cls) {
throw new RuntimeException(e);
}
}

public static File getSourceFileOfClassName(String cls) {
try {
return getSourceFile(Class.forName(cls, false, FoxLauncher.getFoxClassLoader()));
} catch (ClassNotFoundException e) {
return null;
}
}
}
35 changes: 35 additions & 0 deletions common/src/main/java/com/fox2code/foxloader/loader/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public void onPostInit() {}
*/
public void onTick() {}

/**
* Called when camera and render updated! (Only called client side)
*/
public void onCameraAndRenderUpdated(float partialTick) {}

/**
* When server receive client packet.
*/
Expand Down Expand Up @@ -86,6 +91,36 @@ public void onServerStop(NetworkPlayer.ConnectionType connectionType) {}

// GameRegistry mirror

/**
* @see GameRegistry#getRegisteredItem(int)
*/
public RegisteredItem getRegisteredItem(int id) {
return GameRegistry.getInstance().getRegisteredItem(id);
}

/**
* @see GameRegistry#getRegisteredItem(String)
*/
public RegisteredItem getRegisteredItem(String name) {
if (name.indexOf(':') == -1) name = getModContainer().id + ":" + name;
return GameRegistry.getInstance().getRegisteredItem(name);
}

/**
* @see GameRegistry#getRegisteredBlock(int)
*/
public RegisteredBlock getRegisteredBlock(int id) {
return GameRegistry.getInstance().getRegisteredBlock(id);
}

/**
* @see GameRegistry#getRegisteredBlock(String)
*/
public RegisteredBlock getRegisteredBlock(String name) {
if (name.indexOf(':') == -1) name = getModContainer().id + ":" + name;
return GameRegistry.getInstance().getRegisteredBlock(name);
}

/**
* @see GameRegistry#registerNewItem(String, ItemBuilder)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class ModContainer {
public final String id;
public final String name;
public final String version;
public final String description;
public final Logger logger;
private final boolean injected;
String prePatch;
Expand All @@ -38,11 +39,12 @@ public final class ModContainer {
String clientModCls;
String clientMixins;

ModContainer(File file, String id, String name, String version, boolean injected) {
ModContainer(File file, String id, String name, String version, String description, boolean injected) {
this.file = file;
this.id = id;
this.name = name;
this.version = version;
this.description = description;
this.logger = Logger.getLogger(name);
this.injected = injected;
if (ModLoader.DEV_MODE) {
Expand All @@ -68,6 +70,10 @@ public Mod getMod() {
return mod != null ? mod : commonMod;
}

public String getFileName() {
return this.file == null ? "built-in" : this.file.getName();
}

void applyPrePatch() throws ReflectiveOperationException {
if (prePatch != null) {
PreClassTransformer preClassTransformer =
Expand Down Expand Up @@ -217,4 +223,13 @@ void notifyOnTick() {
if (serverMod != null)
serverMod.onTick();
}

void notifyCameraAndRenderUpdated(float partialTick) {
if (commonMod != null)
commonMod.onCameraAndRenderUpdated(partialTick);
if (clientMod != null)
clientMod.onCameraAndRenderUpdated(partialTick);
if (serverMod != null)
serverMod.onCameraAndRenderUpdated(partialTick);
}
}
24 changes: 20 additions & 4 deletions common/src/main/java/com/fox2code/foxloader/loader/ModLoader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fox2code.foxloader.loader;

import com.fox2code.foxloader.launcher.*;
import com.fox2code.foxloader.launcher.utils.SourceUtil;
import com.fox2code.foxloader.loader.packet.ServerHello;
import com.fox2code.foxloader.loader.rebuild.ClassDataProvider;
import com.fox2code.foxloader.network.NetworkPlayer;
Expand Down Expand Up @@ -30,8 +31,8 @@ public class ModLoader {
public static final String FOX_LOADER_MOD_ID = "foxloader";
public static final String FOX_LOADER_VERSION = BuildConfig.FOXLOADER_VERSION;
static final ModContainer foxLoader = new ModContainer(
FoxLauncher.foxLoaderFile, FOX_LOADER_MOD_ID, "FoxLoader", FOX_LOADER_VERSION, false);
static final ModContainer spark = new ModContainer(null, "spark", "Spark", FOX_LOADER_VERSION, false);
FoxLauncher.foxLoaderFile, FOX_LOADER_MOD_ID, "FoxLoader", FOX_LOADER_VERSION,
"ReIndev mod loader with foxes!!!", false);
static final LinkedList<File> coreMods = new LinkedList<>();
// Use LinkedHashMap to keep track in which order mods were loaded.
static final LinkedHashMap<String, ModContainer> modContainers = new LinkedHashMap<>();
Expand All @@ -41,6 +42,7 @@ public class ModLoader {
private static final Attributes.Name MOD_ID = new Attributes.Name("ModId");
private static final Attributes.Name MOD_NAME = new Attributes.Name("ModName");
private static final Attributes.Name MOD_VERSION = new Attributes.Name("ModVersion");
private static final Attributes.Name MOD_DESC = new Attributes.Name("ModDesc");
private static final Attributes.Name PRE_PATCH = new Attributes.Name("PreClassTransformer");
private static final Attributes.Name CLIENT_MOD = new Attributes.Name("ClientMod");
private static final Attributes.Name SERVER_MOD = new Attributes.Name("ServerMod");
Expand Down Expand Up @@ -92,9 +94,12 @@ static void initializeModdedInstance(boolean client) {
if (DEV_MODE && INJECT_MOD != null && !INJECT_MOD.isEmpty()) {
loadModContainerFrom(new File(INJECT_MOD).getAbsoluteFile(), true);
}
if (!modContainers.containsKey(spark.id) && !disableSpark &&
if (!modContainers.containsKey("spark") && !disableSpark &&
DependencyHelper.loadDependencySafe(DependencyHelper.sparkDependency)) {
foxLoader.logger.info("Injecting spark using FoxLoader adapter.");
ModContainer spark = new ModContainer(SourceUtil.getSourceFileOfClassName(
"me.lucko.spark.common.SparkPlugin"), "spark", "Spark",
BuildConfig.SPARK_VERSION, "spark is a performance profiling mod.", false);
spark.clientModCls = "com.fox2code.foxloader.spark.FoxLoaderClientSparkPlugin";
spark.serverModCls = "com.fox2code.foxloader.spark.FoxLoaderServerSparkPlugin";
modContainers.put(spark.id, spark);
Expand Down Expand Up @@ -150,12 +155,16 @@ private static void loadModContainerFrom(File file, boolean injected) {
String id = attributes.getValue(MOD_ID);
String name = attributes.getValue(MOD_NAME);
String version = attributes.getValue(MOD_VERSION);
String desc = attributes.getValue(MOD_DESC);
if (id == null || id.isEmpty()) {
foxLoader.logger.warning("Unable to load " + file.getName() +
" because it doesn't have a mod-id (Is it a core mod?)");
return;
}
if (FOX_LOADER_MOD_ID.equals(id) || "minecraft".equals(id) || "reindev".equals(id) || "null".equals(id)) {
if (injected && "null".equals(id)) { // Crash directly if we
throw new RuntimeException("Please define a modId in gradle");
}
foxLoader.logger.warning("Unable to load " + file.getName() +
" because it used the reserved mod id: " + id);
return;
Expand All @@ -166,13 +175,16 @@ private static void loadModContainerFrom(File file, boolean injected) {
if (version == null) {
version = "1.0";
}
if (desc == null || desc.isEmpty()) {
desc = "...";
}
ModContainer modContainer = modContainers.get(id);
if (modContainer != null) {
foxLoader.logger.warning("Unable to load " + file.getName() + " because " +
modContainer.file.getName() + " already uses the same mod id: " + id);
return;
}
modContainer = new ModContainer(file, id, name, version, injected);
modContainer = new ModContainer(file, id, name, version, desc, injected);
modContainer.prePatch = attributes.getValue(PRE_PATCH);
modContainer.clientModCls = attributes.getValue(CLIENT_MOD);
modContainer.serverModCls = attributes.getValue(SERVER_MOD);
Expand All @@ -192,6 +204,10 @@ public static ModContainer getModContainer(String id) {
return modContainers.get(id);
}

public static Collection<ModContainer> getModContainers() {
return Collections.unmodifiableCollection(modContainers.values());
}

public static boolean areAllModsLoaded() {
return allModsLoaded;
}
Expand Down
Loading

0 comments on commit 801508d

Please sign in to comment.