parent
1d19f464c5
commit
d989f493c2
137 changed files with 7 additions and 8 deletions
72
Fabric/build.gradle
Normal file
72
Fabric/build.gradle
Normal file
|
@ -0,0 +1,72 @@
|
|||
plugins {
|
||||
id 'java'
|
||||
id 'idea'
|
||||
id 'maven-publish'
|
||||
id 'fabric-loom'
|
||||
}
|
||||
base {
|
||||
archivesName = "${mod_name}-fabric-${minecraft_version}"
|
||||
}
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||
mappings loom.officialMojangMappings()
|
||||
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
|
||||
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
|
||||
implementation project(":common")
|
||||
|
||||
modImplementation("curse.maven:tardim-531315:4668945")
|
||||
// modCompileOnly("com.simibubi.create:create-fabric-1.20.1:0.5.1-d-build.1118+mc1.20.1")
|
||||
modCompileOnly("cc.tweaked:cc-tweaked-$minecraft_version-fabric-api:$cc_version")
|
||||
}
|
||||
|
||||
loom {
|
||||
if (project(":common").file("src/main/resources/${mod_id}.accesswidener").exists()) {
|
||||
accessWidenerPath.set(project(":common").file("src/main/resources/${mod_id}.accesswidener"))
|
||||
}
|
||||
mixin {
|
||||
defaultRefmapName.set("${mod_id}.refmap.json")
|
||||
}
|
||||
runs {
|
||||
client {
|
||||
client()
|
||||
setConfigName("Fabric Client")
|
||||
ideConfigGenerated(true)
|
||||
runDir("run")
|
||||
}
|
||||
server {
|
||||
server()
|
||||
setConfigName("Fabric Server")
|
||||
ideConfigGenerated(true)
|
||||
runDir("run")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
source(project(":common").sourceSets.main.allSource)
|
||||
}
|
||||
tasks.withType(Javadoc).configureEach {
|
||||
source(project(":common").sourceSets.main.allJava)
|
||||
}
|
||||
tasks.named("sourcesJar", Jar) {
|
||||
from(project(":common").sourceSets.main.allSource)
|
||||
}
|
||||
|
||||
processResources {
|
||||
from project(":common").sourceSets.main.resources
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
artifactId base.archivesName.get()
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
url "file://" + System.getenv("local_maven")
|
||||
}
|
||||
}
|
||||
}
|
12
Fabric/src/main/java/su/a71/tardim_ic/TardimInControl.java
Normal file
12
Fabric/src/main/java/su/a71/tardim_ic/TardimInControl.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package su.a71.tardim_ic;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.Registration;
|
||||
|
||||
public class TardimInControl implements ModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
Registration.register();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package su.a71.tardim_ic.blocks.food_machine;
|
||||
|
||||
import com.swdteam.tardim.common.init.TRDDimensions;
|
||||
import com.swdteam.tardim.common.init.TRDSounds;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.Registration;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class FoodMachineBlock extends HorizontalDirectionalBlock implements EntityBlock {
|
||||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
||||
|
||||
public FoodMachineBlock() {
|
||||
super(Properties.of().strength(2, 4).noOcclusion().mapColor(MapColor.METAL)); // No occlusion?
|
||||
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
||||
}
|
||||
|
||||
public BlockState getStateForPlacement(BlockPlaceContext $$0) {
|
||||
return this.defaultBlockState().setValue(FACING, $$0.getHorizontalDirection().getOpposite());
|
||||
}
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> $$0) {
|
||||
$$0.add(FACING);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
|
||||
return Registration.FOOD_MACHINE_BE.create(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState blockState, Level w, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult p_60508_) {
|
||||
if (!w.isClientSide) {
|
||||
w.playSound(null, blockPos, TRDSounds.TARDIM_BEEP, SoundSource.BLOCKS, 0.3F, 0.5F);
|
||||
BlockEntity be = w.getBlockEntity(blockPos);
|
||||
if (be instanceof FoodMachineBlockEntity && w.dimension() == TRDDimensions.TARDIS) {
|
||||
TardimData data = TardimManager.getFromPos(blockPos);
|
||||
if (data != null && data.hasPermission(player)) {
|
||||
if (data.getFuel() >= 0.2) {
|
||||
data.setFuel(data.getFuel() - 0.2); // Remove some fuel in exchange for food
|
||||
ItemEntity food = new ItemEntity(EntityType.ITEM, w);
|
||||
|
||||
// Select type of food here
|
||||
food.setItem(new ItemStack(Items.BREAD, 1));
|
||||
|
||||
food.setPos(Vec3.atCenterOf(blockPos).add(new Vec3(0, 0.2, 0)));
|
||||
w.addFreshEntity(food);
|
||||
} else {
|
||||
player.displayClientMessage(
|
||||
Component.literal("You do not have enough fuel").withStyle(ChatFormatting.DARK_RED).withStyle(ChatFormatting.BOLD), true
|
||||
);
|
||||
}
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
||||
player.displayClientMessage(
|
||||
Component.literal("You do not have permission").withStyle(ChatFormatting.DARK_RED).withStyle(ChatFormatting.BOLD), true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
||||
public boolean canSurvive(BlockState blockState, LevelReader levelReader, BlockPos blockPos) {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package su.a71.tardim_ic.blocks.food_machine;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.Registration;
|
||||
|
||||
public class FoodMachineBlockEntity extends BlockEntity {
|
||||
public int curr_food_index;
|
||||
|
||||
public FoodMachineBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(Registration.FOOD_MACHINE_BE, pos, state);
|
||||
this.curr_food_index = 0;
|
||||
}
|
||||
|
||||
public BlockPos getPos() {
|
||||
return this.worldPosition;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveAdditional(CompoundTag tag) {
|
||||
tag.putInt("curr_food_index", curr_food_index);
|
||||
//tag.putBoolean("is_powered", isPowered);
|
||||
super.saveAdditional(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
curr_food_index = tag.getInt("curr_food_index");
|
||||
//lastPlayer = tag.getUUID("last_player");
|
||||
//event.addListener(new FuelMapReloadListener(GSON, "tardim_fuel"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package su.a71.tardim_ic.blocks.redstone_input;
|
||||
|
||||
import com.swdteam.tardim.common.block.BlockBaseTardimPanel;
|
||||
import com.swdteam.tardim.common.init.TRDDimensions;
|
||||
import com.swdteam.tardim.common.init.TRDSounds;
|
||||
import com.swdteam.tardim.network.NetworkHandler;
|
||||
import com.swdteam.tardim.network.PacketOpenEditGui;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
import com.swdteam.tardim.tileentity.TileEntityBaseTardimPanel;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.DebugPackets;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.Registration;
|
||||
import su.a71.tardim_ic.utils.FakePlayer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBlock {
|
||||
|
||||
public RedstoneInputBlock() {
|
||||
super(FabricBlockSettings.create().strength(2, 4).mapColor(MapColor.TERRACOTTA_ORANGE)); // No occlusion? this.setDefaultState((BlockState)this.getDefaultState().with(ON, false));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
|
||||
return Registration.REDSTONE_INPUT_BE.create(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState blockState, Level w, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult p_60508_) {
|
||||
if (!w.isClientSide) {
|
||||
|
||||
w.playSound(null, blockPos, TRDSounds.TARDIM_BEEP, SoundSource.BLOCKS, 0.3F, 0.5F);
|
||||
|
||||
BlockEntity be = w.getBlockEntity(blockPos);
|
||||
if (be instanceof RedstoneInputBlockEntity && w.dimension() == TRDDimensions.TARDIS) {
|
||||
TardimData data = TardimManager.getFromPos(blockPos);
|
||||
if (data != null && data.hasPermission(player)) {
|
||||
((RedstoneInputBlockEntity) be).lastPlayer = player.getGameProfile().getId();
|
||||
NetworkHandler.sendTo((ServerPlayer)player, new PacketOpenEditGui(blockPos, 1));
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
||||
player.displayClientMessage(
|
||||
Component.literal("You do not have permission").withStyle(ChatFormatting.DARK_RED).withStyle(ChatFormatting.BOLD), true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
||||
public boolean canSurvive(BlockState blockState, LevelReader levelReader, BlockPos blockPos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void neighborChanged(BlockState blockState, Level level, BlockPos blockPos, Block block, BlockPos fromPos, boolean isMoving) {
|
||||
DebugPackets.sendNeighborsUpdatePacket(level, blockPos);
|
||||
|
||||
BlockEntity be = level.getBlockEntity(blockPos);
|
||||
if (!(be instanceof RedstoneInputBlockEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get redstone signal
|
||||
Direction direction = blockState.getValue(FACING);
|
||||
int redstoneSignal = level.getSignal(blockPos, direction);
|
||||
if (redstoneSignal > 0 && !((RedstoneInputBlockEntity) be).isPowered) {
|
||||
((RedstoneInputBlockEntity) be).isPowered = true;
|
||||
if (level.dimension() == TRDDimensions.TARDIS) {
|
||||
TardimData data = TardimManager.getFromPos(blockPos);
|
||||
if (data != null && !level.isClientSide && ((RedstoneInputBlockEntity) be).lastPlayer != null) {
|
||||
if (((TileEntityBaseTardimPanel)be).hasCommand()) {
|
||||
((TileEntityBaseTardimPanel)be).execute(new FakePlayer(level, blockPos, ((RedstoneInputBlockEntity) be).lastPlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (redstoneSignal == 0 && ((RedstoneInputBlockEntity) be).isPowered) {
|
||||
((RedstoneInputBlockEntity) be).isPowered = false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package su.a71.tardim_ic.blocks.redstone_input;
|
||||
|
||||
import com.swdteam.tardim.tileentity.TileEntityBaseTardimPanel;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.Registration;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class RedstoneInputBlockEntity extends TileEntityBaseTardimPanel {
|
||||
public boolean isPowered = false;
|
||||
public UUID lastPlayer = null;
|
||||
|
||||
public RedstoneInputBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(Registration.REDSTONE_INPUT_BE, pos, state);
|
||||
}
|
||||
|
||||
public BlockPos getPos() {
|
||||
return this.worldPosition;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveAdditional(CompoundTag tag) {
|
||||
tag.putBoolean("is_powered", isPowered);
|
||||
if (lastPlayer != null) {
|
||||
tag.putUUID("last_player", lastPlayer);
|
||||
}
|
||||
super.saveAdditional(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
isPowered = tag.getBoolean("is_powered");
|
||||
lastPlayer = tag.getUUID("last_player");
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Do we need more roundels?
|
|
@ -0,0 +1,63 @@
|
|||
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.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.Registration;
|
||||
|
||||
|
||||
/*
|
||||
This command transmits the cloister bell sound in a big enough radius that you could hear it in any reasonably sized interior.
|
||||
*/
|
||||
public class CommandCloisterBell 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)) {
|
||||
try {
|
||||
Level lvl = player.level();
|
||||
if (!lvl.isClientSide) {
|
||||
lvl.playSound(
|
||||
null,
|
||||
pos,
|
||||
Registration.CLOISTER_BELL,
|
||||
SoundSource.BLOCKS,
|
||||
1.5f,
|
||||
1f
|
||||
);
|
||||
}
|
||||
} catch (Exception var9) {
|
||||
CommandTardimBase.sendResponse(player, "There was an error", 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 "cloister-bell";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/cloister-bell";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandTardimBase.CommandSource allowedSource() {
|
||||
return CommandTardimBase.CommandSource.BOTH;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package su.a71.tardim_ic.command;
|
||||
|
||||
import com.swdteam.tardim.common.init.CommandManager;
|
||||
|
||||
public class CommandInit {
|
||||
public static void init() {
|
||||
CommandManager.register(new CommandCloisterBell());
|
||||
CommandManager.register(new CommandListBiomes());
|
||||
CommandManager.register(new CommandListDimensions());
|
||||
}
|
||||
|
||||
public static void addCC() {
|
||||
CommandManager.register(new CommandModemTransmit());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package su.a71.tardim_ic.computercraft_compat.digital_interface;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.ComputerCraftCompat;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
public class DigitalInterfaceBlock extends Block implements EntityBlock {
|
||||
|
||||
public DigitalInterfaceBlock() {
|
||||
super(Properties.of().strength(2, 4).noOcclusion().mapColor(MapColor.METAL));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
|
||||
return ComputerCraftCompat.DIGITAL_INTERFACE_BE.create(pos, state);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package su.a71.tardim_ic.computercraft_compat.digital_interface;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import static su.a71.tardim_ic.tardim_ic.registration.ComputerCraftCompat.DIGITAL_INTERFACE_BE;
|
||||
|
||||
|
||||
public class DigitalInterfaceTileEntity extends BlockEntity {
|
||||
public DigitalInterfaceTileEntity(BlockPos pos, BlockState state) {
|
||||
super(DIGITAL_INTERFACE_BE, pos, state);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,829 @@
|
|||
package su.a71.tardim_ic.computercraft_compat.peripherals;
|
||||
|
||||
import com.swdteam.tardim.common.command.tardim.CommandTravel;
|
||||
import com.swdteam.tardim.common.init.TRDSounds;
|
||||
import com.swdteam.tardim.common.init.TardimRegistry;
|
||||
import com.swdteam.tardim.common.item.ItemTardim;
|
||||
import com.swdteam.tardim.tardim.TardimData;
|
||||
import com.swdteam.tardim.tardim.TardimData.Location;
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
|
||||
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 com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import su.a71.tardim_ic.computercraft_compat.digital_interface.DigitalInterfaceBlock;
|
||||
import su.a71.tardim_ic.computercraft_compat.entity.FakeTardimPeripheralTileEntity;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.Registration;
|
||||
import su.a71.tardim_ic.utils.FakePlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class DigitalInterfacePeripheral extends TardimPeripheral<DigitalInterfaceBlock> implements IPeripheral {
|
||||
/**
|
||||
* @param tileEntity the tile entity of this peripheral
|
||||
* @hidden
|
||||
*/
|
||||
public DigitalInterfacePeripheral(FakeTardimPeripheralTileEntity tileEntity) {
|
||||
super(tileEntity, "digital_tardim_interface", (DigitalInterfaceBlock) 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;
|
||||
|
||||
Location curr = data.getCurrentLocation();
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the TARDIM is locked
|
||||
* @return true if locked, false if not
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final boolean isLocked() throws LuaException {
|
||||
return getTardimData().isLocked();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock/unlock the TARDIM
|
||||
* @param locked true to lock, false to unlock
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void setLocked(boolean locked) throws LuaException {
|
||||
getTardimData().setLocked(locked);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
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());
|
||||
}
|
||||
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()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* CommandTravel.isValidPath is for some reason private on Fabric so we reverse engineer it :/
|
||||
* SWDteam pls fix
|
||||
* @hidden
|
||||
*/
|
||||
private boolean isValidPathTemp(String s) {
|
||||
for(int i = 0; i < s.length(); ++i) {
|
||||
if (!CommandTravel.validPathChar(s.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* DimensionMapReloadListener.toTitleCase is unavailable so we reverse engineer it! :D
|
||||
* Fabric... pls fix?
|
||||
* @hidden
|
||||
*/
|
||||
private String toTitleCase(String input) {
|
||||
StringBuilder titleCase = new StringBuilder(input.length());
|
||||
boolean nextTitleCase = true;
|
||||
char[] var3 = input.toCharArray();
|
||||
int var4 = var3.length;
|
||||
|
||||
for(int var5 = 0; var5 < var4; ++var5) {
|
||||
char c = var3[var5];
|
||||
if (Character.isSpaceChar(c)) {
|
||||
nextTitleCase = true;
|
||||
} else if (nextTitleCase) {
|
||||
c = Character.toTitleCase(c);
|
||||
nextTitleCase = false;
|
||||
}
|
||||
|
||||
titleCase.append(c);
|
||||
}
|
||||
|
||||
return titleCase.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set dimension for the TARDIM to travel to
|
||||
* <p>
|
||||
* This is a serious hazard right now due to the fact that I am unable to check if the dimension is valid.
|
||||
* <p>
|
||||
* TODO: If invalid dimension is given, the TARDIM is unable to land until the dimension is changed. Add proper checks.
|
||||
* @param dimension String of the dimension e.g. "minecraft:overworld"
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void setDimension(String dimension) throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
|
||||
String key = dimension;
|
||||
dimension = toTitleCase(dimension);
|
||||
if (TardimManager.DIMENSION_MAP.containsKey(dimension)) {
|
||||
key = (String)TardimManager.DIMENSION_MAP.get(dimension);
|
||||
} else {
|
||||
dimension = dimension.toLowerCase();
|
||||
}
|
||||
|
||||
if (!isValidPathTemp(key)) {
|
||||
throw new LuaException("Invalid dimension");
|
||||
} else {
|
||||
ResourceKey<Level> dim = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(dimension));
|
||||
if (data.getTravelLocation() == null) {
|
||||
data.setTravelLocation(new Location(data.getCurrentLocation()));
|
||||
}
|
||||
|
||||
data.getTravelLocation().setLocation(dim);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the destination's coordinates
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param z Z coordinate
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void setTravelLocation(int x, int y, int z) throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
if (data.getTravelLocation() == null) {
|
||||
data.setTravelLocation(new Location(data.getCurrentLocation()));
|
||||
}
|
||||
|
||||
data.getTravelLocation().setPosition(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set destination to the TARDIM's owner's home (Must be online)
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void home() throws LuaException {
|
||||
if (this.getTileEntity().getLevel().isClientSide()) {
|
||||
return;
|
||||
}
|
||||
TardimData data = getTardimData();
|
||||
|
||||
UUID uuid = data.getOwner();
|
||||
String username = data.getOwnerName();
|
||||
if (uuid == null || username == null) {
|
||||
throw new LuaException("TARDIM has no owner");
|
||||
}
|
||||
|
||||
PlayerList playerList = this.getTileEntity().getLevel().getServer().getPlayerList();
|
||||
ServerPlayer player = playerList.getPlayer(uuid);
|
||||
if (player == null) {
|
||||
throw new LuaException("TARDIM owner is not online");
|
||||
}
|
||||
|
||||
ResourceKey<Level> dim = player.getRespawnDimension();
|
||||
BlockPos pos = player.getRespawnPosition();
|
||||
if (pos == null) {
|
||||
throw new LuaException("TARDIM owner has no home");
|
||||
}
|
||||
|
||||
setDimension(dim.location().toString());
|
||||
setTravelLocation(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set destination for a player's location (Player must be online)
|
||||
* @param username - String of the username of the player
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void locatePlayer(String username) throws LuaException {
|
||||
if (this.getTileEntity().getLevel().isClientSide()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerList playerList = this.getTileEntity().getLevel().getServer().getPlayerList();
|
||||
|
||||
ServerPlayer player = playerList.getPlayerByName(username);
|
||||
if (player == null) {
|
||||
throw new LuaException("Player not found");
|
||||
}
|
||||
|
||||
// for (ItemStack armour : player.getArmorSlots()) {
|
||||
//// if (armour.is(PERSONAL_JAMMER)) {
|
||||
//// throw new LuaException("Player location jammed");
|
||||
//// };
|
||||
// // TODO: Re-add
|
||||
// }
|
||||
|
||||
ResourceKey<Level> dim = player.getCommandSenderWorld().dimension();
|
||||
BlockPos pos = player.blockPosition();
|
||||
|
||||
setDimension(dim.location().toString());
|
||||
setTravelLocation(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.getTileEntity().getLevel().isClientSide()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PlayerList playerList = this.getTileEntity().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 the rotation of the TARDIM's door
|
||||
* @return String of the door rotation ("north", "south", "east", "west")
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final String getDoorRotation() throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
Direction rotation = data.getTravelLocation().getFacing();
|
||||
switch (rotation) {
|
||||
case NORTH -> {
|
||||
return "north";
|
||||
}
|
||||
case EAST -> {
|
||||
return "east";
|
||||
}
|
||||
case SOUTH -> {
|
||||
return "south";
|
||||
}
|
||||
case WEST -> {
|
||||
return "west";
|
||||
}
|
||||
default -> {
|
||||
throw new LuaException("Invalid door rotation");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rotation of the TARDIM's door
|
||||
* @param rotation String of the door rotation ("north", "south", "east", "west")
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void setDoorRotation(String rotation) throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
switch (rotation) {
|
||||
case "north" -> data.getTravelLocation().setFacing(Direction.NORTH);
|
||||
case "east" -> data.getTravelLocation().setFacing(Direction.EAST);
|
||||
case "south" -> data.getTravelLocation().setFacing(Direction.SOUTH);
|
||||
case "west" -> data.getTravelLocation().setFacing(Direction.WEST);
|
||||
default -> throw new LuaException("Invalid door rotation");
|
||||
}
|
||||
|
||||
data.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the rotation of the TARDIM's door (north -> east -> south -> west -> north)
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void toggleDoorRotation() throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
if (data.getTravelLocation() == null) {
|
||||
data.setTravelLocation(new Location(data.getCurrentLocation()));
|
||||
}
|
||||
|
||||
if (data.getTravelLocation().getFacing() == null) {
|
||||
data.getTravelLocation().setFacing(Direction.NORTH);
|
||||
}
|
||||
|
||||
switch (data.getTravelLocation().getFacing()) {
|
||||
case NORTH -> data.getTravelLocation().setFacing(Direction.EAST);
|
||||
case EAST -> data.getTravelLocation().setFacing(Direction.SOUTH);
|
||||
case SOUTH -> data.getTravelLocation().setFacing(Direction.WEST);
|
||||
case WEST -> data.getTravelLocation().setFacing(Direction.NORTH);
|
||||
default -> data.getTravelLocation().setFacing(Direction.NORTH);
|
||||
}
|
||||
|
||||
data.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a number to the destination's coordinates
|
||||
* @param axis String of the axis ("x", "y", "z")
|
||||
* @param amount Number to add to the axis
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void coordAdd(String axis, int amount) throws LuaException {
|
||||
TardimData data = getTardimData();
|
||||
if (data.getTravelLocation() == null) {
|
||||
data.setTravelLocation(new Location(data.getCurrentLocation()));
|
||||
}
|
||||
|
||||
Location location = data.getTravelLocation();
|
||||
switch (axis) {
|
||||
case "x" -> location.addPosition(amount, 0, 0);
|
||||
case "y" -> location.addPosition(0, amount, 0);
|
||||
case "z" -> location.addPosition(0, 0, amount);
|
||||
default -> throw new LuaException("Invalid axis");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dematerialize the TARDIM
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void demat() throws LuaException {
|
||||
if (this.tileEntity.getLevel().isClientSide()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TardimData data = getTardimData();
|
||||
|
||||
if (data.isInFlight()) {
|
||||
throw new LuaException("TARDIM is already in flight");
|
||||
}
|
||||
Location loc = data.getCurrentLocation();
|
||||
ServerLevel level = this.tileEntity.getLevel().getServer().getLevel(loc.getLevel());
|
||||
ItemTardim.destroyTardim(level, loc.getPos(), Direction.NORTH);
|
||||
data.setInFlight(true);
|
||||
if (data.getTravelLocation() == null) {
|
||||
data.setTravelLocation(new Location(data.getCurrentLocation()));
|
||||
}
|
||||
|
||||
// TODO: This is a horrendous way of doing this. Please fix.
|
||||
String level_str = "tardim:tardis_dimension";
|
||||
this.tileEntity.getLevel().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(level_str))).playSound(null, this.tileEntity.getPos(), (SoundEvent) TRDSounds.TARDIM_TAKEOFF, SoundSource.AMBIENT, 1.0F, 1.0F);
|
||||
|
||||
data.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Way to use function from Tardim (ModInitializer)
|
||||
* 1WTC pls fix
|
||||
* @hidden
|
||||
*/
|
||||
public static boolean isPosValid(Level level, BlockPos pos) {
|
||||
return validPos(level, pos) && validPos(level, pos.above()) && validPos(level, pos.above().above()) && validPos(level, pos.north()) && validPos(level, pos.north().above()) && validPos(level, pos.south()) && validPos(level, pos.south().above()) && validPos(level, pos.east()) && validPos(level, pos.east().above()) && validPos(level, pos.west()) && validPos(level, pos.west().above());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DigitalInterfacePeripheral#isPosValid(Level, BlockPos)
|
||||
* @hidden
|
||||
*/
|
||||
private static boolean validPos(Level l, BlockPos pos) {
|
||||
BlockState blockstate = l.getBlockState(pos);
|
||||
return !blockstate.canBeReplaced() && blockstate.getBlock() != Blocks.SNOW ? blockstate.isAir() : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Materialize the TARDIM at the destination
|
||||
* <p>
|
||||
* Has a LOT of checks to make sure the TARDIM can materialize, so please implement error handling if you use this.
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void remat() throws LuaException {
|
||||
if (this.tileEntity.getLevel().isClientSide()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TardimData data = getTardimData();
|
||||
|
||||
if (data.isInFlight()) {
|
||||
if (data.getTimeEnteredFlight() < System.currentTimeMillis() / 1000L - 10L) {
|
||||
Location loc = data.getTravelLocation();
|
||||
ServerLevel level = this.tileEntity.getLevel().getServer().getLevel(loc.getLevel());
|
||||
double fuel = data.calculateFuelForJourney(
|
||||
this.tileEntity.getLevel().getServer().getLevel(data.getCurrentLocation().getLevel()), level, data.getCurrentLocation().getPos(), loc.getPos()
|
||||
);
|
||||
if (data.getFuel() >= fuel) {
|
||||
level.getChunk(loc.getPos());
|
||||
BlockPos landingPosButBetter = CommandTravel.getLandingPosition(level, loc.getPos());
|
||||
boolean recalc = false;
|
||||
|
||||
for(int jj = 0; jj < 32; ++jj) {
|
||||
if (!Block.canSupportRigidBlock(level, landingPosButBetter.below())) {
|
||||
BlockPos pos2 = landingPosButBetter.offset(
|
||||
level.random.nextInt(10) * (level.random.nextBoolean() ? 1 : -1),
|
||||
0,
|
||||
level.random.nextInt(10) * (level.random.nextBoolean() ? 1 : -1)
|
||||
);
|
||||
landingPosButBetter = CommandTravel.getLandingPosition(level, pos2);
|
||||
if (Block.canSupportRigidBlock(level, landingPosButBetter.below())) {
|
||||
recalc = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!recalc) {
|
||||
for(int jj = 0; jj < 32; ++jj) {
|
||||
if (!Block.canSupportRigidBlock(level, landingPosButBetter.below())) {
|
||||
BlockPos pos2 = landingPosButBetter.offset(
|
||||
level.random.nextInt(30) * (level.random.nextBoolean() ? 1 : -1),
|
||||
0,
|
||||
level.random.nextInt(30) * (level.random.nextBoolean() ? 1 : -1)
|
||||
);
|
||||
landingPosButBetter = CommandTravel.getLandingPosition(level, pos2);
|
||||
if (Block.canSupportRigidBlock(level, landingPosButBetter.below())) {
|
||||
recalc = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!recalc) {
|
||||
for(int jj = 0; jj < 32; ++jj) {
|
||||
if (!Block.canSupportRigidBlock(level, landingPosButBetter.below())) {
|
||||
BlockPos pos2 = landingPosButBetter.offset(
|
||||
level.random.nextInt(50) * (level.random.nextBoolean() ? 1 : -1),
|
||||
0,
|
||||
level.random.nextInt(50) * (level.random.nextBoolean() ? 1 : -1)
|
||||
);
|
||||
landingPosButBetter = CommandTravel.getLandingPosition(level, pos2);
|
||||
if (Block.canSupportRigidBlock(level, landingPosButBetter.below())) {
|
||||
recalc = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Block.canSupportRigidBlock(level, landingPosButBetter.below())) {
|
||||
loc.setPosition(landingPosButBetter.getX(), landingPosButBetter.getY(), landingPosButBetter.getZ());
|
||||
if (isPosValid(level, loc.getPos())) {
|
||||
TardimRegistry.TardimBuilder builder = TardimRegistry.getTardimBuilder(data.getTardimID());
|
||||
builder.buildTardim(level, loc.getPos(), data.getTravelLocation().getFacing(), data.getId());
|
||||
data.setCurrentLocation(data.getTravelLocation());
|
||||
data.setTravelLocation(null);
|
||||
data.setInFlight(false);
|
||||
data.addFuel(-fuel);
|
||||
data.save();
|
||||
|
||||
// if (!recalc) {
|
||||
// sendResponse(player, "TARDIM is landing", CommandTardimBase.ResponseType.COMPLETE, source);
|
||||
// } else {
|
||||
// sendResponse(player, "Landing recalculated due to obstruction", CommandTardimBase.ResponseType.INFO, source);
|
||||
// sendResponse(player, "TARDIM is landing", CommandTardimBase.ResponseType.COMPLETE, source);
|
||||
// }
|
||||
|
||||
String level_str = "tardim:tardis_dimension";
|
||||
this.tileEntity.getLevel().getServer().getLevel(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(level_str))).playSound(null, this.tileEntity.getPos(), (SoundEvent) TRDSounds.TARDIM_LANDING, SoundSource.AMBIENT, 1.0F, 1.0F);
|
||||
|
||||
} else {
|
||||
throw new LuaException("TARDIM landing obstructed. Aborting...");
|
||||
}
|
||||
} else {
|
||||
throw new LuaException("TARDIM landing obstructed. Aborting...");
|
||||
}
|
||||
} else {
|
||||
throw new LuaException("Not enough fuel for journey");
|
||||
}
|
||||
} else {
|
||||
throw new LuaException("TARDIM is still taking off");
|
||||
}
|
||||
} else {
|
||||
throw new LuaException("TARDIM has already landed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate a biome
|
||||
* @param biome_str String of the biome e.g. "minecraft:plains"
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void locateBiome(String biome_str) throws LuaException {
|
||||
if (this.tileEntity.getLevel().isClientSide()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TardimData data = getTardimData();
|
||||
if (data.getTravelLocation() == null) {
|
||||
data.setTravelLocation(new Location(data.getCurrentLocation()));
|
||||
}
|
||||
|
||||
Optional<Biome> biome = this.tileEntity.getLevel().getServer()
|
||||
.registryAccess()
|
||||
.registryOrThrow(Registries.BIOME)
|
||||
.getOptional(new ResourceLocation(biome_str));
|
||||
if (biome != null && biome.isPresent()) {
|
||||
if (data.getTravelLocation() == null) {
|
||||
data.setTravelLocation(new Location(data.getCurrentLocation()));
|
||||
}
|
||||
|
||||
ServerLevel level = this.tileEntity.getLevel().getServer().getLevel(data.getTravelLocation().getLevel());
|
||||
BlockPos blockpos = new BlockPos(
|
||||
data.getTravelLocation().getPos().getX(),
|
||||
level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, data.getTravelLocation().getPos()).getY(),
|
||||
data.getTravelLocation().getPos().getZ()
|
||||
);
|
||||
BlockPos blockpos1 = this.findNearestBiome(level, (Biome)biome.get(), blockpos, 6400, 8);
|
||||
if (blockpos1 != null) {
|
||||
data.getTravelLocation().setPosition(blockpos1.getX(), blockpos1.getY(), blockpos1.getZ());
|
||||
data.save();
|
||||
} else {
|
||||
throw new LuaException("Biome not found");
|
||||
}
|
||||
} else {
|
||||
throw new LuaException("Unknown biome");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to find a biome
|
||||
* @param level ServerLevel to search
|
||||
* @param biome Biome to find
|
||||
* @param pos BlockPos to start from
|
||||
* @param i Idk what this is, likely a radius
|
||||
* @param j No idea about this either
|
||||
* @return BlockPos of the biome
|
||||
* @hidden
|
||||
*/
|
||||
public BlockPos findNearestBiome(ServerLevel level, Biome biome, BlockPos pos, int i, int j) {
|
||||
Pair<BlockPos, Holder<Biome>> bb = level.getChunkSource()
|
||||
.getGenerator()
|
||||
.getBiomeSource()
|
||||
.findBiomeHorizontal(
|
||||
pos.getX(),
|
||||
pos.getY(),
|
||||
pos.getZ(),
|
||||
i,
|
||||
j,
|
||||
b_val -> b_val.value() == biome,
|
||||
level.random,
|
||||
true,
|
||||
level.getChunkSource().randomState().sampler()
|
||||
);
|
||||
return bb != null && bb.getFirst() != null ? (BlockPos)bb.getFirst() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the skin of the TARDIM
|
||||
* @param skin Skin name to change to
|
||||
* @hidden
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void setSkin(String skin) throws LuaException {
|
||||
if (this.tileEntity.getLevel().isClientSide()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TardimData data = getTardimData();
|
||||
|
||||
ResourceLocation skinToApply = null;
|
||||
Iterator var13 = TardimRegistry.getRegistry().keySet().iterator();
|
||||
|
||||
label39: {
|
||||
ResourceLocation builder;
|
||||
TardimRegistry.TardimBuilder b;
|
||||
do {
|
||||
if (!var13.hasNext()) {
|
||||
break label39;
|
||||
}
|
||||
|
||||
builder = (ResourceLocation)var13.next();
|
||||
b = TardimRegistry.getTardimBuilder(builder);
|
||||
} while(!b.getDisplayName().equalsIgnoreCase(skin) && !builder.toString().equalsIgnoreCase(skin));
|
||||
|
||||
skinToApply = builder;
|
||||
}
|
||||
|
||||
if (skinToApply == null) {
|
||||
throw new LuaException("Skin '" + skin + "' not found");
|
||||
}
|
||||
|
||||
TardimData.Location loc = data.getCurrentLocation();
|
||||
ServerLevel level = this.tileEntity.getLevel().getServer().getLevel(loc.getLevel());
|
||||
data.setIdentifier(skinToApply);
|
||||
|
||||
// FakePlayer...
|
||||
TardimRegistry.getTardimBuilder(skinToApply).changeTardimSkin(data, level, loc.getPos(), loc.getFacing(), new FakePlayer(this.tileEntity.getLevel(), this.tileEntity.getPos()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.tileEntity.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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play cloister bell sound.
|
||||
*/
|
||||
@LuaFunction(mainThread = true)
|
||||
public final void cloisterBell() throws LuaException {
|
||||
if (this.tileEntity.getLevel().isClientSide()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Level lvl = this.tileEntity.getLevel();
|
||||
if (!lvl.isClientSide) {
|
||||
lvl.playSound(
|
||||
null,
|
||||
this.tileEntity.getPos(),
|
||||
Registration.CLOISTER_BELL,
|
||||
SoundSource.BLOCKS,
|
||||
1.5f,
|
||||
1f
|
||||
);
|
||||
}
|
||||
} catch (Exception var9) {
|
||||
throw new LuaException("There was an error trying to play the sound");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.tileEntity.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,3 @@
|
|||
Display sources for the cartridge loader
|
||||
|
||||
* Inserted X/Y/Z/Dimension
|
|
@ -0,0 +1,5 @@
|
|||
Display sources for the docking station:
|
||||
|
||||
* Owner of docked TARDIM
|
||||
* Lock status
|
||||
* Docked TARDIM's companion list
|
|
@ -0,0 +1,61 @@
|
|||
//package su.a71.tardim_ic.display_source.fuel_storage;
|
||||
//
|
||||
//
|
||||
//import com.simibubi.create.content.redstone.displayLink.DisplayLinkContext;
|
||||
//import com.simibubi.create.content.redstone.displayLink.source.PercentOrProgressBarDisplaySource;
|
||||
//import com.simibubi.create.foundation.gui.ModularGuiLineBuilder;
|
||||
//import com.simibubi.create.foundation.utility.Lang;
|
||||
//
|
||||
//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.world.level.block.entity.BlockEntity;
|
||||
//import net.fabricmc.api.EnvType;
|
||||
//import net.fabricmc.api.Environment;
|
||||
//
|
||||
//import static su.a71.tardim_ic.tardim_ic.Constants.LOG;
|
||||
//
|
||||
//public class FuelLevelDisplaySource extends PercentOrProgressBarDisplaySource {
|
||||
// @Override
|
||||
// protected Float getProgress(DisplayLinkContext context) {
|
||||
// if (context.level() != context.level().getServer().getLevel(TRDDimensions.TARDIS)) {
|
||||
// return null;
|
||||
// }
|
||||
// BlockEntity te = context.getSourceBlockEntity();
|
||||
// if (!(te instanceof TileEntityFuelStorage fuelStorage))
|
||||
// return null;
|
||||
// TardimData data = TardimManager.getFromPos(fuelStorage.getBlockPos());
|
||||
// LOG.info(String.valueOf((float) (data.getFuel())));
|
||||
// return (float) (data.getFuel() / 100);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected boolean progressBarActive(DisplayLinkContext context) {
|
||||
// return context.sourceConfig()
|
||||
// .getInt("Mode") != 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected String getTranslationKey() {
|
||||
// return "fuel_level";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Environment(EnvType.CLIENT)
|
||||
// public void initConfigurationWidgets(DisplayLinkContext context, ModularGuiLineBuilder builder, boolean isFirstLine) {
|
||||
// super.initConfigurationWidgets(context, builder, isFirstLine);
|
||||
// if (isFirstLine)
|
||||
// return;
|
||||
// builder.addSelectionScrollInput(0, 120,
|
||||
// (si, l) -> si.forOptions(Lang.translatedOptions("display_source.fuel_level", "percent", "progress_bar"))
|
||||
// .titled(Lang.translateDirect("display_source.fuel_level.display")),
|
||||
// "Mode");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected boolean allowsLabeling(DisplayLinkContext context) {
|
||||
// return true;
|
||||
// }
|
||||
//}
|
|
@ -0,0 +1,54 @@
|
|||
//package su.a71.tardim_ic.display_source.fuel_storage;
|
||||
//
|
||||
//import com.simibubi.create.content.redstone.displayLink.DisplayLinkContext;
|
||||
//import com.simibubi.create.content.redstone.displayLink.source.NumericSingleLineDisplaySource;
|
||||
//import com.simibubi.create.content.redstone.displayLink.target.DisplayTargetStats;
|
||||
//import com.simibubi.create.foundation.utility.Components;
|
||||
//
|
||||
//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.network.chat.MutableComponent;
|
||||
//import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
//import net.minecraft.world.phys.Vec3;
|
||||
//
|
||||
//public class RequiredFuelDisplaySource extends NumericSingleLineDisplaySource {
|
||||
// @Override
|
||||
// protected MutableComponent provideLine(DisplayLinkContext displayLinkContext, DisplayTargetStats displayTargetStats) {
|
||||
// if (displayLinkContext.level() != displayLinkContext.level().getServer().getLevel(TRDDimensions.TARDIS))
|
||||
// return null;
|
||||
// BlockEntity te = displayLinkContext.getSourceBlockEntity();
|
||||
// if (!(te instanceof TileEntityFuelStorage fuelStorage))
|
||||
// return null;
|
||||
// TardimData data = TardimManager.getFromPos(fuelStorage.getBlockPos());
|
||||
//
|
||||
// if (data.getTravelLocation() == null) return ZERO.copy();
|
||||
//
|
||||
// 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 Components.literal(String.valueOf(fuel));
|
||||
// }
|
||||
//
|
||||
// protected String getTranslationKey() {
|
||||
// return "required_fuel";
|
||||
// }
|
||||
//
|
||||
// protected boolean allowsLabeling(DisplayLinkContext context) {
|
||||
// return true;
|
||||
// }
|
||||
//}
|
|
@ -0,0 +1,5 @@
|
|||
Display sources for the scanner:
|
||||
|
||||
* Owner name
|
||||
* Companion list
|
||||
* Get current TARDIM skin
|
|
@ -0,0 +1,5 @@
|
|||
Display sources for the time rotor:
|
||||
|
||||
* Both current and destination - X/Y/Z/Dimension
|
||||
* Flight status YES/NO
|
||||
*
|
|
@ -0,0 +1,56 @@
|
|||
package su.a71.tardim_ic.jammer;
|
||||
|
||||
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.item.ArmorItem;
|
||||
import net.minecraft.world.item.ArmorMaterial;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PersonalJammerMaterial implements ArmorMaterial {
|
||||
private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11};
|
||||
private static final int[] PROTECTION_VALUES = new int[] {1, 1, 1, 1};
|
||||
|
||||
@Override
|
||||
public int getDurabilityForType(ArmorItem.Type type) {
|
||||
return BASE_DURABILITY[type.getSlot().getIndex()] * 33;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefenseForType(ArmorItem.Type type) {
|
||||
return PROTECTION_VALUES[type.getSlot().getIndex()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantmentValue() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SoundEvent getEquipSound() {
|
||||
return SoundEvents.ARMOR_EQUIP_GENERIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Ingredient getRepairIngredient() {
|
||||
return Ingredient.of(Items.IRON_INGOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
// Must be all lowercase
|
||||
return "personal_jammer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getToughness() {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockbackResistance() {
|
||||
return 0.1F;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package su.a71.tardim_ic.mixin;
|
||||
|
||||
import com.swdteam.tardim.tardim.TardimManager;
|
||||
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 = true)
|
||||
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 = true)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package su.a71.tardim_ic.mixin;
|
||||
|
||||
import com.swdteam.tardim.common.init.CommandManager;
|
||||
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;
|
||||
import su.a71.tardim_ic.command.CommandInit;
|
||||
import su.a71.tardim_ic.platform.Services;
|
||||
|
||||
@Mixin(value = CommandManager.class, remap = false)
|
||||
public class CommandsMixin {
|
||||
@Inject(method="init()V", at=@At("TAIL"))
|
||||
private static void init(CallbackInfo ci) {
|
||||
CommandInit.init();
|
||||
if (Services.PLATFORM.isModLoaded("computercraft")) {
|
||||
CommandInit.addCC();
|
||||
}
|
||||
System.out.println("TARDIM: IC added commands using mixin");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package su.a71.tardim_ic.platform;
|
||||
|
||||
import su.a71.tardim_ic.platform.services.IPlatformHelper;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
public class FabricPlatformHelper implements IPlatformHelper {
|
||||
@Override
|
||||
public String getPlatformName() {
|
||||
return "Fabric";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModLoaded(String modId) {
|
||||
|
||||
return FabricLoader.getInstance().isModLoaded(modId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDevelopmentEnvironment() {
|
||||
|
||||
return FabricLoader.getInstance().isDevelopmentEnvironment();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package su.a71.tardim_ic.soviet_chronobox;
|
||||
|
||||
import com.swdteam.tardim.common.init.TRDTiles;
|
||||
import com.swdteam.tardim.tileentity.TileEntityTardim;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import su.a71.tardim_ic.tardim_ic.registration.Exteriors;
|
||||
|
||||
public class SovietChronoboxTileEntity extends TileEntityTardim {
|
||||
public SovietChronoboxTileEntity(BlockPos pos, BlockState state) {
|
||||
super(Exteriors.TILE_SOVIET_CHRONOBOX, pos, state);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package su.a71.tardim_ic.tardim_ic.registration;
|
||||
|
||||
import com.swdteam.tardim.common.block.BlockFuelStorage;
|
||||
import com.swdteam.tardim.common.block.BlockRotor;
|
||||
import com.swdteam.tardim.common.block.BlockTardimScanner;
|
||||
import dan200.computercraft.api.peripheral.PeripheralLookup;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import su.a71.tardim_ic.Constants;
|
||||
import su.a71.tardim_ic.computercraft_compat.digital_interface.DigitalInterfaceBlock;
|
||||
import su.a71.tardim_ic.computercraft_compat.digital_interface.DigitalInterfaceTileEntity;
|
||||
import su.a71.tardim_ic.computercraft_compat.entity.FakeTardimPeripheralTileEntity;
|
||||
import su.a71.tardim_ic.computercraft_compat.peripherals.DigitalInterfacePeripheral;
|
||||
import su.a71.tardim_ic.computercraft_compat.peripherals.FuelStoragePeripheral;
|
||||
import su.a71.tardim_ic.computercraft_compat.peripherals.TardimScannerPeripheral;
|
||||
import su.a71.tardim_ic.computercraft_compat.peripherals.TimeRotorPeripheral;
|
||||
|
||||
import static com.swdteam.tardim.common.init.TRDBlocks.*;
|
||||
import static su.a71.tardim_ic.tardim_ic.registration.Registration.registerBlock;
|
||||
|
||||
public class ComputerCraftCompat {
|
||||
public static final Block DIGITAL_TARDIM_INTERFACE = new DigitalInterfaceBlock();
|
||||
|
||||
public static final BlockEntityType<DigitalInterfaceTileEntity> DIGITAL_INTERFACE_BE = Registry.register(
|
||||
BuiltInRegistries.BLOCK_ENTITY_TYPE,
|
||||
new ResourceLocation("tardim_ic", "digital_tardim_interface"),
|
||||
FabricBlockEntityTypeBuilder.create(DigitalInterfaceTileEntity::new, DIGITAL_TARDIM_INTERFACE).build()
|
||||
);
|
||||
|
||||
public static void register() {
|
||||
Constants.LOG.info("Loaded ComputerCraft compatibility!");
|
||||
|
||||
registerBlock("digital_tardim_interface", () -> DIGITAL_TARDIM_INTERFACE, null);
|
||||
|
||||
PeripheralLookup.get().registerForBlockEntity((entity, direction) -> new DigitalInterfacePeripheral(new FakeTardimPeripheralTileEntity(entity.getBlockPos(), entity.getLevel())), DIGITAL_INTERFACE_BE);
|
||||
PeripheralLookup.get().registerForBlocks((world, pos, state, blockEntity, direction) -> {
|
||||
if (state.getBlock() instanceof BlockFuelStorage) {
|
||||
return new FuelStoragePeripheral(new FakeTardimPeripheralTileEntity(pos, world));
|
||||
} else if (state.getBlock() instanceof BlockRotor) {
|
||||
return new TimeRotorPeripheral(new FakeTardimPeripheralTileEntity(pos, world));
|
||||
} else if (state.getBlock() instanceof BlockTardimScanner) {
|
||||
return new TardimScannerPeripheral(new FakeTardimPeripheralTileEntity(pos, world));
|
||||
}
|
||||
return null;
|
||||
}, FUEL_STORAGE, SCANNER, ROTOR);
|
||||
}
|
||||
|
||||
public static void addToTab(CreativeModeTab.ItemDisplayParameters itemDisplayParameters, CreativeModeTab.Output output) {
|
||||
output.accept(DIGITAL_TARDIM_INTERFACE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package su.a71.tardim_ic.tardim_ic.registration;
|
||||
|
||||
|
||||
//import com.simibubi.create.content.redstone.displayLink.AllDisplayBehaviours;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import su.a71.tardim_ic.Constants;
|
||||
//import su.a71.tardim_ic.display_source.fuel_storage.FuelLevelDisplaySource;
|
||||
//import su.a71.tardim_ic.display_source.fuel_storage.RequiredFuelDisplaySource;
|
||||
//
|
||||
//import static com.swdteam.tardim.common.init.TRDTiles.TILE_FUEL_STORAGE;
|
||||
|
||||
public class CreateCompat {
|
||||
|
||||
public static void register() {
|
||||
Constants.LOG.info("Loaded Create compatibility!");
|
||||
//
|
||||
// AllDisplayBehaviours.assignBlockEntity(AllDisplayBehaviours.register(new ResourceLocation(Constants.MOD_ID, "fuel_storage_display_source"), new FuelLevelDisplaySource()), TILE_FUEL_STORAGE);
|
||||
// AllDisplayBehaviours.assignBlockEntity(AllDisplayBehaviours.register(new ResourceLocation(Constants.MOD_ID, "fuel_required_display_source"), new RequiredFuelDisplaySource()), TILE_FUEL_STORAGE);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package su.a71.tardim_ic.tardim_ic.registration;
|
||||
|
||||
import com.mojang.datafixers.types.Type;
|
||||
import com.swdteam.tardim.common.block.BlockTardimDoors;
|
||||
import com.swdteam.tardim.common.block.BlockTardimFloor;
|
||||
import com.swdteam.tardim.common.block.BlockTardimRoof;
|
||||
import com.swdteam.tardim.common.init.TardimRegistry;
|
||||
import com.swdteam.tardim.tileentity.TileEntityTardim;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.datafix.fixes.References;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import su.a71.tardim_ic.Constants;
|
||||
import su.a71.tardim_ic.soviet_chronobox.SovietChronoboxTileEntity;
|
||||
|
||||
public class Exteriors {
|
||||
// Soviet Chronobox
|
||||
public static TardimRegistry.TardimBuilder TARDIM_TYPE_SOVIET;
|
||||
public static Block DOOR_SOVIET_CHRONOBOX;
|
||||
public static Block ROOF_SOVIET_CHRONOBOX;
|
||||
public static Block FLOOR_SOVIET_CHRONOBOX;
|
||||
public static BlockEntityType<TileEntityTardim> TILE_SOVIET_CHRONOBOX;
|
||||
|
||||
private static <T extends BlockEntity> BlockEntityType<T> createTardimTile(String string, FabricBlockEntityTypeBuilder<T> builder) {
|
||||
Type<?> type = Util.fetchChoiceType(References.BLOCK_ENTITY, string);
|
||||
return (BlockEntityType) Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, new ResourceLocation(Constants.MOD_ID, string), builder.build(type));
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
FLOOR_SOVIET_CHRONOBOX = Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(Constants.MOD_ID, "tardim_floor_soviet"), new BlockTardimFloor(FabricBlockSettings.create().sounds(SoundType.WOOD).strength(-1.0F, 3600000.0F).noLootTable().noOcclusion(), new BlockTardimFloor.TardimTileData() {
|
||||
public BlockEntityType<TileEntityTardim> getType() {
|
||||
return TILE_SOVIET_CHRONOBOX;
|
||||
}
|
||||
public BlockEntityTicker<? super TileEntityTardim> getTicker() {
|
||||
return TileEntityTardim::serverTick;
|
||||
}
|
||||
public BlockEntity createBlockEntity(BlockPos var1, BlockState var2) {
|
||||
return new SovietChronoboxTileEntity(var1, var2);
|
||||
}
|
||||
}));
|
||||
TILE_SOVIET_CHRONOBOX = createTardimTile("tardim_soviet_chronobox", FabricBlockEntityTypeBuilder.create(SovietChronoboxTileEntity::new, new Block[]{FLOOR_SOVIET_CHRONOBOX}));
|
||||
DOOR_SOVIET_CHRONOBOX = Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(Constants.MOD_ID, "tardim_door_soviet"), new BlockTardimDoors(FabricBlockSettings.create().sounds(SoundType.WOOD).strength(-1.0F, 3600000.0F).noLootTable().noOcclusion()));
|
||||
ROOF_SOVIET_CHRONOBOX = Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(Constants.MOD_ID, "tardim_roof_soviet"), new BlockTardimRoof(FabricBlockSettings.create().sounds(SoundType.WOOD).strength(-1.0F, 3600000.0F).noLootTable().noOcclusion()));
|
||||
TARDIM_TYPE_SOVIET = new TardimRegistry.TardimBuilder(new ResourceLocation(Constants.MOD_ID, "tardim_soviet_chronobox"), "TARDIM Soviet Chronobox", ROOF_SOVIET_CHRONOBOX, DOOR_SOVIET_CHRONOBOX, FLOOR_SOVIET_CHRONOBOX);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package su.a71.tardim_ic.tardim_ic.registration;
|
||||
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import su.a71.tardim_ic.Constants;
|
||||
import su.a71.tardim_ic.blocks.food_machine.FoodMachineBlock;
|
||||
import su.a71.tardim_ic.blocks.food_machine.FoodMachineBlockEntity;
|
||||
import su.a71.tardim_ic.blocks.redstone_input.RedstoneInputBlock;
|
||||
import su.a71.tardim_ic.blocks.redstone_input.RedstoneInputBlockEntity;
|
||||
import su.a71.tardim_ic.computercraft_compat.digital_interface.DigitalInterfaceBlock;
|
||||
import su.a71.tardim_ic.computercraft_compat.digital_interface.DigitalInterfaceTileEntity;
|
||||
import su.a71.tardim_ic.platform.Services;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Registration {
|
||||
public static final Block REDSTONE_INPUT = new RedstoneInputBlock();
|
||||
public static final BlockEntityType<RedstoneInputBlockEntity> REDSTONE_INPUT_BE = Registry.register(
|
||||
BuiltInRegistries.BLOCK_ENTITY_TYPE,
|
||||
new ResourceLocation(Constants.MOD_ID, "redstone_tardim_input"),
|
||||
FabricBlockEntityTypeBuilder.create(RedstoneInputBlockEntity::new, REDSTONE_INPUT).build()
|
||||
);
|
||||
|
||||
public static final Block FOOD_MACHINE = new FoodMachineBlock();
|
||||
public static final BlockEntityType<FoodMachineBlockEntity> FOOD_MACHINE_BE = Registry.register(
|
||||
BuiltInRegistries.BLOCK_ENTITY_TYPE,
|
||||
new ResourceLocation(Constants.MOD_ID, "food_machine"),
|
||||
FabricBlockEntityTypeBuilder.create(FoodMachineBlockEntity::new, FOOD_MACHINE).build()
|
||||
);
|
||||
|
||||
public static final SoundEvent CLOISTER_BELL = SoundEvent.createVariableRangeEvent(new ResourceLocation(Constants.MOD_ID, "cloister"));
|
||||
|
||||
public static final CreativeModeTab TAB = FabricItemGroup.builder()
|
||||
.icon(() -> new ItemStack(REDSTONE_INPUT))
|
||||
.title(Component.translatable("itemGroup.tardim_ic"))
|
||||
.displayItems(((itemDisplayParameters, output) -> {
|
||||
output.accept(REDSTONE_INPUT);
|
||||
output.accept(FOOD_MACHINE);
|
||||
if (FabricLoader.getInstance().isModLoaded("computercraft")) {
|
||||
ComputerCraftCompat.addToTab(itemDisplayParameters, output);
|
||||
}
|
||||
}))
|
||||
.build();
|
||||
|
||||
public static void registerBlock(String name, Supplier<? extends Block> supplier, CreativeModeTab tab)
|
||||
{
|
||||
Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(Constants.MOD_ID, name), supplier.get());
|
||||
BlockItem blockItem = new BlockItem(supplier.get(), new FabricItemSettings());
|
||||
Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(Constants.MOD_ID, name), blockItem);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, new ResourceLocation("tardim_ic", "item_group"), TAB);
|
||||
|
||||
registerBlock("redstone_tardim_input", () -> REDSTONE_INPUT, null);
|
||||
registerBlock("food_machine", () -> FOOD_MACHINE, null);
|
||||
|
||||
Registry.register(BuiltInRegistries.SOUND_EVENT, new ResourceLocation(Constants.MOD_ID, "cloister"), CLOISTER_BELL);
|
||||
|
||||
Exteriors.register();
|
||||
if (FabricLoader.getInstance().isModLoaded("computercraft")) {
|
||||
ComputerCraftCompat.register();
|
||||
}
|
||||
if (FabricLoader.getInstance().isModLoaded("create")) {
|
||||
CreateCompat.register();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
su.a71.tardim_ic.platform.FabricPlatformHelper
|
36
Fabric/src/main/resources/fabric.mod.json
Normal file
36
Fabric/src/main/resources/fabric.mod.json
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "tardim_ic",
|
||||
"version": "${version}",
|
||||
"name": "TARDIM: In Control",
|
||||
"description": "All of time and space, now automated and improved. This mod aims to improve your TARDIM experience",
|
||||
"authors": [
|
||||
"${mod_author}"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://tardim.a71.su/",
|
||||
"sources": "https://github.com/Andrew-71/tardim-in-control"
|
||||
},
|
||||
"license": "MIT",
|
||||
"icon": "assets/tardim_ic/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"su.a71.tardim_ic.TardimInControl"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"tardim_ic.mixins.json",
|
||||
"tardim_ic.fabric.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14",
|
||||
"fabric": "*",
|
||||
"minecraft": ">=1.20.1",
|
||||
"java": ">=17",
|
||||
"tardim": ">=1.2.2"
|
||||
},
|
||||
"suggests": {
|
||||
"computercraft": ">=${cc_version}"
|
||||
}
|
||||
}
|
20
Fabric/src/main/resources/tardim_ic.fabric.mixins.json
Normal file
20
Fabric/src/main/resources/tardim_ic.fabric.mixins.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "su.a71.tardim_ic.mixin",
|
||||
"refmap": "${mod_id}.refmap.json",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"CommandsMixin",
|
||||
"BetterFuelStorageMixin",
|
||||
"BetterFuelMapMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
"server": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue