Jump to content

Create mod that exposes subset of Forge through an IPC/RPC API?


LuciferK9

Recommended Posts

I just started playing minecraft after a few years of not playing anymore, so I don't know much about Forge. Sorry for my ignorance in advance.

 

I was thinking about a mod that exposes an API to allow players to create a "mod" in any programming language (I'm going to refer to these "mods" as "xmods" to differentiate them from forge mods). Not the full Forge's API, just a subset of it, like events, or anything that can be exposed.

 

Basically, the mod would receive messages from xmods and do whatever they say and send messages to them telling them whatever it is happening in the minecraft world.

 

I haven't thought about the specific details of the implementation, but for the messages we could use something like protobuf or flatbuffers, this way we could specificate the schema for the API and use it in different languages easily. The communication could be over TCP, or maybe the mod could spawn the xmods in child processes and communicate over stdin/stdout.

 

The schema could look something like:

message CommonEntityProps {
	Vector3 coordinates;
	int32 life;
	...
}

message ServerEvent {
	optional PlayerPlacedBlockEvent player_placed_block = 1;
	...
}

message Entity {
	...
}

message Player {
	required CommonEntityProps common;
	...
}

message Block {
	required Vector3 coordinates;
	required BlockType type;
	...
}

message PlayerPlacedBlockEvent {
	required Player player;
	required Block block;
	...
}

 

This is not supposed to be a replacement to mods. Just a way to easily create custom content without having to download and learn forge and without the trouble that java brings (for people that don't like it).

 

Maybe someone has an idea and needs to quickly make a prototype and they decide to use python or javascript, just to test it and have fun in single player or lan with friends.

 

This would also allow to create, automatize and invent new stuff very quickly. Imagine a player trying to build a giant pyramid where every 3 blocks there is a diamond block or something, this could be easily created in a script with less than 10 lines of code, and when you get to the top, you get burn because there's a god punishing you.

 

Yesterday I was trying to create a basic game mode where you have to throw a player out of a platform, kill the player automatically if they're below an Y coordinate, and give them full armor and custom items after they respawn, I had problems making it with just command blocks. I would've liked to use some if statements but could not afford setting up forge, read the documentation, and probably download intellij because from what I remember, it's a pain in the *** to code java in something like vim or any other editor that is not an IDE.

 

Some code in Rust on how I would like this to look like:

use forge_xmod::{
    Client, Event,
    player::{ Player, Inventory },
    minecraft::{ Enchantment, Item },
};

fn main() {
    let client = Client::connect("127.0.0.1:9999");

    loop {
        while let Some(event) = client.poll_event() {
            match event {
                Event::PlayerPlacedBlock(player, block) => {
                    println!("The player {} placed a block ({}) on: {}", player, block, block.coordinates);
                },
                Event::PlayerMoved(player) => {
                    if player.coordinates.y < 50 {
                        // this would send a TCP? packet, telling the mod to kill said player. Serialized with protobuf?
                        player.kill();
                    }
                },
            }
        }
        for player in client.players() {
            if !player.inventory.contains(Item::DiamondSword) {
                let mut item = Item::DiamondSword;
                item.enchant(Enchantment::Sharpness, 4);
                player.inventory.insert(item); // send packet
            }
        }
    }
}

I could just then compile it, run it and it would already work. Other person could do the same in JavaScript, C++, etc.

 

I want to read your opinions and see if anyone is interested in working on something like this. As I said, I don't know much about Forge, so I would like some help since I plan to make this anyways, at least to fit my needs. I would help to find where the main Forge APIs are located to see if I can generate the schema programatically.

Edited by LuciferK9
Minor edit
Link to comment
Share on other sites

Java is pretty easy with intelliJ really. Also lex has said in the past he's not including other languages in forge. Forge is for java. If you need another language lib / cross compatability, you best make your own in java. 

 

At that point honestly just write it in java. Or Kotlin / Scala etc which have their libs you can include and run on JVM bytecode. Better then having to bog things down with cross language stuff.  Writing using intelliJ is easy. You can write without, i used to write C# in notepad++ to be frank and it never bothered me much, just got to check them compile errors and your code is trash and slow because you have no IDE assists.

Java is honestly one of the easier OO languages. Less to worry about then say C++ etc. or any of the big languages, Rust is trying to replace C++ along with Golang and Dlang so it in theory would be quite more low level the java but honestly out of the 4, i'd probably be more inclined to learn D / Go if i had to. Either way point is i don't really like rust and have never really learned it so i could be off the mark on how easy it is to learn but when it's trying to replace C++ you would assume it would be more low level. 

Edited by ShinyAfro
Link to comment
Share on other sites

5 hours ago, ShinyAfro said:

Java is pretty easy with intelliJ really. Also lex has said in the past he's not including other languages in forge. Forge is for java. If you need another language lib / cross compatability, you best make your own in java.

I know Java is easy with intelliJ, the post was not about java being difficult, was about just wanting to code in a better language. I wasn't asking to include compatibility in Forge with another language, I was talking about creating a mod that exposes the API through RPC/IPC. It's not a feature request, that's why it's here in general discussion.

 

5 hours ago, ShinyAfro said:

At that point honestly just write it in java. Or Kotlin / Scala etc which have their libs you can include and run on JVM bytecode. Better then having to bog things down with cross language stuff.  Writing using intelliJ is easy. You can write without, i used to write C# in notepad++ to be frank and it never bothered me much, just got to check them compile errors and your code is trash and slow because you have no IDE assists.

I don't think a language should depend on an IDE. The only language (that I know) that lacks command line tools is java. Even C# with .NET Core already has better tooling that allows people to write code efficiently without using a full IDE.

 

5 hours ago, ShinyAfro said:

Java is honestly one of the easier OO languages. Less to worry about then say C++ etc. or any of the big languages, Rust is trying to replace C++ along with Golang and Dlang so it in theory would be quite more low level the java but honestly out of the 4, i'd probably be more inclined to learn D / Go if i had to. Either way point is i don't really like rust and have never really learned it so i could be off the mark on how easy it is to learn but when it's trying to replace C++ you would assume it would be more low level. 

D, GoLang, Rust and modern C++ are just as easy as java. But using these languages you have a set of features that you can opt-in if you want to write lower-level code or make some hand-crafted optimizations.

Link to comment
Share on other sites

Personally, this is probably not necessary.

This would means that the developer need to write a hook in all the said languages to expose the Forge API. This of course includes the circumvention of non dynamically loadable languages like C++. Unless you meant to parse the said languages into a intermediate form (which probably require more effort, as a compiler is needed), which is then loaded by the "xmod", but this would make the user unable to access Minecraft and Forge with reflection and ASM.

 

18 hours ago, LuciferK9 said:

The only language (that I know) that lacks command line tools is java.

You can compile and run Java code from the command line. However, writing Java (and most other static languages) without an IDE would be a pain and is not recommended.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

On 9/11/2019 at 2:48 AM, LuciferK9 said:

I know Java is easy with intelliJ, the post was not about java being difficult, was about just wanting to code in a better language. I wasn't asking to include compatibility in Forge with another language, I was talking about creating a mod that exposes the API through RPC/IPC. It's not a feature request, that's why it's here in general discussion.

 

I don't think a language should depend on an IDE. The only language (that I know) that lacks command line tools is java. Even C# with .NET Core already has better tooling that allows people to write code efficiently without using a full IDE.

 

D, GoLang, Rust and modern C++ are just as easy as java. But using these languages you have a set of features that you can opt-in if you want to write lower-level code or make some hand-crafted optimizations.

Well a little while ago there was a bunch of hackers on the 1.7.10 mods and i noticed a few mods used RPC from netty to execute java bytecode. You might want to look into that if you want to make a mod for any language you want to make some sort of library.

 

And hell yes i have written C# in a text editor and you can do the same with java, I just don't see the why when said tools greatly accelerate my workflow. Eclipse is another good editor.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.