TARDIM factory closed due to supply chain issues
This commit is contained in:
parent
ff96023b56
commit
3922140f13
2 changed files with 82 additions and 41 deletions
43
README.md
43
README.md
|
@ -1,33 +1,20 @@
|
||||||
# CC Tutorial
|
# TARDIM: In Control
|
||||||
This is a little tutorial on how peripherals in cc work.
|
### All of time and space, *now automated*.
|
||||||
We use the simple system with the IPeripheral interface.
|
|
||||||
|
|
||||||
If you want to see, how I use this system with more functions and blocks, take a look at [Advanced Peripherals](https://github.com/Seniorendi/AdvancedPeripherals)
|
This mod is an addon for the [TARDIM mod](https://www.curseforge.com/minecraft/mc-mods/tardim), and adds a way to control your time (but mostly space) machine using
|
||||||
|
[ComputerCraft: Tweaked](https://tweaked.cc) computers using a new "Digital TARDIM Interface" peripheral.
|
||||||
|
|
||||||
We create a peripheral with two functions:
|
### How to use
|
||||||
* isRaining - a main thread function which will return true when it rains
|
* Place the Digital Interface peripheral inside your TARDIM.
|
||||||
* sendMessage - a function which will send a message to every player
|
* Connect a computer to the peripheral using a wired modem and wrap it with `peripheral.wrap()`.
|
||||||
|
* Call one of the many methods available to you.
|
||||||
|
|
||||||
## Supported Versions
|
All the methods can be found in the [API documentation](https:/google.com), and there are some examples in the [examples folder](/examples)
|
||||||
- [1.19](https://github.com/Seniorendi/CCTutorial/tree/1.19)
|
|
||||||
- [1.18](https://github.com/Seniorendi/CCTutorial/tree/1.18)
|
|
||||||
- [1.16](https://github.com/Seniorendi/CCTutorial/tree/1.16)
|
|
||||||
|
|
||||||
## Content
|
### Example usecases
|
||||||
* CCBlock - Our normal block, nothing special
|
* Monitor to display fuel levels, current location, and other information on a screen in a nice way.
|
||||||
|
* Way to remotely summon your TARDIM to you, or to a specific location. (Using chunkloaders)
|
||||||
|
* Refined control of your TARDIM, such as saving and loading locations, or setting a destination in a GUI.
|
||||||
|
* Visual effects that activate during flight.
|
||||||
|
|
||||||
* CCPeripheral - Our peripheral, here we register functions and manage connected computers
|
The possibilities are endless, the only limit is your imagination! (And coding skills)
|
||||||
|
|
||||||
* Registration - Normal registration to register our blocks, items and so on
|
|
||||||
|
|
||||||
* CCTutorial - Our main class
|
|
||||||
|
|
||||||
* CCTileEntity - Our tile entity
|
|
||||||
|
|
||||||
* /src/main/resources/META-INF/mods.toml - Here we have our name of the mod, the mod id, the versiond and more. The most importang thing in the file is the modid and the dependencies for addons like cc-tweaked.
|
|
||||||
|
|
||||||
## Pictures
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||

|
|
|
@ -6,6 +6,7 @@ import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.lua.ObjectLuaTable;
|
import dan200.computercraft.api.lua.ObjectLuaTable;
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,22 +62,75 @@ public class CCPeripheral implements IPeripheral {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get TARDIM's data, which we need for *every* function
|
/* Get TARDIM's data, which we need for *every* function
|
||||||
// TODO: How do we check if there is no TARDIM?!
|
*
|
||||||
public TardimData getTardimData() {
|
* We can't do a simple
|
||||||
return TardimManager.getFromPos(getTileEntity().getPos());
|
* TardimManager.getFromPos(getTileEntity().getPos())
|
||||||
|
* because if someone attempts to call a method outside a TARDIM, this would create a new TARDIM/Point to the one with ID of 0 (Due to the way TardimSaveHandler.loadTardisData works).
|
||||||
|
* Which is obviously not what we want.
|
||||||
|
*
|
||||||
|
* So instead we use this, and recieve ability to give user a LuaException if they think that fiddling with time devices is funny
|
||||||
|
* This is mostly a copy of getIDForXZ function */
|
||||||
|
public TardimData getTardimData() throws LuaException {
|
||||||
|
int X = getTileEntity().getPos().getX(), Z = getTileEntity().getPos().getZ();
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
int dx = 0;
|
||||||
|
int dy = 1;
|
||||||
|
int segment_length = 1;
|
||||||
|
int segment_passed = 0;
|
||||||
|
boolean found = false;
|
||||||
|
long timecheck = System.currentTimeMillis();
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
if (System.currentTimeMillis() - timecheck > 10000L) {
|
||||||
|
System.out.println("Finding ID from XZ Coordinates is taking too long!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (X >= x * TardimManager.INTERIOR_BOUNDS
|
||||||
|
&& X <= TardimManager.INTERIOR_BOUNDS + x * TardimManager.INTERIOR_BOUNDS
|
||||||
|
&& Z >= y * TardimManager.INTERIOR_BOUNDS
|
||||||
|
&& Z <= TardimManager.INTERIOR_BOUNDS + y * TardimManager.INTERIOR_BOUNDS) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
|
if (++segment_passed == segment_length) {
|
||||||
|
segment_passed = 0;
|
||||||
|
int buffer = dy;
|
||||||
|
dy = -dx;
|
||||||
|
dx = buffer;
|
||||||
|
if (buffer == 0) {
|
||||||
|
++segment_length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We really don't want to create a new TARDIM if we are not inside one, do we?
|
||||||
|
if (!found) {
|
||||||
|
throw new LuaException("Peripheral is not inside a TARDIM");
|
||||||
|
}
|
||||||
|
|
||||||
|
return TardimManager.getTardim(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peripheral methods ===============================================================
|
// Peripheral methods ===============================================================
|
||||||
|
|
||||||
// Get amount of fuel we have (Out of 100)
|
// Get amount of fuel we have (Out of 100)
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final double get_fuel() {
|
public final double get_fuel() throws LuaException {
|
||||||
return getTardimData().getFuel();
|
return getTardimData().getFuel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final double calculate_fuel() {
|
public final double calculate_fuel() throws LuaException {
|
||||||
TardimData data = getTardimData();
|
TardimData data = getTardimData();
|
||||||
|
|
||||||
if (data.getTravelLocation() == null) return 0;
|
if (data.getTravelLocation() == null) return 0;
|
||||||
|
@ -96,17 +150,17 @@ public class CCPeripheral implements IPeripheral {
|
||||||
|
|
||||||
// Check whether the TARDIM is locked
|
// Check whether the TARDIM is locked
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final boolean is_locked() {
|
public final boolean is_locked() throws LuaException {
|
||||||
return getTardimData().isLocked();
|
return getTardimData().isLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the TARDIM is in flight
|
// Check whether the TARDIM is in flight
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final boolean is_in_flight() { return getTardimData().isInFlight(); }
|
public final boolean is_in_flight() throws LuaException { return getTardimData().isInFlight(); }
|
||||||
|
|
||||||
// Supposedly gets UNIX timestamp of when we entered flight
|
// Supposedly gets UNIX timestamp of when we entered flight
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final long get_time_entered_flight() {
|
public final long get_time_entered_flight() throws LuaException {
|
||||||
TardimData data = getTardimData();
|
TardimData data = getTardimData();
|
||||||
if (!data.isInFlight()) {
|
if (!data.isInFlight()) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -117,20 +171,20 @@ public class CCPeripheral implements IPeripheral {
|
||||||
|
|
||||||
// Get username of the TARDIM's owner
|
// Get username of the TARDIM's owner
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final String get_owner_name() {
|
public final String get_owner_name() throws LuaException {
|
||||||
TardimData data = getTardimData();
|
TardimData data = getTardimData();
|
||||||
return data.getOwnerName();
|
return data.getOwnerName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock/Unlock the TARDIM
|
// Lock/Unlock the TARDIM
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final void set_locked(boolean locked) {
|
public final void set_locked(boolean locked) throws LuaException {
|
||||||
getTardimData().setLocked(locked);
|
getTardimData().setLocked(locked);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns table with current TARDIM location
|
// Returns table with current TARDIM location
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final ObjectLuaTable get_current_location() {
|
public final ObjectLuaTable get_current_location() throws LuaException {
|
||||||
Location loc = getTardimData().getCurrentLocation();
|
Location loc = getTardimData().getCurrentLocation();
|
||||||
return new ObjectLuaTable(Map.of(
|
return new ObjectLuaTable(Map.of(
|
||||||
"dimension", loc.getLevel().location().toString(),
|
"dimension", loc.getLevel().location().toString(),
|
||||||
|
@ -145,7 +199,7 @@ public class CCPeripheral implements IPeripheral {
|
||||||
|
|
||||||
// Returns flight destination (or null if there isn't one)
|
// Returns flight destination (or null if there isn't one)
|
||||||
@LuaFunction(mainThread = true)
|
@LuaFunction(mainThread = true)
|
||||||
public final ObjectLuaTable get_flight_location() {
|
public final ObjectLuaTable get_flight_location() throws LuaException {
|
||||||
TardimData data = getTardimData();
|
TardimData data = getTardimData();
|
||||||
if (data.getTravelLocation() != null) {
|
if (data.getTravelLocation() != null) {
|
||||||
Location loc = data.getTravelLocation();
|
Location loc = data.getTravelLocation();
|
||||||
|
|
Loading…
Add table
Reference in a new issue