Game launches, blocks place. Now for the content.
This commit is contained in:
parent
987a18c360
commit
4c6939e69f
89 changed files with 1191 additions and 548 deletions
|
@ -20,6 +20,8 @@ dependencies {
|
|||
|
||||
// ComputerCraft
|
||||
compileOnly("cc.tweaked:cc-tweaked-$minecraft_version-common-api:$cc_version")
|
||||
|
||||
compileOnly(files("./tardim-1.2.2-dev.jar"))
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package su.a71.tardim_ic;
|
||||
|
||||
public class Registration {
|
||||
|
||||
public static void register() {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package su.a71.tardim_ic.command;
|
||||
|
||||
import com.swdteam.tardim.common.command.tardim.CommandTardimBase;
|
||||
import com.swdteam.tardim.common.command.tardim.ICommand;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.FurnaceFuelSlot;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.FurnaceBlockEntity;
|
||||
|
||||
|
||||
/*
|
||||
This command prints list of all biomes into the console to find technical names
|
||||
You can also pass an argument to search for entries with this string (e.g. amethyst for terralith:amethyst_rainforest
|
||||
*/
|
||||
public class CommandListBiomes implements ICommand{
|
||||
@Override
|
||||
public void execute(String[] args, Player player, BlockPos pos, CommandTardimBase.CommandSource source) {
|
||||
;
|
||||
if (args.length == 1 || args.length == 0) {
|
||||
TardimData data = TardimManager.getFromPos(pos);
|
||||
if (data != null) {
|
||||
if (data.hasPermission(player)) {
|
||||
Registry<Biome> biomeRegistry = player.level().registryAccess().registryOrThrow(Registries.BIOME);
|
||||
biomeRegistry.keySet().forEach(
|
||||
(ResourceLocation res) -> {
|
||||
String out = res.toString();
|
||||
if (args.length == 0 || out.toLowerCase().contains(args[0].toLowerCase())) {
|
||||
CommandTardimBase.sendResponse(player, out, CommandTardimBase.ResponseType.INFO, source);
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
CommandTardimBase.sendResponse(player, "You do not have permission", CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CommandTardimBase.sendResponse(player, this.getUsage(), CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "list-biomes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/list-biomes <..search_query>"; // TODO: how to communicate this better
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTardimBase.CommandSource allowedSource() {
|
||||
return CommandTardimBase.CommandSource.BOTH;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package su.a71.tardim_ic.command;
|
||||
|
||||
import com.swdteam.tardim.common.command.tardim.CommandTardimBase;
|
||||
import com.swdteam.tardim.common.command.tardim.ICommand;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
/*
|
||||
This command prints list of all dimensions into the console to find technical names
|
||||
*/
|
||||
public class CommandListDimensions implements ICommand{
|
||||
@Override
|
||||
public void execute(String[] args, Player player, BlockPos pos, CommandTardimBase.CommandSource source) {
|
||||
if (args.length == 0) {
|
||||
TardimData data = TardimManager.getFromPos(pos);
|
||||
if (data != null) {
|
||||
if (data.hasPermission(player)) {
|
||||
for (ServerLevel serverLevel : player.level().getServer().getAllLevels()) {
|
||||
CommandTardimBase.sendResponse(player, serverLevel.dimension().location().toString(), CommandTardimBase.ResponseType.INFO, source);
|
||||
}
|
||||
} else {
|
||||
CommandTardimBase.sendResponse(player, "You do not have permission", CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CommandTardimBase.sendResponse(player, this.getUsage(), CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "list-dimensions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/list-dimensions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTardimBase.CommandSource allowedSource() {
|
||||
return CommandTardimBase.CommandSource.BOTH;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package su.a71.tardim_ic.command;
|
||||
|
||||
// This will be added whenever I manage to convince TARDIM devs to make CommandManager.register public
|
||||
// 13.04.23 ITS ALIVE
|
||||
|
||||
import com.swdteam.tardim.common.command.tardim.CommandTardimBase;
|
||||
import com.swdteam.tardim.common.command.tardim.ICommand;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.network.Packet;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
/*
|
||||
This command sends out a ComputerCraft modem signal
|
||||
This could be useful for connecting advanced navigation systems into "vanilla" controls
|
||||
You can specify both channels, message and even make the message go across dimensions
|
||||
*/
|
||||
public class CommandModemTransmit implements ICommand {
|
||||
@Override
|
||||
public void execute(String[] args, Player player, BlockPos pos, CommandTardimBase.CommandSource source) {
|
||||
if (args.length == 3) { // TODO: 3 or 4???
|
||||
TardimData data = TardimManager.getFromPos(pos);
|
||||
if (data != null) {
|
||||
if (data.hasPermission(player)) {
|
||||
try {
|
||||
int sendChannel = Integer.parseInt(args[0]);
|
||||
int replyChannel = Integer.parseInt(args[1]);
|
||||
String message = args[2];
|
||||
boolean allDimensions = Boolean.parseBoolean(args[3]) || args[3].equals("true");
|
||||
|
||||
if (data.getTravelLocation() == null) {
|
||||
data.setTravelLocation(new TardimData.Location(data.getCurrentLocation()));
|
||||
}
|
||||
|
||||
if (allDimensions)
|
||||
{
|
||||
ComputerCraftAPI.getWirelessNetwork(player.getServer()).transmitInterdimensional(new Packet(sendChannel, replyChannel, message, new CommandSender(player, data.getTravelLocation().getPos())));
|
||||
}
|
||||
else {
|
||||
ComputerCraftAPI.getWirelessNetwork(player.getServer()).transmitSameDimension(new Packet(sendChannel, replyChannel, message,
|
||||
new CommandSender(player, data.getTravelLocation().getPos())), 300);
|
||||
}
|
||||
CommandTardimBase.sendResponse(player, "Sent modem message", CommandTardimBase.ResponseType.COMPLETE, source);
|
||||
} catch (Exception var9) {
|
||||
CommandTardimBase.sendResponse(player, "Invalid coordinates", CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
} else {
|
||||
CommandTardimBase.sendResponse(player, "You do not have permission", CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CommandTardimBase.sendResponse(player, this.getUsage(), CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "cc-modem-transmit";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/cc-modem-transmit <Chnl> <replyChnl> <msg> <ender: bool>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTardimBase.CommandSource allowedSource() {
|
||||
return CommandTardimBase.CommandSource.BOTH;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package su.a71.tardim_ic.command;
|
||||
|
||||
import dan200.computercraft.api.network.PacketSender;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CommandSender implements PacketSender {
|
||||
|
||||
private final Player player;
|
||||
private final Level level;
|
||||
private final BlockPos pos;
|
||||
|
||||
CommandSender(Player player, BlockPos pos) {
|
||||
this.player = player;
|
||||
this.level = player.level();
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Level getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Vec3 getPosition() {
|
||||
return new Vec3(this.pos.getX(), this.pos.getY(), this.pos.getZ());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getSenderID() {
|
||||
return this.player.getName().getString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package su.a71.tardim_ic.computercraft_compat.entity;
|
||||
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
public class FakeTardimPeripheralTileEntity implements ITardimPeripheralTileEntity {
|
||||
public BlockPos blockPos;
|
||||
public Level level;
|
||||
public TardimData data; // Our TARDIM
|
||||
|
||||
public FakeTardimPeripheralTileEntity(BlockPos in_block, Level in_level) {
|
||||
this.blockPos = in_block;
|
||||
this.level = in_level;
|
||||
this.data = getTardimDataInitial();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getPos() {
|
||||
return this.blockPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Level getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TardimData getTardim() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock() {
|
||||
return this.level.getBlockState(this.blockPos).getBlock();
|
||||
}
|
||||
|
||||
public TardimData getTardimDataInitial() {
|
||||
int X = this.getPos().getX(), Z = this.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 access a ghost TARDIM, do we?
|
||||
// If we fail checks here are not inside a TARDIM
|
||||
if (!found) {
|
||||
return null;
|
||||
}
|
||||
TardimData T = TardimManager.getTardim(index);
|
||||
if (T.getCurrentLocation() == null || T.getOwnerName() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return T;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package su.a71.tardim_ic.computercraft_compat.entity;
|
||||
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
// This is used to getPost(), getLevel() and getTardim() nicely without refactoring code to account for PeripheralProvider
|
||||
// At least I believe so. Otherwise, don't really remember why I don't just pass these methods to the peripherals.
|
||||
public interface ITardimPeripheralTileEntity {
|
||||
public BlockPos getPos();
|
||||
public Level getLevel();
|
||||
|
||||
public TardimData getTardim();
|
||||
|
||||
public Block getBlock();
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package su.a71.tardim_ic.computercraft_compat.peripherals;
|
||||
|
||||
import com.swdteam.tardim.common.block.BlockFuelStorage;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import su.a71.tardim_ic.computercraft_compat.entity.FakeTardimPeripheralTileEntity;
|
||||
|
||||
|
||||
/*
|
||||
* CC Peripheral for TARDIM's fuel storage block.
|
||||
* Only provides getters for the fuel parts for people who cannot afford or don't need the digital interface.
|
||||
*/
|
||||
public class FuelStoragePeripheral extends TardimPeripheral<BlockFuelStorage> implements IPeripheral {
|
||||
/**
|
||||
* @param tileEntity the tile entity of this peripheral
|
||||
* @hidden
|
||||
*/
|
||||
public FuelStoragePeripheral(FakeTardimPeripheralTileEntity tileEntity) {
|
||||
super(tileEntity, "tardim_fuel_storage", (BlockFuelStorage) tileEntity.getBlock());
|
||||
}
|
||||
|
||||
|
||||
// Peripheral methods ===============================================================
|
||||
|
||||
/**
|
||||
* Return how much fuel is left in the TARDIM
|
||||
*
|
||||
* @return Fuel left (Out of 100)
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final double getFuel() throws LuaException {
|
||||
return getTardimData().getFuel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get how much fuel it would take to travel to the destination
|
||||
* @return Amount of fuel needed (Out of 100)
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final double calculateFuelForJourney() throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
|
||||
if (data.getTravelLocation() == null) return 0;
|
||||
|
||||
TardimData.Location curr = data.getCurrentLocation();
|
||||
TardimData.Location dest = data.getTravelLocation();
|
||||
|
||||
double fuel = 0.0;
|
||||
|
||||
if (curr.getLevel() != dest.getLevel())
|
||||
{
|
||||
fuel = 10.0;
|
||||
}
|
||||
|
||||
Vec3 posA = new Vec3(curr.getPos().getX(), curr.getPos().getY(), curr.getPos().getZ());
|
||||
Vec3 posB = new Vec3(dest.getPos().getX(), dest.getPos().getY(), dest.getPos().getZ());
|
||||
fuel += posA.distanceTo(posB) / 100.0;
|
||||
if (fuel > 100.0) fuel = 100.0;
|
||||
|
||||
return fuel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package su.a71.tardim_ic.computercraft_compat.peripherals;
|
||||
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import su.a71.tardim_ic.computercraft_compat.entity.ITardimPeripheralTileEntity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
// Base CC peripheral for whn you need something with access to a TARDIM
|
||||
public abstract class TardimPeripheral<BL extends Block> implements IPeripheral {
|
||||
|
||||
private final List<IComputerAccess> connectedComputers = new ArrayList<>(); // List of computers connected to the peripheral
|
||||
public final ITardimPeripheralTileEntity tileEntity; // Peripheral's BlockEntity, used for accessing coordinates
|
||||
public final String name;
|
||||
private final BL block;
|
||||
|
||||
/**
|
||||
* @param tileEntity the tile entity of this peripheral
|
||||
* @hidden
|
||||
*/
|
||||
public TardimPeripheral(ITardimPeripheralTileEntity tileEntity, String name, BL block) {
|
||||
this.tileEntity = tileEntity;
|
||||
this.name = name;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BL getTarget() {
|
||||
return this.block;
|
||||
}
|
||||
|
||||
/** Setting name for the peripheral. A computer will see it as "digital_tardim_interface_n"
|
||||
* @hidden
|
||||
*/
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getType() { return this.name; }
|
||||
|
||||
/** Apparently CC uses this to check if the peripheral in front of a modem is this one
|
||||
* @hidden
|
||||
* @param iPeripheral The peripheral to compare against. This may be {@code null}.
|
||||
* @return {@code true} if the peripheral is the same as this one.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(@Nullable IPeripheral iPeripheral) { return this == iPeripheral; }
|
||||
|
||||
/** Called when a computer disconnects from the peripheral
|
||||
* @hidden
|
||||
* @param computer The interface to the computer that is being detached. Remember that multiple computers can be
|
||||
* attached to a peripheral at once.
|
||||
*/
|
||||
@Override
|
||||
public void detach(@Nonnull IComputerAccess computer) { connectedComputers.remove(computer); }
|
||||
|
||||
/** Called when a computer connects to the peripheral
|
||||
* @hidden
|
||||
* @param computer The interface to the computer that is being attached. Remember that multiple computers can be
|
||||
* attached to a peripheral at once.
|
||||
*/
|
||||
@Override
|
||||
public void attach(@Nonnull IComputerAccess computer) { connectedComputers.add(computer); }
|
||||
|
||||
/**
|
||||
* I *think* I use this to get peripheral's world position
|
||||
* @hidden
|
||||
* @return
|
||||
*/
|
||||
public ITardimPeripheralTileEntity getTileEntity() {
|
||||
return tileEntity;
|
||||
}
|
||||
|
||||
|
||||
public TardimData getTardimData() throws LuaException {
|
||||
TardimData data = this.getTileEntity().getTardim();
|
||||
if (data == null || data.getCurrentLocation() == null || data.getOwnerName() == null) {
|
||||
throw new LuaException("Peripheral is not inside a TARDIM");
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
package su.a71.tardim_ic.computercraft_compat.peripherals;
|
||||
|
||||
import com.swdteam.tardim.common.block.BlockTardimScanner;
|
||||
import com.swdteam.tardim.common.init.TardimRegistry;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.api.lua.ObjectLuaTable;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import su.a71.tardim_ic.computercraft_compat.entity.FakeTardimPeripheralTileEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/*
|
||||
* CC Peripheral for TARDIM's scanner block.
|
||||
* Only provides getters for data-related (mostly table output) methods e.g. biome or companion list
|
||||
* for people who cannot afford or don't need the digital interface.
|
||||
*/
|
||||
public class TardimScannerPeripheral extends TardimPeripheral<BlockTardimScanner> implements IPeripheral {
|
||||
/**
|
||||
* @param tileEntity the tile entity of this peripheral
|
||||
* @hidden
|
||||
*/
|
||||
public TardimScannerPeripheral(FakeTardimPeripheralTileEntity tileEntity) {
|
||||
super(tileEntity, "tardim_scanner", (BlockTardimScanner) tileEntity.getBlock());
|
||||
}
|
||||
|
||||
|
||||
// Peripheral methods ===============================================================
|
||||
|
||||
/**
|
||||
* Get username of the TARDIM's owner
|
||||
* @return String of the owner's username
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final String getOwnerName() throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
return data.getOwnerName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of the TARDIM owner's companions
|
||||
* @return ObjectLuaTable containing the usernames of the companions
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final ObjectLuaTable getCompanions() throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
Map<Integer, String> companions = new HashMap<>();
|
||||
for (int i = 0; i < data.getCompanions().size(); i++) {
|
||||
companions.put(i + 1, data.getCompanions().get(i).getUsername());
|
||||
}
|
||||
return new ObjectLuaTable(companions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get online players. Useful for making a GUI for the locate function or just a nice dashboard.
|
||||
*
|
||||
* @return ObjectLuaTable of the online players
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final ObjectLuaTable getOnlinePlayers() throws LuaException {
|
||||
if (this.tileEntity.getLevel().isClientSide()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PlayerList playerList = this.tileEntity.getLevel().getServer().getPlayerList();
|
||||
Map<Integer, String> players = new HashMap<>();
|
||||
for (int i = 0; i < playerList.getPlayers().size(); i++) {
|
||||
players.put(i + 1, playerList.getPlayers().get(i).getGameProfile().getName());
|
||||
}
|
||||
|
||||
return new ObjectLuaTable(players);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available TARDIM skins. Useful for making a GUI skin selection.
|
||||
*
|
||||
* @return ObjectLuaTable of the available skins
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final ObjectLuaTable getSkins() throws LuaException {
|
||||
if (this.getTileEntity().getLevel().isClientSide()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<Integer, String> skins = new HashMap<>();
|
||||
|
||||
Iterator var5 = TardimRegistry.getRegistry().keySet().iterator();
|
||||
int i = 0;
|
||||
while(var5.hasNext()) {
|
||||
ResourceLocation builder = (ResourceLocation)var5.next();
|
||||
TardimRegistry.TardimBuilder b = TardimRegistry.getTardimBuilder(builder);
|
||||
skins.put(i + 1, b.getDisplayName());
|
||||
i++;
|
||||
}
|
||||
|
||||
return new ObjectLuaTable(skins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a table with all registered biomes' names.
|
||||
* Useful for creating advanced navigation systems.
|
||||
* @return ObjectLuaTable with all biomes' technical names
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final ObjectLuaTable getBiomes() throws LuaException {
|
||||
Map<Integer, String> biomes = new HashMap<>();
|
||||
Registry<Biome> biomeRegistry = tileEntity.getLevel().registryAccess().registryOrThrow(Registries.BIOME);
|
||||
Iterator<ResourceLocation> biome_it = biomeRegistry.keySet().iterator();
|
||||
int i = 0;
|
||||
while (biome_it.hasNext()) {
|
||||
biomes.put(i + 1, biome_it.next().toString());
|
||||
i++;
|
||||
}
|
||||
|
||||
return new ObjectLuaTable(biomes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a table with all registered dimensions' names.
|
||||
* Useful for creating advanced navigation systems.
|
||||
* @return ObjectLuaTable with all dimensions' technical names
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final ObjectLuaTable getDimensions() throws LuaException {
|
||||
Iterator<ServerLevel> dim_it = this.getTileEntity().getLevel().getServer().getAllLevels().iterator(); // TODO: Does this really work?
|
||||
Map<Integer, String> dimensions = new HashMap<>();
|
||||
int i = 0;
|
||||
while (dim_it.hasNext()) {
|
||||
dimensions.put(i + 1, dim_it.next().dimension().location().toString());
|
||||
i++;
|
||||
}
|
||||
return new ObjectLuaTable(dimensions);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package su.a71.tardim_ic.computercraft_compat.peripherals;
|
||||
|
||||
import com.swdteam.tardim.common.block.BlockRotor;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.api.lua.ObjectLuaTable;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import su.a71.tardim_ic.computercraft_compat.entity.FakeTardimPeripheralTileEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
* CC Peripheral for TARDIM's time rotor block.
|
||||
* Only provides getters for the flight status for people who cannot afford or don't need the digital interface.
|
||||
*/
|
||||
public class TimeRotorPeripheral extends TardimPeripheral<BlockRotor> implements IPeripheral {
|
||||
/**
|
||||
* @param tileEntity the tile entity of this peripheral
|
||||
* @hidden
|
||||
*/
|
||||
public TimeRotorPeripheral(FakeTardimPeripheralTileEntity tileEntity) {
|
||||
super(tileEntity, "tardim_time_rotor", (BlockRotor) tileEntity.getBlock());
|
||||
}
|
||||
|
||||
|
||||
// Peripheral methods ===============================================================
|
||||
|
||||
/**
|
||||
* Check whether the TARDIM is in flight
|
||||
* @return true if in flight, false if not
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final boolean isInFlight() throws LuaException { return getTardimData().isInFlight(); }
|
||||
|
||||
/**
|
||||
* Supposedly gets UNIX timestamp of when we entered flight
|
||||
* @return UNIX timestamp if in flight, -1 if not
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final long getTimeEnteredFlight() throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
if (!data.isInFlight()) {
|
||||
return -1;
|
||||
}
|
||||
return data.getTimeEnteredFlight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current location of the TARDIM
|
||||
* @return ObjectLuaTable of the current location with the following keys:
|
||||
* <ul>
|
||||
* <li>dimension - String of the dimension</li>
|
||||
* <li>pos - table with the keys x, y, z that hold numbers</li>
|
||||
* <li>facing - String of the facing</li>
|
||||
* </ul>
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final ObjectLuaTable getCurrentLocation() throws LuaException {
|
||||
TardimData.Location loc = getTardimData().getCurrentLocation();
|
||||
return new ObjectLuaTable(Map.of(
|
||||
"dimension", loc.getLevel().location().toString(),
|
||||
"pos", new ObjectLuaTable(Map.of(
|
||||
"x", loc.getPos().getX(),
|
||||
"y", loc.getPos().getY(),
|
||||
"z", loc.getPos().getZ()
|
||||
)),
|
||||
"facing", loc.getFacing().toString()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current location of the TARDIM
|
||||
* @return if there is no destination returns null.
|
||||
* <p>
|
||||
* Otherwise, ObjectLuaTable of the current location with the following keys:
|
||||
* <ul>
|
||||
* <li>dimension - String of the dimension</li>
|
||||
* <li>pos - table with the keys x, y, z that hold numbers</li>
|
||||
* <li>facing - String of the facing</li>
|
||||
* </ul>
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final ObjectLuaTable getTravelLocation() throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
if (data.getTravelLocation() == null) {
|
||||
data.setTravelLocation(data.getCurrentLocation());
|
||||
}
|
||||
TardimData.Location loc = data.getTravelLocation();
|
||||
return new ObjectLuaTable(Map.of(
|
||||
"dimension", loc.getLevel().location().toString(),
|
||||
"pos", new ObjectLuaTable(Map.of(
|
||||
"x", loc.getPos().getX(),
|
||||
"y", loc.getPos().getY(),
|
||||
"z", loc.getPos().getZ()
|
||||
)),
|
||||
"facing", loc.getFacing().toString()
|
||||
));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package su.a71.tardim_ic.mixin;
|
||||
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import com.swdteam.tardim.tileentity.TileEntityFuelStorage;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import static com.swdteam.tardim.tardim.TardimManager.FUEL_MAP;
|
||||
|
||||
// This mixin aims to make TARDIM fuel system less awful by allowing users to put standard furnace fuel into it.
|
||||
@Mixin(value = TardimManager.class, remap = false)
|
||||
public class BetterFuelMapMixin {
|
||||
|
||||
@Overwrite
|
||||
public static boolean isFuel(Item i) {
|
||||
return FUEL_MAP.containsKey(i) || AbstractFurnaceBlockEntity.getFuel().containsKey(i);
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public static double getFuel(Item i) {
|
||||
if (!isFuel(i)) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if (!AbstractFurnaceBlockEntity.getFuel().containsKey(i)) {
|
||||
return (Double)FUEL_MAP.get(i);
|
||||
}
|
||||
else
|
||||
return AbstractFurnaceBlockEntity.getFuel().get(i) / 8000.0; // Adapt with coal's 1600 ticks -> 0.2 fuel
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package su.a71.tardim_ic.mixin;
|
||||
|
||||
import com.swdteam.tardim.common.block.BlockFuelStorage;
|
||||
import com.swdteam.tardim.common.init.TRDDimensions;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import com.swdteam.tardim.tileentity.TileEntityFuelStorage;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.BucketItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.HopperBlock;
|
||||
import net.minecraft.world.level.block.entity.HopperBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import static su.a71.tardim_ic.Constants.LOG;
|
||||
|
||||
@Mixin(value = TileEntityFuelStorage.class, remap = false)
|
||||
public class BetterFuelStorageMixin {
|
||||
|
||||
// This is rather inefficient as we iterate 2 times
|
||||
// However, the hoppers are so small and this method is called so rarely that it should be fine.
|
||||
@Inject(method = "serverTick(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lcom/swdteam/tardim/tileentity/TileEntityFuelStorage;)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/HopperBlockEntity;removeItem(II)Lnet/minecraft/world/item/ItemStack;"),
|
||||
locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private static void saveLavaBuckets(Level world, BlockPos pos, BlockState state, TileEntityFuelStorage blockEntity, CallbackInfo ci) {
|
||||
HopperBlockEntity mixin_hopper = (HopperBlockEntity)world.getBlockEntity(blockEntity.getBlockPos().above());
|
||||
for(int j = 0; j < mixin_hopper.getContainerSize(); ++j) {
|
||||
ItemStack stack = mixin_hopper.getItem(j);
|
||||
double fuel = TardimManager.getFuel(stack.getItem());
|
||||
if (fuel > 0.0) {
|
||||
if (stack.getItem() instanceof BucketItem) {
|
||||
LOG.info("THIS IS A BUCKET");
|
||||
mixin_hopper.setItem(j, new ItemStack(stack.getItem().getCraftingRemainingItem(), 2));
|
||||
} else {
|
||||
mixin_hopper.removeItem(j, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
Common/src/main/java/su/a71/tardim_ic/mixin/JammerMixin.java
Normal file
58
Common/src/main/java/su/a71/tardim_ic/mixin/JammerMixin.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package su.a71.tardim_ic.mixin;
|
||||
|
||||
import com.swdteam.tardim.common.command.tardim.CommandLocate;
|
||||
import com.swdteam.tardim.common.command.tardim.CommandTardimBase;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import static com.swdteam.tardim.common.command.tardim.CommandTardimBase.sendResponse;
|
||||
|
||||
@Mixin(value = CommandLocate.class, remap = false)
|
||||
public class JammerMixin {
|
||||
// @Inject(method="execute()V", at=@At(value = "INVOKE",
|
||||
// target = "Lcom/swdteam/tardim/tardim/TardimData;setTravelLocation(Lcom/swdteam/tardim/tardim/TardimData$Location;)V"))
|
||||
// public void execute(CallbackInfo ci) {
|
||||
// LOG.info("test");
|
||||
//// for (ItemStack armour : player.getArmorSlots()) {
|
||||
//// if (armour.is(LOCATION_JAMMER)) {
|
||||
//// sendResponse(player, "Player's location is jammed", CommandTardimBase.ResponseType.FAIL, source);
|
||||
//// ci.cancel();
|
||||
//// };
|
||||
//// }
|
||||
// }
|
||||
|
||||
@Overwrite
|
||||
public void execute(String[] args, Player player, BlockPos pos, CommandTardimBase.CommandSource source) {
|
||||
if (args.length == 1) {
|
||||
TardimData data = TardimManager.getFromPos(pos);
|
||||
if (data != null) {
|
||||
if (data.hasPermission(player)) {
|
||||
Player otherPlayer = player.getServer().getPlayerList().getPlayerByName(args[0]);
|
||||
if (otherPlayer != null) {
|
||||
for (ItemStack armour : otherPlayer.getArmorSlots()) {
|
||||
// if (armour.is(PERSONAL_JAMMER)) {
|
||||
// sendResponse(player, otherPlayer.getGameProfile().getName() + "'s location is jammed", CommandTardimBase.ResponseType.FAIL, source);
|
||||
// return;
|
||||
// }
|
||||
// TODO: Re-add
|
||||
}
|
||||
data.setTravelLocation(new TardimData.Location(otherPlayer.blockPosition(), otherPlayer.level().dimension()));
|
||||
sendResponse(player, "Coords locked on to " + otherPlayer.getGameProfile().getName(), CommandTardimBase.ResponseType.COMPLETE, source);
|
||||
} else {
|
||||
sendResponse(player, "Player does not exist", CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
} else {
|
||||
sendResponse(player, "You do not have permission", CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sendResponse(player, ((CommandLocate)(Object)this).getUsage(), CommandTardimBase.ResponseType.FAIL, source);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package su.a71.tardim_ic.platform;
|
||||
|
||||
import com.example.examplemod.Constants;
|
||||
import su.a71.tardim_ic.Constants;
|
||||
import su.a71.tardim_ic.platform.services.IPlatformHelper;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
@ -19,7 +19,7 @@ public class Services {
|
|||
final T loadedService = ServiceLoader.load(clazz)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||
Constants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
||||
// Constants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
|
||||
return loadedService;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,16 @@
|
|||
package su.a71.tardim_ic.platform.services;
|
||||
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface IPlatformHelper {
|
||||
|
||||
/**
|
||||
|
@ -33,6 +44,4 @@ public interface IPlatformHelper {
|
|||
|
||||
return isDevelopmentEnvironment() ? "development" : "production";
|
||||
}
|
||||
|
||||
// TODO: Add registration stuff here?
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"parent": "tardim_ic:block/redstone_tardim_input",
|
||||
"textures": {
|
||||
"1": "tardim_ic:block/redstone_input_lit",
|
||||
"2": "tardim_ic:block/redstone_input_lit",
|
||||
"particle": "tardim_ic:block/redstone_input_lit"
|
||||
}
|
||||
}
|
|
@ -1,20 +1,13 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "su.a71.tardim_ic.mixin",
|
||||
"refmap": "${mod_id}.refmap.json",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
"server": [
|
||||
"BetterFuelMapMixin",
|
||||
"BetterFuelStorageMixin",
|
||||
"JammerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "su.a71.tardim_ic.mixin",
|
||||
"refmap": "${mod_id}.refmap.json",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
|
||||
|
|
BIN
Common/tardim-1.2.2-dev.jar
Normal file
BIN
Common/tardim-1.2.2-dev.jar
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue