Archive eaglerforge-injector (tool, 1.8.8, clean-with-notes)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
## Coming Soon / It's not done yet.
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,127 @@
|
||||
## Custom Item Tutorial with ModAPI
|
||||
This tutorial will cover making custom items with ModAPI. It is recommended that you follow the [custom block tutorial](custom_block.md) first, as this tutorial is more fast-paced. The custom item we'll be adding will set the player's velocity to a random value when used, to demonstrate how methods can be overridden.
|
||||
|
||||
We'll begin with a constant item texture encoded into a data URI, as well as some metadata.
|
||||
```javascript
|
||||
(function CustomItemMod() {
|
||||
const itemTexture = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAKZJREFUOE9j/P//PxMDBIBoEP6HREOl4PLIciA2AyPIgMcM//7KgvWSDJjBBpx9/+YvJzc3Sbq12DhB6sEGsJ19/+YnmQawYhigzc7FcPXnN4KugbqAHWQAy9n3b34T4wJkw6EGYLqAoNVQBWS5ANlwZBfAvUCs/0EGkW0AzBKqGoCSDgh5A80F2KMRpAgfAKUT6kcjsfEPUycmKMQgy8AETkgUZWcAS3CPIf4oSPsAAAAASUVORK5CYII=";
|
||||
|
||||
ModAPI.meta.title("Custom Item Mod");
|
||||
ModAPI.meta.icon(itemTexture);
|
||||
ModAPI.meta.description("it's a custom item. what more do you want");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
})();
|
||||
```
|
||||
|
||||
Add a function that will contain the code to register the item called `CustomItem`. Inside it we'll do something really similar to the custom blocks tutorial, where we'll define a custom item class, and then register it (or, if on the server, wait until the `bootstrap` event fires). The reason it's contained in a function is to make the job of running the same code on the server and client easier.
|
||||
|
||||
```javascript
|
||||
(function CustomItemMod() {
|
||||
//...
|
||||
|
||||
function CustomItem() {
|
||||
var creativeMiscTab = ModAPI.reflect.getClassById("net.minecraft.creativetab.CreativeTabs").staticVariables.tabMisc; //chuck it in the miscellaneous category ig
|
||||
var itemClass = ModAPI.reflect.getClassById("net.minecraft.item.Item"); //Get the item class
|
||||
var itemSuper = ModAPI.reflect.getSuper(itemClass, (x) => x.length === 1); //Get the super() function of the item class that has a length of 1
|
||||
function CustomItem() {
|
||||
itemSuper(this); //Use super function to get block properties on this class.
|
||||
this.$setCreativeTab(creativeMiscTab); //Set the creative tab of the item to be the misc tab
|
||||
}
|
||||
ModAPI.reflect.prototypeStack(itemClass, CustomItem); // ModAPI equivalent of `extends` in java
|
||||
CustomItem.prototype.$onItemRightClick = function ($itemstack, $world, $player) { //example of how to override a method
|
||||
//use ModAPI.util.wrap to create a proxy of the player and the world without $ prefixes on the properties and methods
|
||||
var player = ModAPI.util.wrap($player);
|
||||
var world = ModAPI.util.wrap($world);
|
||||
|
||||
if (!world.isRemote) { //If we are on the server
|
||||
// Math.random() returns a number from 0.0 to 1.0, so we subtract 0.5 and then multiply by 2 to make it become -1.0 to 1.0 instead
|
||||
player.motionX += (Math.random() - 0.5) * 3;
|
||||
player.motionZ += (Math.random() - 0.5) * 3;
|
||||
|
||||
player.motionY += Math.random() * 1.5; // gravity is a thing, so no negative numbers here otherwise it'll be boring
|
||||
}
|
||||
|
||||
return $itemstack;
|
||||
}
|
||||
|
||||
// Internal registration function. This will be used to actually register the item on both the client and the server.
|
||||
function internal_reg() {
|
||||
// Construct an instance of the CustomItem, and set it's unlocalized name (translation id)
|
||||
var custom_item = (new CustomItem()).$setUnlocalizedName(
|
||||
ModAPI.util.str("custom_item")
|
||||
);
|
||||
//Register it using ModAPI.keygen() to get the item id.
|
||||
itemClass.staticMethods.registerItem.method(ModAPI.keygen.item("custom_item"), ModAPI.util.str("custom_item"), custom_item);
|
||||
|
||||
//Expose it to ModAPI
|
||||
ModAPI.items["custom_item"] = custom_item;
|
||||
|
||||
//return the instance.
|
||||
return custom_item;
|
||||
}
|
||||
|
||||
//if the item global exists (and it will on the client), register the item and return the registered instance.
|
||||
if (ModAPI.items) {
|
||||
return internal_reg();
|
||||
} else {
|
||||
//Otherwise attatch the registration method to the bootstrap method.
|
||||
ModAPI.addEventListener("bootstrap", internal_reg);
|
||||
}
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
Now let's run the `CustomItem` function on the server and the client, and then use [AsyncSink](../../examplemods/AsyncSink.js) to create an in-memory resource pack to load item textures and models!
|
||||
```javascript
|
||||
(function CustomItemMod() {
|
||||
const itemTexture = "...";
|
||||
|
||||
ModAPI.meta.title("Custom Item Mod");
|
||||
ModAPI.meta.icon(itemTexture);
|
||||
ModAPI.meta.description("it's a custom item. what more do you want");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
|
||||
function CustomItem() {
|
||||
// ...
|
||||
}
|
||||
|
||||
// Run the function when the dedicated server loads.
|
||||
ModAPI.dedicatedServer.appendCode(CustomItem);
|
||||
|
||||
// Run the function on the client
|
||||
var custom_item = CustomItem();
|
||||
|
||||
ModAPI.addEventListener("lib:asyncsink", async () => {
|
||||
ModAPI.addEventListener("lib:asyncsink:registeritems", (renderItem)=>{
|
||||
renderItem.registerItem(custom_item, ModAPI.util.str("custom_item"));
|
||||
});
|
||||
AsyncSink.L10N.set("item.custom_item.name", "Cool Custom Item");
|
||||
AsyncSink.setFile("resourcepacks/AsyncSinkLib/assets/minecraft/models/item/custom_item.json", JSON.stringify(
|
||||
{
|
||||
"parent": "builtin/generated",
|
||||
"textures": {
|
||||
"layer0": "items/custom_item"
|
||||
},
|
||||
"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/custom_item.png", await (await fetch(
|
||||
itemTexture
|
||||
)).arrayBuffer());
|
||||
});
|
||||
})();
|
||||
```
|
||||
|
||||
That's it! Upload your completed mod, run `.reload_tex` in chat in a singleplayer world and use your new item!\
|
||||
[completed mod]()
|
||||
@@ -0,0 +1,90 @@
|
||||
## Disable All Particles
|
||||
Particles in minecraft are really laggy, and there's a large chance you may want to disable them to boost your FPS when breaking blocks.
|
||||
|
||||
Let's look through the Eaglercraft 1.8 source code to find where particles are rendered. We can do this with a global search for `particle`. You'll find a lot of hits in the `EffectRenderer` class in the `net.minecraft.client.particle` package. We methods we'll want to patch are:
|
||||
- `renderParticles`
|
||||
- `addEffect`
|
||||
- `addBlockDestroyEffects`
|
||||
- `hasParticlesInAlphaLayer`
|
||||
|
||||
For the first 3 methods, you can see that they are defined something like:
|
||||
```java
|
||||
public void renderParticles() {
|
||||
// render particles code.
|
||||
}
|
||||
```
|
||||
The `void` in `public void` means that it does not expect a return value.
|
||||
Using [`ModAPI.util.getMethodFromPackage`](../apidoc/utils.md) we can find the compiled method name, and look for it in [`ModAPI.hooks.methods`](../apidoc/hooks.md#property-modapihooksmethods).
|
||||
|
||||
```javascript
|
||||
(function NoParticles() {
|
||||
//Basic, boilerplate code
|
||||
ModAPI.meta.title("No Particles");
|
||||
ModAPI.meta.description("Disables all particles in game");
|
||||
ModAPI.meta.credits("By <developer name>");
|
||||
|
||||
ModAPI.hooks.methods[
|
||||
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles")
|
||||
] = function () {}; //Override renderParticles in EffectRenderer to an empty function that does nothing.
|
||||
})();
|
||||
```
|
||||
|
||||
We can also do this for `addEffect` and `addBlockDestroyEffects`.
|
||||
|
||||
```javascript
|
||||
(function NoParticles() {
|
||||
//Basic, boilerplate code
|
||||
ModAPI.meta.title("No Particles");
|
||||
ModAPI.meta.description("Disables all particles in game");
|
||||
ModAPI.meta.credits("By <developer name>");
|
||||
|
||||
ModAPI.hooks.methods[
|
||||
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles")
|
||||
] = function () {}; //Override renderParticles in EffectRenderer with an empty function that does nothing.
|
||||
|
||||
ModAPI.hooks.methods[
|
||||
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addEffect")
|
||||
] = function () {}; //Override addEffect in EffectRenderer with an empty function that does nothing.
|
||||
|
||||
ModAPI.hooks.methods[
|
||||
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addBlockDestroyEffects")
|
||||
] = function () {}; //Override addBlockDestroyEffects in EffectRenderer with an empty function that does nothing.
|
||||
})();
|
||||
```
|
||||
|
||||
For `hasParticlesInAlphaLayer`, it doesn't use `void`, but instead a `boolean`.
|
||||
```java
|
||||
public boolean hasParticlesInAlphaLayer() {
|
||||
// hasParticlesInAlphaLayer code.
|
||||
}
|
||||
```
|
||||
When TeaVM translates booleans, it converts booleans to integers:
|
||||
- `false` turns into `0`
|
||||
- `true` turns into `1`
|
||||
|
||||
So when we override `hasParticlesInAlphaLayer`, we'll need to return a `0` or a `1`. Since we want the game to think that there aren't any particles in the alpha layer, we'll return `0` (false).
|
||||
|
||||
```javascript
|
||||
(function NoParticles() {
|
||||
//Basic, boilerplate code
|
||||
ModAPI.meta.title("No Particles");
|
||||
ModAPI.meta.description("Disables all particles in game");
|
||||
ModAPI.meta.credits("By <developer name>");
|
||||
|
||||
ModAPI.hooks.methods[
|
||||
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles")
|
||||
] = function () {}; //Override renderParticles in EffectRenderer with an empty function that does nothing.
|
||||
|
||||
ModAPI.hooks.methods[
|
||||
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addEffect")
|
||||
] = function () {}; //Override addEffect in EffectRenderer with an empty function that does nothing.
|
||||
|
||||
ModAPI.hooks.methods[
|
||||
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addBlockDestroyEffects")
|
||||
] = function () {}; //Override addBlockDestroyEffects in EffectRenderer with an empty function that does nothing.
|
||||
|
||||
ModAPI.hooks.methods[
|
||||
ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "hasParticlesInAlphaLayer")
|
||||
] = function () {return 0}; //Override hasParticlesInAlphaLayer in EffectRenderer with a function that returns 0.
|
||||
})();
|
||||
```
|
||||
@@ -0,0 +1,71 @@
|
||||
## /hat with ModAPI
|
||||
/hat is a common server-side plugin that lets you put any block/item on your head. This tutorial will explain how to register a server-side command, construct a packet, and send it to a player.
|
||||
[`S09PacketHeldItemChange` constructors](https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/network/play/server/S09PacketHeldItemChange.html)
|
||||
|
||||
|
||||
As always, start with the basic boilerplate IIFE with credits:
|
||||
```javascript
|
||||
(function HatMod() {
|
||||
ModAPI.meta.title("Hat Mod");
|
||||
ModAPI.meta.description("Use /hat to put anything on your head.");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
})();
|
||||
```
|
||||
In order to add a server side command, we need to:
|
||||
- Write a function to run on the server.
|
||||
- In this function, we'll add a listener to the [`processcommand` event](../apidoc/events.md#server-side-events)
|
||||
- We'll check if the command is `/hat`
|
||||
- If it is, we'll swap their head and current hand inventory slots, and send a network packet.
|
||||
- Finally, the function from step 1 is thrown into [`ModAPI.dedicatedServer.appendCode`](../apidoc/dedicatedserver.md)
|
||||
|
||||
Here's the completed code:
|
||||
```javascript
|
||||
(function HatMod() {
|
||||
ModAPI.meta.title("Hat Mod");
|
||||
ModAPI.meta.description("Use /hat to put anything on your head.");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
|
||||
ModAPI.dedicatedServer.appendCode(function serverSideCode() {
|
||||
// Find the constructor for the held item change packet that has only one argument.
|
||||
// This will be used to notify the client that their hotbar has been updated.
|
||||
// Reference: https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/network/play/server/S09PacketHeldItemChange.html
|
||||
var S09PacketHeldItemChange_Constructor = ModAPI.reflect.getClassByName("S09PacketHeldItemChange").constructors.find(x => x.length === 1);
|
||||
|
||||
//Add an event listener for when a command is processed on the server.
|
||||
ModAPI.addEventListener("processcommand", (event) => {
|
||||
// If the command starts with /hat
|
||||
if (event.command.toLowerCase().startsWith("/hat")) {
|
||||
// Exit if the sender isn't a player
|
||||
if (
|
||||
!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP").instanceOf(
|
||||
event.sender.getRef()
|
||||
)
|
||||
) {
|
||||
return
|
||||
};
|
||||
|
||||
// Get the current held item
|
||||
var heldItem = event.sender.inventory.getCurrentItem();
|
||||
|
||||
// Get the contents of the helmet slot
|
||||
var armorItem = event.sender.inventory.armorInventory[3];
|
||||
|
||||
// Get the inventory index of the current held item
|
||||
var hotbarIdx = event.sender.inventory.currentItem;
|
||||
|
||||
// Set the helmet slot to heldItem.getRef() (raw java object) if heldItem exists, otherwise set it to null
|
||||
event.sender.inventory.armorInventory[3] = heldItem ? heldItem.getRef() : null;
|
||||
|
||||
// Set the hotbar slot to the original value of the helmet slot if it has a value, otherwise set it to null
|
||||
event.sender.inventory.mainInventory[hotbarIdx] = armorItem ? armorItem.getRef() : null;
|
||||
|
||||
// Make a packet to notify the client that the selected hotbar slot has been updated.
|
||||
event.sender.playerNetServerHandler.sendPacket(makePacketItemChange(hotbarIdx));
|
||||
|
||||
// Prevent the 'unknown command' error
|
||||
event.preventDefault = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
```
|
||||
@@ -0,0 +1,38 @@
|
||||
## Mod tutorials with ModAPI
|
||||
|
||||
|
||||
|
||||
### Beginner
|
||||
|
||||
Prerequisites:
|
||||
- Basic knowledge of JavaScript
|
||||
- A good code editor (recommended: https://vscode.dev)
|
||||
|
||||
Tutorials:
|
||||
- [Step Hack](step.md)
|
||||
- [Spider Hack](spider.md)
|
||||
- [VClip Exploit](vclip.md)
|
||||
|
||||
### Intermediate
|
||||
Prerequisites:
|
||||
- Intermediate knowledge of JavaScript (functions, arrays, promises, callbacks, keys and values in objects)
|
||||
- A good code editor (recommended: https://vscode.dev)
|
||||
- A copy of the eaglercraft workspace (optional, get it at: https://git.eaglercraft.rip/eaglercraft/eaglercraft-1.8-workspace)
|
||||
|
||||
Tutorials:
|
||||
- [Disable All Particles](disable_all_particles.md)
|
||||
- [Slippery Mod](slippery.md)
|
||||
- [/hat mod](hat.md)
|
||||
- [/spawnxp command](spawnxp.md)
|
||||
|
||||
### Advanced
|
||||
Prerequisites:
|
||||
- Advanced knowledge of JavaScript (prototypes)
|
||||
- A good code editor (recommended: https://vscode.dev)
|
||||
- A copy of the eaglercraft workspace (get it at: https://git.eaglercraft.rip/eaglercraft/eaglercraft-1.8-workspace)
|
||||
- Your EaglerForgeInjector processed.html opened in an editor (optional)
|
||||
|
||||
Tutorials:
|
||||
- [Custom Blocks](custom_block.md)
|
||||
- [Custom Items](custom_item.md)
|
||||
- [Timescale Command](timescale.md)
|
||||
@@ -0,0 +1,109 @@
|
||||
## Slippery Mod with ModAPI
|
||||
In this tutorial you will learn how to modify properties of blocks, and run the code that does this on both the dedicated server and the client.
|
||||
|
||||
We'll begin with the basic boilerplate mod code:
|
||||
```javascript
|
||||
(function SlipperyMod() {
|
||||
ModAPI.meta.title("Slippery Mod");
|
||||
ModAPI.meta.description("Makes everything turn into ice.");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
|
||||
//New code will go here!
|
||||
})();
|
||||
```
|
||||
|
||||
Let's write the client side part of the code first.
|
||||
- We'll get the keys for the ModAPI.blocks object (ids of each block) using [`Object.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
|
||||
- Then, we'll loop over those keys, and modify their respective block to be as slippery as ice.
|
||||
|
||||
```javascript
|
||||
var blockKeys = Object.keys(ModAPI.blocks);
|
||||
|
||||
blockKeys.forEach(key => { //for each key (block id)
|
||||
//make sure the block has a slipperiness property
|
||||
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
|
||||
if(ModAPI.blocks[key]?.slipperiness) {
|
||||
ModAPI.blocks[key].slipperiness = 0.98; //Set the slipperiness value of the block at that key to 0.98
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Your code should now look like this:
|
||||
```javascript
|
||||
(function SlipperyMod() {
|
||||
ModAPI.meta.title("Slippery Mod");
|
||||
ModAPI.meta.description("Makes everything turn into ice.");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
|
||||
var blockKeys = Object.keys(ModAPI.blocks);
|
||||
blockKeys.forEach(key => {
|
||||
if(ModAPI.blocks[key]?.slipperiness) {
|
||||
ModAPI.blocks[key].slipperiness = 0.98;
|
||||
}
|
||||
});
|
||||
})();
|
||||
```
|
||||
|
||||
Your code should now look like this:
|
||||
```javascript
|
||||
(function SlipperyMod() {
|
||||
ModAPI.meta.title("Slippery Mod");
|
||||
ModAPI.meta.description("Makes everything turn into ice.");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
|
||||
var blockKeys = Object.keys(ModAPI.blocks);
|
||||
blockKeys.forEach(key => {
|
||||
if(ModAPI.blocks[key]?.slipperiness) {
|
||||
ModAPI.blocks[key].slipperiness = 0.98;
|
||||
}
|
||||
});
|
||||
|
||||
//dedicated server code will be added here
|
||||
})();
|
||||
```
|
||||
|
||||
Currently this only runs on the client meaning in singleplayer, when you throw an item or punch a sheep, it still won't slide. Only you will.
|
||||
|
||||
We'll have to duplicate the code to run on the server using [`ModAPI.dedicatedServer`](../apidoc/dedicatedserver.md).
|
||||
We also have to run the code after the `serverstart` event, as on the server, `ModAPI.blocks` is only created when it is needed.
|
||||
```javascript
|
||||
ModAPI.dedicatedServer.appendCode(function () {
|
||||
//Code in here cannot reference outside variables.
|
||||
ModAPI.addEventListener("serverstart", function () {
|
||||
var blockKeys = Object.keys(ModAPI.blocks);
|
||||
blockKeys.forEach(key => {
|
||||
if(ModAPI.blocks[key]?.slipperiness) {
|
||||
ModAPI.blocks[key].slipperiness = 0.98;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
let's add this to the final mod, and we'll be finished!
|
||||
```javascript
|
||||
(function SlipperyMod() {
|
||||
ModAPI.meta.title("Slippery Mod");
|
||||
ModAPI.meta.description("Makes everything turn into ice.");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
|
||||
var blockKeys = Object.keys(ModAPI.blocks);
|
||||
blockKeys.forEach(key => {
|
||||
if(ModAPI.blocks[key]?.slipperiness) {
|
||||
ModAPI.blocks[key].slipperiness = 0.98;
|
||||
}
|
||||
});
|
||||
|
||||
ModAPI.dedicatedServer.appendCode(function () {
|
||||
//Code in here cannot reference outside variables.
|
||||
ModAPI.addEventListener("serverstart", function () {
|
||||
var blockKeys = Object.keys(ModAPI.blocks);
|
||||
blockKeys.forEach(key => {
|
||||
if(ModAPI.blocks[key]?.slipperiness) {
|
||||
ModAPI.blocks[key].slipperiness = 0.98;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
```
|
||||
@@ -0,0 +1,67 @@
|
||||
## /spawnxp command
|
||||
This tutorial will cover spawning in entities using the [`ModAPI.promisify()`](../apidoc/promisify.md) API.
|
||||
|
||||
As usual, we'll start with the boilerplate:
|
||||
```javascript
|
||||
(function SpawnXPMod() {
|
||||
ModAPI.meta.title("Spawn XP");
|
||||
ModAPI.meta.description("Adds a /spawnxp command.");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
|
||||
//future code
|
||||
})();
|
||||
```
|
||||
We'll move context to the server, and add a command listener, and ensure the sender is a player:
|
||||
```javascript
|
||||
PluginAPI.dedicatedServer.appendCode(function () { //Run this code on the server
|
||||
PluginAPI.addEventListener("processcommand", (event) => { //Command processing event
|
||||
if (
|
||||
!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP")
|
||||
.instanceOf(event.sender.getRef())
|
||||
) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Next, we'll check that the command is /spawnxp. If it is, we'll get the current dimension of the player, and spawn an XP orb at the sender's position. To construct the XP orb, we'll get the `EntityXPOrb` class and get the [first constructor](https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/net/minecraft/entity/EntityXPOrb.html)
|
||||
```javascript
|
||||
PluginAPI.dedicatedServer.appendCode(function () { //Run this code on the server
|
||||
PluginAPI.addEventListener("processcommand", (event) => { //Command processing event
|
||||
if (
|
||||
!ModAPI.reflect.getClassById("net.minecraft.entity.player.EntityPlayerMP") //If it isn't a player, exit the method
|
||||
.instanceOf(event.sender.getRef())
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.command.toLowerCase().startWith("/spawnxp")) {
|
||||
const world = event.sender.getServerForPlayer(); //get the current dimension
|
||||
const senderPos = event.sender.getPosition(); //get the player's current position
|
||||
|
||||
const EntityXP = ModAPI.reflect.getClassByName("EntityXPOrb"); // Get the entity xp orb class
|
||||
|
||||
const xporb = EntityXP.constructors[0](world.getRef(), senderPos.getX(), senderPos.getY(), senderPos.getZ(), 10); //Construct the first constructor, with arguments, World, x, y, z, xp value
|
||||
|
||||
//Get the spawn entity in world method
|
||||
var spawnEntityInWorldMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.world.World", "spawnEntityInWorld")];
|
||||
//Because this method reads and writes data to chunks, it tries to save and load the eaglercraft state, which won't work if eaglercraft is also running its own code.
|
||||
//To work around this issue, use ModAPI.promisify() to convert the method into one that returns a promise
|
||||
spawnEntityInWorldMethod = ModAPI.promisify(spawnEntityInWorldMethod);
|
||||
|
||||
//we can now use the spawnEntityInWorld method
|
||||
//wherever you see getRef(), it means to retrieve the raw, untouched data that TeaVM can use.
|
||||
spawnEntityInWorldMethod(world.getRef(), xporb).then(result => {
|
||||
// Get the chat component class
|
||||
const ChatComponentTextClass = ModAPI.reflect.getClassById("net.minecraft.util.ChatComponentText");
|
||||
|
||||
// Construct the chat component and send it to the client.
|
||||
event.sender.addChatMessage(ChatComponentTextClass.constructors[0](ModAPI.util.str("An xp orb has been spawned!")));
|
||||
});
|
||||
|
||||
//Stop the unknown command error
|
||||
event.preventDefault = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
## Spider Hack with ModAPI
|
||||
A spider hack allows players to climb up any wall like a spider.
|
||||
|
||||
Start by creating a new file in your code editor. Save it to a folder on your device, ensuring that the file extension is `.js`.
|
||||
|
||||
The spider hack has a lot of similarities to the step hack, so lets copy the step hack and rename the `stepHackUpdateCode` function to `spiderHackUpdateCode`:
|
||||
```javascript
|
||||
ModAPI.require("player");
|
||||
|
||||
function spiderHackUpdateCode() {
|
||||
//We will add code here.
|
||||
}
|
||||
ModAPI.addEventListener("update", spiderHackUpdateCode);
|
||||
```
|
||||
|
||||
Most spider hacks work by checking if the player is walking into a wall, and then setting their vertical velocity to a constant amount (usually `0.2`, for parity with ladders).
|
||||
Let's start by checking if the player is walking into a wall, by adding an if statement inside the `spiderHackUpdateCode` function:
|
||||
```javascript
|
||||
if (ModAPI.player.isCollidedHorizontally) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Now, let's set the player's vertical velocity:
|
||||
```javascript
|
||||
if (ModAPI.player.isCollidedHorizontally) {
|
||||
ModAPI.player.motionY = 0.2; //Feel free to change this value to something bigger, smaller or even negative.
|
||||
}
|
||||
```
|
||||
|
||||
Time to see the final code:
|
||||
```javascript
|
||||
ModAPI.require("player");
|
||||
|
||||
function spiderHackUpdateCode() {
|
||||
if (ModAPI.player.isCollidedHorizontally) {
|
||||
ModAPI.player.motionY = 0.2; //Feel free to change this value to something bigger, smaller or even negative.
|
||||
}
|
||||
}
|
||||
ModAPI.addEventListener("update", spiderHackUpdateCode);
|
||||
```
|
||||
@@ -0,0 +1,33 @@
|
||||
## Step Hack with ModAPI
|
||||
A step hack allows a player to walk up full blocks (or more) as if they were slabs.
|
||||
|
||||
Start by creating a new file in your code editor. Save it to a folder on your device, ensuring that the file extension is `.js`.
|
||||
|
||||
Let's start by requiring the player. This will allow us to change attributes on the player:
|
||||
```javascript
|
||||
ModAPI.require("player");
|
||||
```
|
||||
|
||||
Now, we have to detect when the player in a world. This will be done with the `update` event, which runs every tick while the player is in a world. In EaglerForge's ModAPI, to run code on an event, you have to create a function. Then, you register the function to an event.
|
||||
```javascript
|
||||
ModAPI.require("player");
|
||||
|
||||
function stepHackUpdateCode() {
|
||||
//We will add code here.
|
||||
}
|
||||
ModAPI.addEventListener("update", stepHackUpdateCode);
|
||||
```
|
||||
|
||||
Inside this method, lets change the player's `stepHeight`, which controls how high they can step. By default this is `0.5`, to alow players to walk up slabs or stairs. I'll change it to `2` for demonstration purposes. You can also try any other number, like `0`, `6`, etc.
|
||||
```javascript
|
||||
ModAPI.require("player");
|
||||
|
||||
function stepHackUpdateCode() {
|
||||
ModAPI.player.stepHeight = 2;
|
||||
}
|
||||
ModAPI.addEventListener("update", stepHackUpdateCode);
|
||||
```
|
||||
|
||||
Now, to load this mod, open your EaglerForge build, and in the start screen select `Upload Mod (.js)`. Upload the mod you created, and you should now be able to walk up two block tall pillars, or more depending on what `stepHeight` you selected.
|
||||
|
||||
Disclaimer: using this on servers may get you banned/kicked for cheating!
|
||||
@@ -0,0 +1,103 @@
|
||||
## Timescale Mod with ModAPI
|
||||
This mod will cover adding a new command that controls the speed that Eaglercraft runs at. This tutorial assumes that you have some knowledge on how to use [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) in JavaScript.
|
||||
|
||||
Let's get our basic template code down:
|
||||
|
||||
```javascript
|
||||
(function TimescaleCommand() {
|
||||
ModAPI.meta.title("Timescale Command");
|
||||
ModAPI.meta.description("use /timescale to control time");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
})()
|
||||
```
|
||||
|
||||
Our mod is going to be split into 2 distinct parts: client-side and server-side. The client will modify `ModAPI.mc.timer.timerSpeed` when a `/timescale` command is sent, while the server will set the timescale to a global variable, and then modify `net.minecraft.server.MinecraftServer`'s `getCurrentTimeMillis()` to change the rate calculations happen at on the server.\
|
||||
\
|
||||
However, there is a slight logistical problem: the server gets the time in milliseconds as a JavaScript [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt), which means we can't just multiply it by a number, we have to either multiply or divide it by another BigInt.
|
||||
```javascript
|
||||
var x = 1n * 1.0; //TypeError
|
||||
|
||||
var x = 1n * 1n; //Success
|
||||
```
|
||||
To allow us to both speed up and slow down time, we'll need to check if the speed inputted is greater or equal to 1. If it is, we round it and then convert it to a `BigInt`, which we'll store on the `globalThis` object. If it's less we'll need to find the speed to the power of -1, or `1 / speed`. We can then round this value and convert that to a `BigInt` to store on `globalThis`. We'll also set `globalThis.timeScaleDividing` to `true`, to signal to replaced `getCurrentTimeMillis()` to divide by the `BigInt` speed factor instead of multiply.\
|
||||
\
|
||||
Finally, due to our `BigInt` rounding shenanigans on the server, we have to replicate the rounding inaccuracy on the client.\
|
||||
\
|
||||
Let's implement the client side part.
|
||||
```javascript
|
||||
(function TimescaleCommand() {
|
||||
ModAPI.meta.title("Timescale Command");
|
||||
ModAPI.meta.description("use /timescale to control time");
|
||||
ModAPI.meta.credits("By <author_name>");
|
||||
|
||||
ModAPI.addEventListener("sendchatmessage", (event) => { // before a message gets sent to the server
|
||||
if (event.message.toLowerCase().startsWith("/timescale")) { //if it is the timescale command
|
||||
var speed = parseFloat(event.message.split(" ")[1]); //get the part of the message after the space
|
||||
if (!speed) { //If it doesn't exist, set it to 1.
|
||||
speed = 1;
|
||||
} else { //If it does exist:
|
||||
if (speed < 1) { //When the speed is less than 1, round the denominator (1 over x)
|
||||
speed = 1 / Math.round(1 / speed);
|
||||
} else {
|
||||
// When the speed is greater or equal to 1, round the numerator (x over 1)
|
||||
speed = Math.round(speed);
|
||||
}
|
||||
// Set the speed
|
||||
ModAPI.mc.timer.timerSpeed = speed;
|
||||
}
|
||||
// Log the speed to chat
|
||||
ModAPI.displayToChat("[Timescale] Set world timescale to " + speed.toFixed(2) + ".");
|
||||
}
|
||||
});
|
||||
})()
|
||||
```
|
||||
Now for the serverside part.
|
||||
```javascript
|
||||
(function TimescaleCommand() {
|
||||
//...
|
||||
|
||||
ModAPI.dedicatedServer.appendCode(function () { // Run on the server
|
||||
globalThis.timeScale = 1n; // Initialize globalThis.timeScale
|
||||
globalThis.timeScaleDividing = false; // Initialize globalThis.timeScaleDividing
|
||||
|
||||
ModAPI.addEventListener("processcommand", (event) => { // when the server receives a command
|
||||
if (event.command.toLowerCase().startsWith("/timescale")) { // if it is a timescale command
|
||||
var speed = parseFloat(event.command.split(" ")[1]); // get the second part of the command (the speed of time)
|
||||
if (!speed) { // If it doesn't exist, set it to 1.
|
||||
globalThis.timeScale = 1n;
|
||||
globalThis.timeScaleDividing = false;
|
||||
} else { // If it does exist:
|
||||
if (speed < 1) {
|
||||
// When the speed is less than 1, round the denominator (1 over x)
|
||||
// And enable division mode
|
||||
globalThis.timeScaleDividing = true;
|
||||
globalThis.timeScale = BigInt(Math.round(1 / speed));
|
||||
} else {
|
||||
// When the speed is greater or equal to 1, round the numerator (x over 1)
|
||||
// And disable division mode
|
||||
globalThis.timeScaleDividing = false;
|
||||
globalThis.timeScale = BigInt(Math.round(speed));
|
||||
}
|
||||
}
|
||||
if (ModAPI.server) { //If the server is initialized
|
||||
//Bump the current time forward so the server doesn't try to play catch-up
|
||||
ModAPI.server.currentTime = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "getCurrentTimeMillis")]();
|
||||
}
|
||||
|
||||
//Prevent the command not found error from appearing
|
||||
event.preventDefault = true;
|
||||
}
|
||||
});
|
||||
|
||||
//Monkey patch the getCurrentTime function.
|
||||
const original_getCurrentTime = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "getCurrentTimeMillis")];
|
||||
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "getCurrentTimeMillis")] = function () {
|
||||
if (globalThis.timeScaleDividing) { //If we are in divide mode
|
||||
return original_getCurrentTime() / globalThis.timeScale; //Return the current time divided by the time scale
|
||||
} else {
|
||||
return original_getCurrentTime() * globalThis.timeScale; //Else, return the current time multiplied by the time scale
|
||||
}
|
||||
};
|
||||
});
|
||||
})()
|
||||
```
|
||||
@@ -0,0 +1,82 @@
|
||||
## VClip Exploit with ModAPI
|
||||
Most minecraft servers have an exploit where you can trick the server into clipping you up to 10 blocks up or down through ceilings or floors.
|
||||
|
||||
### Part 1: Setup
|
||||
|
||||
Make a new file in your editor, and call it something like `vclip.js`
|
||||
First, let's setup a basic [IIFE (immediately invoked function expression)](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) around our mod code. This ensures that we don't leak variables that can interfere wiht other mods.\
|
||||
Example of the issue: if mod A and mod B both use `var myVariable = 0`, the value for myVariable will get overwritten.
|
||||
|
||||
```javascript
|
||||
(function VClipExploit() {
|
||||
//Future code here
|
||||
})(); //We define a function, called VClipExploit, which we wrap in parantheses () and immediately execute.
|
||||
```
|
||||
This allows us to use variables without worrying about mod compatibility, as variables are scoped to the function.
|
||||
|
||||
\
|
||||
Then, we'll add some basic [metadata](../apidoc/meta.md) for the mod loader (note that this is optional, but makes the mod look a lot better in the GUI once the game is loaded.)\
|
||||
We'll also require the player, so the `ModAPI.player` global is generated.
|
||||
|
||||
```javascript
|
||||
(function VClipExploit() {
|
||||
ModAPI.meta.title("VClip Exploit");
|
||||
ModAPI.meta.description("todo: add description.");
|
||||
ModAPI.meta.credits("By author_name");
|
||||
|
||||
ModAPI.require("player");
|
||||
|
||||
|
||||
})();
|
||||
```
|
||||
|
||||
### Part 2: VClip Exploit
|
||||
Our VClip exploit will be triggered by a client-side command, `.vclip <amount>`.
|
||||
Let's start off with the vclip command by adding an event listener to when the player sends a chat message:
|
||||
```javascript
|
||||
(function VClipExploit() {
|
||||
ModAPI.meta.title("VClip Exploit");
|
||||
ModAPI.meta.description("todo: add description.");
|
||||
ModAPI.meta.credits("By author_name");
|
||||
|
||||
ModAPI.require("player");
|
||||
|
||||
ModAPI.addEventListener("sendchatmessage", (ev) => {
|
||||
// handler code here
|
||||
});
|
||||
})();
|
||||
```
|
||||
In this event handler, we can get the content of the message by using `event.message`, process it, and check whether it is using the `.vclip` command. We can do this by casting the string to lowercase, using [`string.toLowerCase()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase), checking if the result of that is a call to the `.vclip` command using [`string.startsWith()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith).
|
||||
|
||||
If it is a call to the VClip command, we can use [`string.split(" ")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) to get all the arguments, find the vclip amount, and change the player's position.
|
||||
|
||||
```javascript
|
||||
(function VClipExploit() {
|
||||
ModAPI.meta.title("VClip Exploit");
|
||||
ModAPI.meta.description("todo: add description.");
|
||||
ModAPI.meta.credits("By author_name");
|
||||
|
||||
ModAPI.require("player");
|
||||
|
||||
ModAPI.addEventListener("sendchatmessage", (ev) => {
|
||||
var string = ev.message.toLowerCase(); //Get the lower case version of the command
|
||||
if (string.startsWith(".vclip")) { //does the chat message start with .vclip?
|
||||
ev.preventDefault = true; //we don't want this being sent into chat as a message
|
||||
var yOffset = 1; //The offset on the y axis
|
||||
var args = string.split(" ");
|
||||
if (args[1]) { //If the second argument to .vclip exists (the vclip <amount>)
|
||||
yOffset = parseFloat(args[1]) || 0; //Convert the second argument into a number. We use || to replace NaN (invalid numbers) with 0. Then, store it into the y offset.
|
||||
} //This allows you to just type .vclip to clip upwards 1 block.
|
||||
|
||||
ModAPI.player.setPosition( //This function sets the players position to an XYZ coordinate
|
||||
ModAPI.player.posX,
|
||||
ModAPI.player.posY + yOffset, //All XYZ elements are the same, except we add the yOffset variable to the y axis.
|
||||
ModAPI.player.posZ
|
||||
);
|
||||
|
||||
//Finally, log the amount we've VClipped into the chat.
|
||||
ModAPI.displayToChat("[VClip] VClipped " + yOffset + " blocks.");
|
||||
}
|
||||
});
|
||||
})();
|
||||
```
|
||||
Reference in New Issue
Block a user