# Minecraft Base Project

IntelliJ base project related to Minecraft Lab of 221_SIn & 231_SIn course

## Purpose
This project is made during the 4th semester of study in Industrial Systems at the University of Engineering in Sion,
Wallis, Switzerland. It is used to learn the basics of DevOps, Database, web development and modbus communication. 
This project is made by a group of 2 students. This project was made during 7 weeks and cut into 6 parts.
The goal of this project is to interface a Minecraft mod. This mod is a simulation of a micro-gri. Our goal is to 
read electrical value from the Minecraft world and save it in database, display it on a web page and finally send 
regulation value to the Minecraft world for keep the micro-gri stable.
To reach this goal, we have to use a modbus communication between the Minecraft world and our program.
The program is divided into 6 parts:

### Core part
The core part is the main part of the project. It is the part that will be used to communicate with the other parts. 
In Core, we have the management of DataPoints. A DataPoint is a virtual copy of a Minecraft input or output. In Core, 
we have a static Map of DataPoints. The key of the map is the name of the DataPoint and the value is the DataPoint 
itself. The DataPoint class is an abstract class. It has 2 subclasses, FloatDataPoint and BooleanDataPoint.

### Database part
The database part is the part that will be used to store the DataPoints. All DataPoints are send with a http POST 
request to the database. The database use in this project is InfluxDB. InfluxDB is a time series database. We use 
after Grafana to display the data. Database part can also erase all the data in the database.
The time management is also on this class. The goal of this class is to convert the time from the Minecraft server 
to the real time. We start to send data to the database only when the Minecraft server is started.

### Web part
The web part is the part that will be used to display the data from the database. We already have a web page that is 
given by teacher. We use a websocket to interface with web page. With this web page we can read Minecraft data and 
set some regulation value. We also add a switch to start or stop the smart part. 

### Modbus part
The modbus part is the part that will be used to communicate with the Minecraft world. We use the modbus TCP 
communication. We use the library modbus4j.

### Field part
The field part is the part that will be used to connect modbus part to the core part. We read a csv file to know all 
the modbus address and the name of the DataPoint. With this file, we can link DataPoint to minecraft input or output.

### Smart part
The smart part is the part that will be used to send regulation value to the Minecraft world. We make a very simple 
regulation just for keep the grid alive during the time of the simulation. We stop our program when the Minecraft 
simulation send a score. This score is how many production we have made with the factory during the simulation. So 
the goal is to maximize this score. We didn't have time to make a better regulation.

### Full description
You can find the Javadoc of this project in the folder ``javadoc`` at the root of the project. 

## How to use
To use this project you can just download the last release and run the JAR file with some arguments. 
The command to run the JAR file is:  
``java -jar MinecraftController.jar <db_url> <db_org> <db_bucket> <db_token> <modbus_host> <modbus_port> [-erasedb]``  
Where the arguments are:  
``db_url``: The complete URL of the InfluxDB server, including the protocol (http or https)...  
Example: https://influx.sdi.hevs.ch  
``db_org``: The name of the Influx DB to use. For this project, this name is the name of the group you've been 
affected to. (SInXX)  
``db_bucket``: The user's name to use to access the DB. It's also your group's name. (SInXX)  
``db_token``: The Token to use to access the DB.  
``modbus_host``: The IP address of the Minecraft ModbusTCP server (default value: localhost)  
``modbus_port``: The port number of the Minecraft ModbusTCP server (default value: 1502)  
``-erasedb``: Optional parameter! If set, the application will erase the previous data in InfluxDB...  
Example:  
``java -jar MinecraftController.jar https://influx.sdi.hevs.ch SIn15 SIn15 evP...nj-Q== localhost 1502 -erasedb``



