mirror of
https://github.com/JonasunderscoreJones/Microcraft.git
synced 2025-10-25 20:49:19 +02:00
Added basic mod structure
This commit is contained in:
parent
746af8d251
commit
9e7c20ef07
179 changed files with 1528 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
|||
package me.jonasjones.arduinoctrls;
|
||||
|
||||
import me.jonasjones.arduinoctrls.debug.LedBlink;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ArduinoControls implements ModInitializer {
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("arduinoctrls");
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
LOGGER.info("UwU from Arduino Controls!");
|
||||
try {
|
||||
LedBlink.initialisation();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
48
src/main/java/me/jonasjones/arduinoctrls/debug/LedBlink.java
Normal file
48
src/main/java/me/jonasjones/arduinoctrls/debug/LedBlink.java
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package me.jonasjones.arduinoctrls.debug;
|
||||
|
||||
import arduino.Arduino;
|
||||
import me.jonasjones.arduinoctrls.ArduinoControls;
|
||||
|
||||
public class LedBlink {
|
||||
public static void initialisation() throws InterruptedException {
|
||||
|
||||
//do portscan
|
||||
//String port = (new SPortScan()).getActivePort();
|
||||
String port = "/dev/ttyUSB0";
|
||||
//establish connection to Ardiuno
|
||||
Arduino ArduinoCon = new Arduino(port, 9600);
|
||||
boolean isOn = true; //Led state off
|
||||
String[] commands = {"turnOff", "turnOn"}; //commands for Arduino
|
||||
|
||||
ArduinoCon.openConnection();
|
||||
Thread.sleep(4000);
|
||||
ArduinoCon.serialWrite(commands[1]);
|
||||
Thread.sleep(1000);
|
||||
ArduinoCon.serialWrite(commands[0]);
|
||||
Thread.sleep(1000);
|
||||
ArduinoCon.serialWrite(commands[1]);
|
||||
Thread.sleep(1000);
|
||||
ArduinoCon.serialWrite(commands[0]);
|
||||
ArduinoCon.closeConnection();
|
||||
}
|
||||
|
||||
public static boolean blink(Arduino ArduinoCon, String[] commands, boolean isOn) throws InterruptedException {
|
||||
ArduinoCon.openConnection();
|
||||
Thread.sleep(4000);
|
||||
isOn = !isOn;
|
||||
if (isOn) {
|
||||
ArduinoCon.serialWrite(commands[1]);
|
||||
} else {
|
||||
ArduinoCon.serialWrite(commands[0]);
|
||||
}
|
||||
ArduinoCon.closeConnection();
|
||||
return isOn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package me.jonasjones.arduinoctrls.debug;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import gnu.io.*;
|
||||
import me.jonasjones.arduinoctrls.ArduinoControls;
|
||||
|
||||
public class SPortScan {
|
||||
private String activePort;
|
||||
|
||||
public SPortScan(){
|
||||
CommPortIdentifier serialPortId;
|
||||
|
||||
Enumeration enumComm;
|
||||
|
||||
enumComm = CommPortIdentifier.getPortIdentifiers(); // get active ports
|
||||
ArduinoControls.LOGGER.info("Found Ports: " + enumComm.toString());
|
||||
|
||||
/*
|
||||
go throught ports and identify the serial
|
||||
*/
|
||||
while(enumComm.hasMoreElements())
|
||||
{
|
||||
serialPortId = (CommPortIdentifier) enumComm.nextElement(); // get next one
|
||||
if(serialPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) // check if is serial type
|
||||
{
|
||||
this.activePort = (String) serialPortId.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getActivePort(){
|
||||
return this.activePort;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package me.jonasjones.arduinoctrls.mixin;
|
||||
|
||||
import me.jonasjones.arduinoctrls.ArduinoControls;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.text.Text;
|
||||
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(TitleScreen.class)
|
||||
public abstract class ArduinoMixin extends Screen {
|
||||
protected ArduinoMixin(Text title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "init()V")
|
||||
private void init(CallbackInfo info) {
|
||||
ArduinoControls.LOGGER.info("This line is printed by an example mod mixin!");
|
||||
}
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "initWidgetsNormal")
|
||||
private void ledToggleButton(int y, int spacingY, CallbackInfo ci) {
|
||||
this.addDrawableChild(new ButtonWidget(50, 50, 20, 20,Text.of("LED"), (button) -> {
|
||||
this.client.scheduleStop();
|
||||
}));
|
||||
}
|
||||
}
|
||||
14
src/main/resources/arduinoctrls.mixins.json
Normal file
14
src/main/resources/arduinoctrls.mixins.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "me.jonasjones.arduinoctrls.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"ArduinoMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/modid/icon.png
Normal file
BIN
src/main/resources/assets/modid/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 453 B |
38
src/main/resources/fabric.mod.json
Normal file
38
src/main/resources/fabric.mod.json
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "arduinoctrls",
|
||||
"version": "v0.0.1alpha01",
|
||||
|
||||
"name": "Minecraft Arduino Controls",
|
||||
"description": "A mod that allows for communication between the Minecraft client and an Arduino.",
|
||||
"authors": [
|
||||
"Jonas_Jones"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://jonasjones.me/MinecraftArduinoControls",
|
||||
"sources": "https://github.com/J-onasJones/MinecraftArduinoControls"
|
||||
},
|
||||
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/arduinoctrls/icon.png",
|
||||
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"me.jonasjones.arduinoctrls.ArduinoControls"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"arduinoctrls.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.6",
|
||||
"fabric": "*",
|
||||
"minecraft": "~1.19",
|
||||
"java": ">=17"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue