-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from eaglerforge/main
add self-compile instructions to documentation
- Loading branch information
Showing
10 changed files
with
246 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Compiling Eaglercraft with support for EFI | ||
In recent updates of eaglercraft, compiling for EaglerForgeInjector has become a great deal more complicated. To enable reflection and disable obfuscation, follow these steps once you have an EaglercraftX workspace set up: | ||
|
||
|
||
1. In any files named `build.gradle`, set the `obfuscate` property to `false`. | ||
2. In any files named `build.gradle`, find any code that looks like this: | ||
```javascript | ||
tasks.named("generateJavaScript") { | ||
doLast { | ||
|
||
// NOTE: This step may break at any time, and is not required for 99% of browsers | ||
|
||
def phile = file(folder + "/" + name) | ||
def dest = phile.getText("UTF-8") | ||
def i = dest.substring(0, dest.indexOf("=\$rt_globals.Symbol('jsoClass');")).lastIndexOf("let ") | ||
dest = dest.substring(0, i) + "var" + dest.substring(i + 3) | ||
def j = dest.indexOf("function(\$rt_globals,\$rt_exports){") | ||
dest = dest.substring(0, j + 34) + "\n" + file(folder + "/ES6ShimScript.txt").getText("UTF-8") + "\n" + dest.substring(j + 34) | ||
phile.write(dest, "UTF-8") | ||
} | ||
} | ||
``` | ||
and delete it. | ||
3. Inside of the `src/teavm/java/net/lax1dude/eaglercraft/v1_8/internal/teavm/` folder, create a new file called `ForceReflection.java`, with these contents: | ||
```java | ||
package net.lax1dude.eaglercraft.v1_8.internal.teavm; | ||
public class ForceReflection { | ||
public static Object myObject; | ||
public static Object forceInit(Class iClass) { | ||
myObject = new ReflectiveClass(); | ||
try { | ||
myObject = iClass.newInstance(); | ||
} catch (Exception e) { | ||
// TODO: handle exception | ||
} | ||
return myObject; | ||
} | ||
public static class ReflectiveClass { | ||
} | ||
} | ||
``` | ||
4. In the same folder, edit `MainClass.java` edit the start of the `main(String[] args)` method to look like this: | ||
```java | ||
public static void main(String[] args) { | ||
ForceReflection.forceInit(ForceReflection.class); | ||
if(args.length == 1) { | ||
//... rest of method | ||
``` | ||
5. Finally, build an offline download by using `CompileJS.bat`/`CompileJS.sh` and then `MakeOfflineDownload.bat`/`MakeOfflineDownload.sh`. | ||
6. You can then upload the `EaglercraftX_1.8_Offline_en_US.html` into EaglerForgeInjector. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(function AddDiamondRecipe() { | ||
ModAPI.meta.title("DiamondCraftingRecipeMod"); | ||
ModAPI.meta.description("Adds a crafting recipe to create diamond blocks from dirt."); | ||
|
||
async function addDiamondRecipe() { | ||
await new Promise((res,rej)=>{var x = setInterval(()=>{if(ModAPI.blocks){clearInterval(x);res();}}, 100);}) | ||
var ObjectClass = ModAPI.reflect.getClassById("java.lang.Object").class; | ||
function ToChar(char) { | ||
return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0)); | ||
} | ||
|
||
// Define the recipe legend to map characters to items | ||
var recipeLegend = { | ||
"D": { | ||
type: "block", | ||
id: "dirt" // Using dirt blocks | ||
} | ||
}; | ||
|
||
// Define the crafting grid pattern for the recipe | ||
var recipePattern = [ | ||
"DDD", | ||
"DDD", | ||
"DDD" | ||
]; | ||
|
||
// Convert the recipe pattern and legend into the required format | ||
var recipeInternal = []; | ||
Object.keys(recipeLegend).forEach((key) => { | ||
recipeInternal.push(ToChar(key)); | ||
var ingredient = ModAPI.blocks[recipeLegend[key].id].getRef(); | ||
recipeInternal.push(ingredient); | ||
}); | ||
|
||
var recipeContents = recipePattern.flatMap(row => ModAPI.util.str(row)); | ||
var recipe = ModAPI.util.makeArray(ObjectClass, recipeContents.concat(recipeInternal)); | ||
|
||
// Define the output item as diamond_block | ||
var resultItem = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[1](ModAPI.blocks["diamond_block"].getRef(), 1); | ||
|
||
|
||
|
||
// Register the recipe with CraftingManager | ||
var craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method(); | ||
ModAPI.hooks.methods.nmic_CraftingManager_addRecipe(craftingManager, resultItem, recipe); | ||
} | ||
|
||
ModAPI.dedicatedServer.appendCode(addDiamondRecipe); | ||
|
||
addDiamondRecipe(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// This is an example mod on how to register an item. | ||
(()=>{ | ||
const itemTexture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAKZJREFUOE9j/P//PxMDBIBoEP6HREOl4PLIciA2AyPIgMcM//7KgvWSDJjBBpx9/+YvJzc3Sbq12DhB6sEGsJ19/+YnmQawYhigzc7FcPXnN4KugbqAHWQAy9n3b34T4wJkw6EGYLqAoNVQBWS5ANlwZBfAvUCs/0EGkW0AzBKqGoCSDgh5A80F2KMRpAgfAKUT6kcjsfEPUycmKMQgy8AETkgUZWcAS3CPIf4oSPsAAAAASUVORK5CYII="; | ||
//this texture is really baad, so the item appears 2d in game. | ||
ModAPI.meta.title("Adding items demo."); | ||
ModAPI.meta.version("v1.0"); | ||
ModAPI.meta.icon(itemTexture); | ||
ModAPI.meta.description("Requires AsyncSink."); | ||
|
||
function ExampleItem() { | ||
var creativeMiscTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabMisc; | ||
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item"); | ||
var itemSuper = ModAPI.reflect.getSuper(itemClass, (x) => x.length === 1); | ||
var nmi_ItemExample = function nmi_ItemExample() { | ||
itemSuper(this); //Use super function to get block properties on this class. | ||
this.$setCreativeTab(creativeMiscTab); | ||
} | ||
ModAPI.reflect.prototypeStack(itemClass, nmi_ItemExample); | ||
nmi_ItemExample.prototype.$onItemRightClick = function ($itemstack, $world, $player) { //example of how to override a method | ||
return $itemstack; | ||
} | ||
|
||
function internal_reg() { | ||
var example_item = (new nmi_ItemExample()).$setUnlocalizedName( | ||
ModAPI.util.str("exampleitem") | ||
); | ||
itemClass.staticMethods.registerItem0.method(432, ModAPI.util.str("exampleitem"), example_item); | ||
ModAPI.items["exampleitem"] = example_item; | ||
|
||
return example_item; | ||
} | ||
|
||
if (ModAPI.items) { | ||
return internal_reg(); | ||
} else { | ||
ModAPI.addEventListener("bootstrap", internal_reg); | ||
} | ||
} | ||
|
||
ModAPI.dedicatedServer.appendCode(ExampleItem); | ||
var example_item = ExampleItem(); | ||
|
||
ModAPI.addEventListener("lib:asyncsink", async () => { | ||
ModAPI.addEventListener("custom:asyncsink_reloaded", ()=>{ | ||
ModAPI.mc.renderItem.registerItem(example_item, ModAPI.util.str("exampleitem")); | ||
}); | ||
AsyncSink.L10N.set("item.exampleitem.name", "Example Item"); | ||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/exampleitem.json", JSON.stringify( | ||
{ | ||
"parent": "builtin/generated", | ||
"textures": { | ||
"layer0": "items/exampleitem" | ||
}, | ||
"display": { | ||
"thirdperson": { | ||
"rotation": [ -90, 0, 0 ], | ||
"translation": [ 0, 1, -3 ], | ||
"scale": [ 0.55, 0.55, 0.55 ] | ||
}, | ||
"firstperson": { | ||
"rotation": [ 0, -135, 25 ], | ||
"translation": [ 0, 4, 2 ], | ||
"scale": [ 1.7, 1.7, 1.7 ] | ||
} | ||
} | ||
} | ||
)); | ||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/textures/items/exampleitem.png", await (await fetch( | ||
itemTexture | ||
)).arrayBuffer()); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters