From 9e9412e53e6e902d486c2cac8ae2975e2feedbce Mon Sep 17 00:00:00 2001 From: Andrew-71 Date: Sun, 16 Apr 2023 23:46:48 +0300 Subject: [PATCH] The Masters Dalek Plan --- .../tardim_ic/tardim_ic/utils/FakePlayer.java | 7 +- .../tardim_ic/models/block/tardim_dock.json | 158 +++++++++++++----- .../a71/tardim_ic/tardim_ic/Registration.java | 13 ++ .../command/CommandCloisterBell.java | 11 +- .../tardim_ic/tardim_ic/mixin/FuelTank.java | 34 ++++ .../redstone_input/RedstoneInputBlock.java | 30 ++-- .../RedstoneInputTileEntity.java | 23 +++ .../tardim_ic/tardim_dock/DockData.java | 21 +++ .../tardim_ic/tardim_dock/DockManager.java | 88 ++++++++++ .../tardim_dock/TardimDockBlock.java | 8 +- .../tardim_dock/TardimDockBlockEntity.java | 1 + Fabric/src/main/resources/fabric.mod.json | 3 + .../src/main/resources/tardim_ic.mixins.json | 14 ++ Forge/build.gradle | 9 + .../a71/tardim_ic/tardim_ic/Registration.java | 14 +- .../tardim_ic/tardim_ic/TardimInControl.java | 2 +- .../command/CommandCloisterBell.java | 19 ++- .../tardim_ic/tardim_ic/mixin/Commands.java | 17 ++ .../tardim_ic/tardim_ic/mixin/FuelTank.java | 9 + .../RedstoneInputTileEntity.java | 28 ---- .../RedstoneInputBlock.java | 28 ++-- .../RedstoneInputTileEntity.java | 41 +++++ .../tardim_ic/registration/CommandInit.java | 2 +- .../src/main/resources/mixins.tardim_ic.json | 15 ++ README.md | 36 ++-- 25 files changed, 492 insertions(+), 139 deletions(-) create mode 100644 Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/FuelTank.java create mode 100644 Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/DockData.java create mode 100644 Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/DockManager.java create mode 100644 Fabric/src/main/resources/tardim_ic.mixins.json create mode 100644 Forge/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/Commands.java create mode 100644 Forge/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/FuelTank.java delete mode 100644 Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redsone_input/RedstoneInputTileEntity.java rename Forge/src/main/java/su/a71/tardim_ic/tardim_ic/{redsone_input => redstone_input}/RedstoneInputBlock.java (80%) create mode 100644 Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputTileEntity.java create mode 100644 Forge/src/main/resources/mixins.tardim_ic.json diff --git a/Common/src/main/java/su/a71/tardim_ic/tardim_ic/utils/FakePlayer.java b/Common/src/main/java/su/a71/tardim_ic/tardim_ic/utils/FakePlayer.java index 583e975..c55aabc 100644 --- a/Common/src/main/java/su/a71/tardim_ic/tardim_ic/utils/FakePlayer.java +++ b/Common/src/main/java/su/a71/tardim_ic/tardim_ic/utils/FakePlayer.java @@ -10,7 +10,12 @@ import java.util.UUID; public class FakePlayer extends Player { public FakePlayer(Level lvl, BlockPos blockPos) { - super(lvl, blockPos, 0, new GameProfile(UUID.randomUUID(), "DigitalInterfaceFakePlayer"), null); + super(lvl, blockPos, 0, new GameProfile(UUID.randomUUID(), "FakePlayer_tardimic"), null); + } + + public FakePlayer(Level lvl, BlockPos blockPos, UUID id) { + super(lvl, blockPos, 0, new GameProfile(id, "FakePlayer_tardimic"), null); + } @Override diff --git a/Common/src/main/resources/assets/tardim_ic/models/block/tardim_dock.json b/Common/src/main/resources/assets/tardim_ic/models/block/tardim_dock.json index 8f72de8..bc13bb6 100644 --- a/Common/src/main/resources/assets/tardim_ic/models/block/tardim_dock.json +++ b/Common/src/main/resources/assets/tardim_ic/models/block/tardim_dock.json @@ -1,9 +1,8 @@ { "credit": "Made with Blockbench", - "render": "translucent", "texture_size": [64, 64], "textures": { - "0": "tardim_ic:blocks/tardim_dock", + "1": "tardim_ic:blocks/tardim_dock", "particle": "tardim_ic:blocks/tardim_dock" }, "elements": [ @@ -11,76 +10,128 @@ "from": [2, 0, 2], "to": [14, 12, 14], "faces": { - "north": {"uv": [4, 0, 7, 3], "texture": "#0"}, - "east": {"uv": [4, 3, 7, 6], "texture": "#0"}, - "south": {"uv": [4, 6, 7, 9], "texture": "#0"}, - "west": {"uv": [7, 0, 10, 3], "texture": "#0"}, - "up": {"uv": [10, 6, 7, 3], "texture": "#0"}, - "down": {"uv": [10, 6, 7, 9], "texture": "#0"} + "north": {"uv": [4, 0, 7, 3], "texture": "#1"}, + "east": {"uv": [4, 3, 7, 6], "texture": "#1"}, + "south": {"uv": [4, 6, 7, 9], "texture": "#1"}, + "west": {"uv": [7, 0, 10, 3], "texture": "#1"}, + "up": {"uv": [10, 6, 7, 3], "texture": "#1"}, + "down": {"uv": [10, 6, 7, 9], "texture": "#1"} } }, { "from": [0, 12, 0], "to": [16, 16, 16], "faces": { - "north": {"uv": [0, 8, 4, 9], "texture": "#0"}, - "east": {"uv": [0, 9, 4, 10], "texture": "#0"}, - "south": {"uv": [4, 9, 8, 10], "texture": "#0"}, - "west": {"uv": [8, 9, 12, 10], "texture": "#0"}, - "up": {"uv": [4, 4, 0, 0], "texture": "#0"}, - "down": {"uv": [4, 4, 0, 8], "texture": "#0"} + "north": {"uv": [0, 8, 4, 9], "texture": "#1"}, + "east": {"uv": [0, 9, 4, 10], "texture": "#1"}, + "south": {"uv": [4, 9, 8, 10], "texture": "#1"}, + "west": {"uv": [8, 9, 12, 10], "texture": "#1"}, + "up": {"uv": [4, 4, 0, 0], "texture": "#1"}, + "down": {"uv": [4, 4, 0, 8], "texture": "#1"} } }, { - "from": [12, 0, 0], - "to": [12, 12, 2], + "from": [12, 7, 0], + "to": [12, 12, 1], "rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]}, "faces": { - "north": {"uv": [0, 0, 0, 3], "texture": "#0"}, - "east": {"uv": [10.5, 0, 10, 3], "texture": "#0"}, - "south": {"uv": [0, 0, 0, 3], "texture": "#0"}, - "west": {"uv": [10, 0, 10.5, 3], "texture": "#0"}, - "up": {"uv": [0, 0.5, 0, 0], "texture": "#0"}, - "down": {"uv": [0, 0, 0, 0.5], "texture": "#0"} + "north": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "east": {"uv": [10.25, 0, 10, 1.25], "texture": "#1"}, + "south": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "west": {"uv": [10, 0, 10.25, 1.25], "texture": "#1"}, + "up": {"uv": [0, 0.5, 0, 0], "texture": "#1"}, + "down": {"uv": [0, 0, 0, 0.5], "texture": "#1"} } }, { - "from": [4, 0, 14], + "from": [12, 6, 1], + "to": [12, 7, 2], + "rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]}, + "faces": { + "north": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "east": {"uv": [10.5, 1.25, 10.25, 1.5], "texture": "#1"}, + "south": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "west": {"uv": [10.5, 1.25, 10.25, 1.5], "texture": "#1"}, + "up": {"uv": [0, 0.5, 0, 0], "texture": "#1"}, + "down": {"uv": [0, 0, 0, 0.5], "texture": "#1"} + } + }, + { + "from": [4, 4, 0], + "to": [4, 12, 1], + "rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]}, + "faces": { + "north": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "east": {"uv": [1.25, 10, 1, 12], "texture": "#1"}, + "south": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "west": {"uv": [1, 10, 1.25, 12], "texture": "#1"}, + "up": {"uv": [0, 0.5, 0, 0], "texture": "#1"}, + "down": {"uv": [0, 0, 0, 0.5], "texture": "#1"} + } + }, + { + "from": [4, 3, 1], + "to": [4, 4, 2], + "rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]}, + "faces": { + "north": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "east": {"uv": [1.5, 12, 1.25, 12.25], "texture": "#1"}, + "south": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "west": {"uv": [1.25, 12, 1.5, 12.25], "texture": "#1"}, + "up": {"uv": [0, 0.5, 0, 0], "texture": "#1"}, + "down": {"uv": [0, 0, 0, 0.5], "texture": "#1"} + } + }, + { + "from": [4, 7, 15], "to": [4, 12, 16], "rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]}, "faces": { - "north": {"uv": [0, 0, 0, 3], "texture": "#0"}, - "east": {"uv": [10, 0, 10.5, 3], "texture": "#0"}, - "south": {"uv": [0, 0, 0, 3], "texture": "#0"}, - "west": {"uv": [10.5, 0, 10, 3], "texture": "#0"}, - "up": {"uv": [0, 0.5, 0, 0], "rotation": 180, "texture": "#0"}, - "down": {"uv": [0, 0, 0, 0.5], "rotation": 180, "texture": "#0"} + "north": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "east": {"uv": [10, 0, 10.25, 1.25], "texture": "#1"}, + "south": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "west": {"uv": [10.25, 0, 10, 1.25], "texture": "#1"}, + "up": {"uv": [0, 0.5, 0, 0], "rotation": 180, "texture": "#1"}, + "down": {"uv": [0, 0, 0, 0.5], "rotation": 180, "texture": "#1"} } }, { - "from": [4, 0, 0], - "to": [4, 12, 2], + "from": [4, 6, 14], + "to": [4, 7, 15], "rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]}, "faces": { - "north": {"uv": [0, 0, 0, 3], "texture": "#0"}, - "east": {"uv": [1.5, 10, 1, 13], "texture": "#0"}, - "south": {"uv": [0, 0, 0, 3], "texture": "#0"}, - "west": {"uv": [1, 10, 1.5, 13], "texture": "#0"}, - "up": {"uv": [0, 0.5, 0, 0], "texture": "#0"}, - "down": {"uv": [0, 0, 0, 0.5], "texture": "#0"} + "north": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "east": {"uv": [10.5, 1.25, 10.25, 1.5], "texture": "#1"}, + "south": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "west": {"uv": [10.5, 1.25, 10.25, 1.5], "texture": "#1"}, + "up": {"uv": [0, 0.5, 0, 0], "rotation": 180, "texture": "#1"}, + "down": {"uv": [0, 0, 0, 0.5], "rotation": 180, "texture": "#1"} } }, { - "from": [12, 0, 14], + "from": [12, 4, 15], "to": [12, 12, 16], "rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]}, "faces": { - "north": {"uv": [0, 0, 0, 3], "texture": "#0"}, - "east": {"uv": [1, 10, 1.5, 13], "texture": "#0"}, - "south": {"uv": [0, 0, 0, 3], "texture": "#0"}, - "west": {"uv": [1.5, 10, 1, 13], "texture": "#0"}, - "up": {"uv": [0, 0.5, 0, 0], "rotation": 180, "texture": "#0"}, - "down": {"uv": [0, 0, 0, 0.5], "rotation": 180, "texture": "#0"} + "north": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "east": {"uv": [1, 10, 1.25, 12], "texture": "#1"}, + "south": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "west": {"uv": [1.25, 10, 1, 12], "texture": "#1"}, + "up": {"uv": [0, 0.5, 0, 0], "rotation": 180, "texture": "#1"}, + "down": {"uv": [0, 0, 0, 0.5], "rotation": 180, "texture": "#1"} + } + }, + { + "from": [12, 3, 14], + "to": [12, 4, 15], + "rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 8]}, + "faces": { + "north": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "east": {"uv": [1.25, 12, 1.5, 12.25], "texture": "#1"}, + "south": {"uv": [0, 0, 0, 3], "texture": "#1"}, + "west": {"uv": [1.5, 12, 1.25, 12.25], "texture": "#1"}, + "up": {"uv": [0, 0.5, 0, 0], "rotation": 180, "texture": "#1"}, + "down": {"uv": [0, 0, 0, 0.5], "rotation": 180, "texture": "#1"} } } ], @@ -124,7 +175,24 @@ "origin": [8, 8, 8], "color": 0, "nbt": "{}", - "children": [0, 1, 2, 3, 4, 5] + "children": [ + 0, + 1, + { + "name": "group", + "origin": [8, 8, 8], + "color": 0, + "nbt": "{}", + "children": [2, 3, 4, 5] + }, + { + "name": "group", + "origin": [8, 8, 8], + "color": 0, + "nbt": "{}", + "children": [6, 7, 8, 9] + } + ] } ] } \ No newline at end of file diff --git a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/Registration.java b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/Registration.java index 6b1c08a..9110a0b 100644 --- a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/Registration.java +++ b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/Registration.java @@ -1,8 +1,11 @@ package su.a71.tardim_ic.tardim_ic; import dan200.computercraft.api.ComputerCraftAPI; + import net.fabricmc.fabric.api.item.v1.FabricItemSettings; + import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.ItemStack; @@ -26,6 +29,10 @@ import su.a71.tardim_ic.tardim_ic.registration.CommandInit; import su.a71.tardim_ic.tardim_ic.tardim_dock.TardimDockBlock; import su.a71.tardim_ic.tardim_ic.tardim_dock.TardimDockBlockEntity; +import com.swdteam.tardim.tileentity.TileEntityFuelStorage; +import com.swdteam.tardim.common.block.BlockFuelStorage; + + public class Registration { // Blocks @@ -58,6 +65,10 @@ public class Registration { .icon(() -> new ItemStack(DIGITAL_TARDIM_INTERFACE)) .build(); + // Cloister bell + public static final ResourceLocation CLOISTER_SOUND = new ResourceLocation("tardim_ic:cloister"); + public static SoundEvent CLOISTER_SOUND_EVENT = new SoundEvent(CLOISTER_SOUND); + // Register our stuff public static void register() { @@ -70,6 +81,8 @@ public class Registration { Registry.register(Registry.BLOCK, new ResourceLocation(Constants.MOD_ID, "tardim_dock"), TARDIM_DOCK); Registry.register(Registry.ITEM, new ResourceLocation(Constants.MOD_ID, "tardim_dock"), new BlockItem(TARDIM_DOCK, new FabricItemSettings().tab(TARDIM_IC_TAB))); + Registry.register(Registry.SOUND_EVENT, CLOISTER_SOUND, CLOISTER_SOUND_EVENT); + ComputerCraftAPI.registerPeripheralProvider(new DigitalInterfacePeripheralProvider()); CommandInit.init(); } diff --git a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/command/CommandCloisterBell.java b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/command/CommandCloisterBell.java index bdc60fa..788f8d6 100644 --- a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/command/CommandCloisterBell.java +++ b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/command/CommandCloisterBell.java @@ -4,16 +4,13 @@ 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.resources.ResourceKey; import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.player.Player; - -import com.swdteam.tardim.common.init.TRDDimensions; import net.minecraft.world.level.Level; -import su.a71.tardim_ic.tardim_ic.Registration; -//import static com.swdteam.common.command.tardim.CommandTardimBase.sendResponse; +import su.a71.tardim_ic.tardim_ic.Registration; public class CommandCloisterBell implements ICommand { @Override @@ -34,8 +31,6 @@ public class CommandCloisterBell implements ICommand { 1f ); } - - CommandTardimBase.sendResponse(player, "", CommandTardimBase.ResponseType.COMPLETE, source); } catch (Exception var9) { CommandTardimBase.sendResponse(player, "There was an error", CommandTardimBase.ResponseType.FAIL, source); } @@ -55,7 +50,7 @@ public class CommandCloisterBell implements ICommand { @Override public String getUsage() { - return "cloister-bell"; + return "/cloister-bell"; } @Override diff --git a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/FuelTank.java b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/FuelTank.java new file mode 100644 index 0000000..263794b --- /dev/null +++ b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/FuelTank.java @@ -0,0 +1,34 @@ +package su.a71.tardim_ic.tardim_ic.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.ComparatorBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.entity.ComparatorBlockEntity; +import net.minecraft.world.level.block.state.BlockState; +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 com.swdteam.tardim.tileentity.TileEntityFuelStorage; + +//@Mixin(TileEntityFuelStorage.class) +//public class FuelTank extends BlockEntity, ComparatorBlockEntity { +// +// public ExampleMixin(BlockEntityType blockEntityType, BlockPos blockPos, BlockState blockState) { +// super(blockEntityType, blockPos, blockState); +// } +// +// @Inject(at = @At("HEAD"), method = "init()V") +// private void init(CallbackInfo info) { +// +// Constants.LOG.info("This line is printed by an example mod mixin from Fabric!"); +// Constants.LOG.info("MC Version: {}", Minecraft.getInstance().getVersionType()); +// Constants.LOG.info("Classloader: {}", this.getClass().getClassLoader()); +// } +//} +//public class FuelTank { +//} diff --git a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputBlock.java b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputBlock.java index 4caefbb..05ef6cb 100644 --- a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputBlock.java +++ b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputBlock.java @@ -16,7 +16,6 @@ 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.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -24,21 +23,20 @@ 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.ComparatorBlock; import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.phys.BlockHitResult; import org.jetbrains.annotations.NotNull; import su.a71.tardim_ic.tardim_ic.Registration; +import su.a71.tardim_ic.tardim_ic.utils.FakePlayer; import javax.annotation.Nullable; public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBlock { - private boolean isPowered = false; - private Player lastPlayer = null; public RedstoneInputBlock() { super(FabricBlockSettings.of(Material.METAL).strength(2, 4)); // No occlusion? } @@ -56,10 +54,10 @@ public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBl w.playSound(null, blockPos, TRDSounds.TARDIM_BEEP, SoundSource.BLOCKS, 0.3F, 0.5F); BlockEntity be = w.getBlockEntity(blockPos); - if (be instanceof TileEntityBaseTardimPanel && w.dimension() == TRDDimensions.TARDIS) { + if (be instanceof RedstoneInputTileEntity && w.dimension() == TRDDimensions.TARDIS) { TardimData data = TardimManager.getFromPos(blockPos); if (data != null && data.hasPermission(player)) { - this.lastPlayer = player; + ((RedstoneInputTileEntity) be).lastPlayer = player.getGameProfile().getId(); NetworkHandler.sendTo((ServerPlayer)player, new PacketOpenEditGui(blockPos, 1)); return InteractionResult.CONSUME; } @@ -80,22 +78,26 @@ public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBl 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 RedstoneInputTileEntity)) { + return; + } + // get redstone signal Direction direction = blockState.getValue(FACING); int redstoneSignal = level.getSignal(blockPos, direction); - if (redstoneSignal > 0 && !isPowered) { - isPowered = true; - BlockEntity be = level.getBlockEntity(blockPos); - if (be instanceof TileEntityBaseTardimPanel && level.dimension() == TRDDimensions.TARDIS) { + if (redstoneSignal > 0 && !((RedstoneInputTileEntity) be).isPowered) { + ((RedstoneInputTileEntity) be).isPowered = true; + if (level.dimension() == TRDDimensions.TARDIS) { TardimData data = TardimManager.getFromPos(blockPos); - if (data != null && !level.isClientSide && this.lastPlayer != null) { + if (data != null && !level.isClientSide && ((RedstoneInputTileEntity) be).lastPlayer != null) { if (((TileEntityBaseTardimPanel)be).hasCommand()) { - ((TileEntityBaseTardimPanel)be).execute(this.lastPlayer); + ((TileEntityBaseTardimPanel)be).execute(new FakePlayer(level, blockPos, ((RedstoneInputTileEntity) be).lastPlayer)); } } } - } else if (redstoneSignal == 0 && isPowered) - isPowered = false; + } else if (redstoneSignal == 0 && ((RedstoneInputTileEntity) be).isPowered) + ((RedstoneInputTileEntity) be).isPowered = false; } } diff --git a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputTileEntity.java b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputTileEntity.java index 0d67be3..091bd65 100644 --- a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputTileEntity.java +++ b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputTileEntity.java @@ -3,11 +3,17 @@ package su.a71.tardim_ic.tardim_ic.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; +import java.util.UUID; + public class RedstoneInputTileEntity extends TileEntityBaseTardimPanel { + public boolean isPowered = false; + public UUID lastPlayer = null; + public RedstoneInputTileEntity(BlockPos pos, BlockState state) { super(Registration.REDSTONE_TARDIM_INPUT_TILEENTITY, pos, state); } @@ -15,4 +21,21 @@ public class RedstoneInputTileEntity extends TileEntityBaseTardimPanel { 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"); + } } diff --git a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/DockData.java b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/DockData.java new file mode 100644 index 0000000..f140e20 --- /dev/null +++ b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/DockData.java @@ -0,0 +1,21 @@ +package su.a71.tardim_ic.tardim_ic.tardim_dock; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; + +public class DockData { + public String name; + public BlockPos blockPos; + public Level level; + public boolean active = true; + + public DockData(int id, Level level, BlockPos blockPos) { + this.level = level; + this.blockPos = blockPos; + this.name = DockManager.addDock(this); + } + + public void setActive(boolean setting) { + this.active = setting; + } +} diff --git a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/DockManager.java b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/DockManager.java new file mode 100644 index 0000000..fc6c12f --- /dev/null +++ b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/DockManager.java @@ -0,0 +1,88 @@ +package su.a71.tardim_ic.tardim_ic.tardim_dock; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.swdteam.tardim.main.Config; +import com.swdteam.tardim.main.Tardim; +import com.swdteam.tardim.tardim.TardimData; +import com.swdteam.tardim.tardim.TardimManager; +import com.swdteam.tardim.tardim.TardimSaveHandler; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.level.storage.LevelResource; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.Map; + +public class DockManager { + private static Map DOCK_DATA = new HashMap<>(); + Gson gson = new Gson(); + + + public DockManager() { + } + + public static DockData getDock(String name) { + return DOCK_DATA.get(name); + } + + public static String addDock(DockData dockData) { + String new_id = Integer.toString(DOCK_DATA.size()); + DOCK_DATA.put(new_id, dockData); + return new_id; + } + + public void toggleActive(String name, boolean active) { + DockData dockData = DOCK_DATA.get(name); + dockData.setActive(active); + } + + public void updateDock(String name, DockData dockData) { + DOCK_DATA.put(name, dockData); + } + + public void load(MinecraftServer server) throws Exception { + File file = new File(server.getWorldPath(LevelResource.ROOT) + "/tardim_ic/dock_map.json"); + + // Check if file exists + if (!file.exists()) { + file.getParentFile().mkdirs(); + file.createNewFile(); + FileWriter writer = new FileWriter(file); + writer.write(gson.toJson(new HashMap())); + writer.close(); + return; + } + + Type typeOfDockMap = new TypeToken>() { }.getType(); + + JsonReader reader = new JsonReader(new FileReader(file)); + String json = gson.fromJson(reader, String.class); + DOCK_DATA = gson.fromJson(json, typeOfDockMap); + + System.out.println("Loaded TARDIM: IC docks"); + } + + public void save(MinecraftServer server) throws Exception { + File file = new File(server.getWorldPath(LevelResource.ROOT) + "/tardim_ic/dock_map.json"); + + // Check if file exists + if (!file.exists()) { + file.getParentFile().mkdirs(); + file.createNewFile(); + } + + Gson gson = new Gson(); + String json = gson.toJson(DOCK_DATA); + JsonWriter writer = new JsonWriter(new FileWriter(file)); + writer.jsonValue(json); + writer.close(); + + System.out.println("Saved TARDIM: IC docks"); + } +} diff --git a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/TardimDockBlock.java b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/TardimDockBlock.java index 5c5373b..3168884 100644 --- a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/TardimDockBlock.java +++ b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/TardimDockBlock.java @@ -35,15 +35,9 @@ import su.a71.tardim_ic.tardim_ic.Registration; public class TardimDockBlock extends Block implements EntityBlock { public TardimDockBlock() { - super(FabricBlockSettings.of(Material.METAL).strength(2, 4).noOcclusion()); // No occlusion? + super(FabricBlockSettings.of(Material.METAL).strength(2, 4).noOcclusion()); } -// @Nullable -// @Override -// public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { -// return Registration.REDSTONE_TARDIM_INPUT_TILEENTITY.create(pos, state); -// } - @Override public InteractionResult use(BlockState blockState, Level w, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult p_60508_) { if (!w.isClientSide) { diff --git a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/TardimDockBlockEntity.java b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/TardimDockBlockEntity.java index 24fc141..46d8f90 100644 --- a/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/TardimDockBlockEntity.java +++ b/Fabric/src/main/java/su/a71/tardim_ic/tardim_ic/tardim_dock/TardimDockBlockEntity.java @@ -10,6 +10,7 @@ import su.a71.tardim_ic.tardim_ic.Registration; public class TardimDockBlockEntity extends BlockEntity { public int dock_id; + public DockData data; public TardimDockBlockEntity(BlockPos blockPos, BlockState blockState) { super(Registration.TARDIM_DOCK_BLOCKENTITY, blockPos, blockState); diff --git a/Fabric/src/main/resources/fabric.mod.json b/Fabric/src/main/resources/fabric.mod.json index edd4ec9..c4befe5 100644 --- a/Fabric/src/main/resources/fabric.mod.json +++ b/Fabric/src/main/resources/fabric.mod.json @@ -21,6 +21,9 @@ "su.a71.tardim_ic.tardim_ic.TardimInControl" ] }, + "mixins": [ + "tardim_ic.mixins.json" + ], "depends": { "fabricloader": ">=0.14.10", diff --git a/Fabric/src/main/resources/tardim_ic.mixins.json b/Fabric/src/main/resources/tardim_ic.mixins.json new file mode 100644 index 0000000..22f1e80 --- /dev/null +++ b/Fabric/src/main/resources/tardim_ic.mixins.json @@ -0,0 +1,14 @@ + +"required": true, +"minVersion": "0.8", +"package": "su.a71.tardim_ic.mixin", +"compatibilityLevel": "JAVA_17", +"mixins": [ +], +"client": [ +"FuelTank" +], +"injectors": { +"defaultRequire": 1 +} +} \ No newline at end of file diff --git a/Forge/build.gradle b/Forge/build.gradle index 474d167..35c37d8 100644 --- a/Forge/build.gradle +++ b/Forge/build.gradle @@ -5,12 +5,14 @@ buildscript { } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true + classpath 'org.spongepowered:mixingradle:0.7.+' } } apply plugin: 'java' apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' +apply plugin: 'org.spongepowered.mixin' archivesBaseName = "${mod_name}-forge-${minecraft_version}" @@ -70,6 +72,11 @@ minecraft { } } +mixin { + add sourceSets.main, 'refmap.tardim_ic.json' + config 'mixins.tardim_ic.json' +} + sourceSets.main.resources.srcDir 'src/generated/resources' dependencies { @@ -78,6 +85,8 @@ dependencies { implementation fg.deobf("curse.maven:tardim-531315:4453925") implementation fg.deobf("org.squiddev:cc-tweaked-1.19.1:${cc_version}") + + annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' } tasks.withType(JavaCompile) { diff --git a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/Registration.java b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/Registration.java index 1677e42..2f96cd0 100644 --- a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/Registration.java +++ b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/Registration.java @@ -1,7 +1,9 @@ package su.a71.tardim_ic.tardim_ic; import com.google.common.collect.Sets; -import com.swdteam.common.command.tardim.ICommand; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; @@ -16,8 +18,9 @@ import net.minecraftforge.registries.RegistryObject; import su.a71.tardim_ic.tardim_ic.digital_interface.DigitalInterfaceBlock; import su.a71.tardim_ic.tardim_ic.digital_interface.DigitalInterfaceTileEntity; -import su.a71.tardim_ic.tardim_ic.redsone_input.RedstoneInputBlock; -import su.a71.tardim_ic.tardim_ic.redsone_input.RedstoneInputTileEntity; +import su.a71.tardim_ic.tardim_ic.redstone_input.RedstoneInputBlock; +import su.a71.tardim_ic.tardim_ic.redstone_input.RedstoneInputTileEntity; +import su.a71.tardim_ic.tardim_ic.registration.CommandInit; import java.util.function.Supplier; @@ -26,6 +29,7 @@ public class Registration { public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, TardimInControl.MODID); public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, TardimInControl.MODID); public static final DeferredRegister> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, TardimInControl.MODID); + public static final DeferredRegister SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, TardimInControl.MODID); public static final CreativeModeTab TARDIM_IC_TAB = new CreativeModeTab("tardim_ic") { @Override @@ -47,11 +51,15 @@ public class Registration { public static final RegistryObject> DIGITAL_TARDIM_INTERFACE_TILEENTITY = Registration.BLOCK_ENTITIES.register("digital_tardim_interface", () -> new BlockEntityType<>(DigitalInterfaceTileEntity::new, Sets.newHashSet(DIGITAL_TARDIM_INTERFACE.get()), null)); public static final RegistryObject> REDSTONE_TARDIM_INPUT_TILEENTITY = Registration.BLOCK_ENTITIES.register("redstone_tardim_input", () -> new BlockEntityType<>(RedstoneInputTileEntity::new, Sets.newHashSet(REDSTONE_TARDIM_INPUT.get()), null)); + // Cloister bell + public static final RegistryObject CLOISTER_SOUND = SOUNDS.register("cloister", () -> new SoundEvent(new ResourceLocation(TardimInControl.MODID, "cloister"))); + // Register our stuff public static void register() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); BLOCKS.register(modEventBus); ITEMS.register(modEventBus); BLOCK_ENTITIES.register(modEventBus); + SOUNDS.register(modEventBus); } } \ No newline at end of file diff --git a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/TardimInControl.java b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/TardimInControl.java index 07c89cd..10c6b81 100644 --- a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/TardimInControl.java +++ b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/TardimInControl.java @@ -4,6 +4,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import su.a71.tardim_ic.tardim_ic.registration.CommandInit; +import com.swdteam.tardim.TardimSaveHandler; // The value here should match an entry in the META-INF/mods.toml file @Mod(Constants.MOD_ID) @@ -14,7 +15,6 @@ public class TardimInControl { public TardimInControl() { Registration.register(); - CommandInit.init(); // Register commands // Register ourselves for server and other game events we are interested in. Currently, we do not use any events MinecraftForge.EVENT_BUS.register(this); diff --git a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/command/CommandCloisterBell.java b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/command/CommandCloisterBell.java index 28359ff..7af746f 100644 --- a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/command/CommandCloisterBell.java +++ b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/command/CommandCloisterBell.java @@ -13,9 +13,12 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; 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; //import static com.swdteam.common.command.tardim.CommandTardimBase.sendResponse; + public class CommandCloisterBell implements ICommand { @Override public void execute(String[] args, Player player, BlockPos pos, CommandTardimBase.CommandSource source) { @@ -24,7 +27,17 @@ public class CommandCloisterBell implements ICommand { if (data != null) { if (data.hasPermission(player)) { try { - CommandTardimBase.sendResponse(player, "", CommandTardimBase.ResponseType.COMPLETE, source); + Level lvl = player.getLevel(); + if (!lvl.isClientSide) { + lvl.playSound( + null, + pos, + Registration.CLOISTER_SOUND.get(), + SoundSource.BLOCKS, + 1.5f, + 1f + ); + } } catch (Exception var9) { CommandTardimBase.sendResponse(player, "There was an error", CommandTardimBase.ResponseType.FAIL, source); } @@ -39,12 +52,12 @@ public class CommandCloisterBell implements ICommand { @Override public String getCommandName() { - return "cloisterBell"; + return "cloister-bell"; } @Override public String getUsage() { - return "cloisterBell"; + return "/cloister-bell"; } @Override diff --git a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/Commands.java b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/Commands.java new file mode 100644 index 0000000..e290cd1 --- /dev/null +++ b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/Commands.java @@ -0,0 +1,17 @@ +package su.a71.tardim_ic.tardim_ic.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import com.swdteam.common.init.CommandManager; +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.tardim_ic.registration.CommandInit; + +@Mixin(value = CommandManager.class, remap = false) +public abstract class Commands { + @Inject(method="init()V", at=@At("TAIL")) + private static void init(CallbackInfo ci) { + CommandInit.init(); + System.out.println("TARDIM: IC added commands using mixin"); + } +} diff --git a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/FuelTank.java b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/FuelTank.java new file mode 100644 index 0000000..f4b1190 --- /dev/null +++ b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/mixin/FuelTank.java @@ -0,0 +1,9 @@ +package su.a71.tardim_ic.tardim_ic.mixin; + +import com.swdteam.tileentity.TileEntityFuelStorage; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(TileEntityFuelStorage.class) +public abstract class FuelTank { + +} diff --git a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redsone_input/RedstoneInputTileEntity.java b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redsone_input/RedstoneInputTileEntity.java deleted file mode 100644 index c0af4fc..0000000 --- a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redsone_input/RedstoneInputTileEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -package su.a71.tardim_ic.tardim_ic.redsone_input; - -import com.swdteam.tileentity.TileEntityBaseTardimPanel; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.util.LazyOptional; -import org.jetbrains.annotations.NotNull; - -import com.swdteam.common.init.TRDTiles; - -import su.a71.tardim_ic.tardim_ic.Registration; -import com.swdteam.tileentity.TileEntityTardimScanner; -import com.swdteam.common.block.BlockTardimScanner; - - -public class RedstoneInputTileEntity extends TileEntityBaseTardimPanel { - public RedstoneInputTileEntity(BlockPos pos, BlockState state) { - super(Registration.REDSTONE_TARDIM_INPUT_TILEENTITY.get(), pos, state); - } - - - public BlockPos getPos() { - return this.worldPosition; - } -} diff --git a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redsone_input/RedstoneInputBlock.java b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputBlock.java similarity index 80% rename from Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redsone_input/RedstoneInputBlock.java rename to Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputBlock.java index bdfd4aa..675132b 100644 --- a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redsone_input/RedstoneInputBlock.java +++ b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputBlock.java @@ -1,4 +1,4 @@ -package su.a71.tardim_ic.tardim_ic.redsone_input; +package su.a71.tardim_ic.tardim_ic.redstone_input; import com.swdteam.common.block.BlockBaseTardimPanel; import com.swdteam.common.init.TRDDimensions; @@ -29,16 +29,13 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.common.util.FakePlayerFactory; // TODO: ??? -import net.minecraftforge.server.ServerLifecycleHooks; - import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; import su.a71.tardim_ic.tardim_ic.Registration; +import su.a71.tardim_ic.tardim_ic.utils.FakePlayer; public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBlock { - private boolean isPowered = false; public RedstoneInputBlock() { super(Properties.of(Material.METAL).strength(2, 4).noOcclusion()); } @@ -59,6 +56,7 @@ public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBl if (be instanceof TileEntityBaseTardimPanel && w.dimension() == TRDDimensions.TARDIS) { TardimData data = TardimManager.getFromPos(blockPos); if (data != null && data.hasPermission(player)) { + ((RedstoneInputTileEntity) be).lastPlayer = player.getGameProfile().getId(); NetworkHandler.sendTo((ServerPlayer)player, new PacketOpenEditGui(1, blockPos)); return InteractionResult.CONSUME; } @@ -79,22 +77,26 @@ public class RedstoneInputBlock extends BlockBaseTardimPanel implements EntityBl 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 RedstoneInputTileEntity)) { + return; + } + // get redstone signal Direction direction = blockState.getValue(FACING); int redstoneSignal = level.getSignal(blockPos, direction); - if (redstoneSignal > 0 && !isPowered) { - isPowered = true; - BlockEntity be = level.getBlockEntity(blockPos); - if (be instanceof TileEntityBaseTardimPanel && level.dimension() == TRDDimensions.TARDIS) { + if (redstoneSignal > 0 && !((RedstoneInputTileEntity) be).isPowered) { + ((RedstoneInputTileEntity) be).isPowered = true; + if (level.dimension() == TRDDimensions.TARDIS) { TardimData data = TardimManager.getFromPos(blockPos); - if (data != null) { + if (data != null && !level.isClientSide && ((RedstoneInputTileEntity) be).lastPlayer != null) { if (((TileEntityBaseTardimPanel)be).hasCommand()) { - ((TileEntityBaseTardimPanel)be).execute(FakePlayerFactory.getMinecraft(ServerLifecycleHooks.getCurrentServer().getLevel(level.dimension()))); + ((TileEntityBaseTardimPanel)be).execute(new FakePlayer(level, blockPos, ((RedstoneInputTileEntity) be).lastPlayer)); } } } - } else if (redstoneSignal == 0 && isPowered) - isPowered = false; + } else if (redstoneSignal == 0 && ((RedstoneInputTileEntity) be).isPowered) + ((RedstoneInputTileEntity) be).isPowered = false; } } diff --git a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputTileEntity.java b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputTileEntity.java new file mode 100644 index 0000000..06f4303 --- /dev/null +++ b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/redstone_input/RedstoneInputTileEntity.java @@ -0,0 +1,41 @@ +package su.a71.tardim_ic.tardim_ic.redstone_input; + +import com.swdteam.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; + +import java.util.UUID; + + +public class RedstoneInputTileEntity extends TileEntityBaseTardimPanel { + public boolean isPowered = false; + public UUID lastPlayer = null; + + public RedstoneInputTileEntity(BlockPos pos, BlockState state) { + super(Registration.REDSTONE_TARDIM_INPUT_TILEENTITY.get(), 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"); + } +} \ No newline at end of file diff --git a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/registration/CommandInit.java b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/registration/CommandInit.java index 294a2cb..1b25632 100644 --- a/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/registration/CommandInit.java +++ b/Forge/src/main/java/su/a71/tardim_ic/tardim_ic/registration/CommandInit.java @@ -8,6 +8,6 @@ import com.swdteam.common.init.CommandManager; public class CommandInit { public static void init() { CommandManager.register(new CommandModemTransmit()); - //CommandManager.register(new CommandCloisterBell()); + CommandManager.register(new CommandCloisterBell()); } } diff --git a/Forge/src/main/resources/mixins.tardim_ic.json b/Forge/src/main/resources/mixins.tardim_ic.json new file mode 100644 index 0000000..68e23e1 --- /dev/null +++ b/Forge/src/main/resources/mixins.tardim_ic.json @@ -0,0 +1,15 @@ +{ + "required": true, + "package": "su.a71.tardim_ic.tardim_ic.mixin", + "compatibilityLevel": "JAVA_17", + "refmap": "refmap.tardim_ic.json", + "mixins": [ + "Commands" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + }, + "minVersion": "0.8.4" +} \ No newline at end of file diff --git a/README.md b/README.md index 3bc4e59..9da4025 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,15 @@ # TARDIM: In Control ![Modrinth Downloads](https://img.shields.io/modrinth/dt/tardim-in-control?color=00AF5C&label=modrinth&style=flat&logo=modrinth) ### All of time and space, *now automated*. -This mod is an addon for the [TARDIM mod](https://modrinth.com/mod/tardim), and adds a way to control your time (but mostly space) machine with [ComputerCraft: Tweaked](https://tweaked.cc) computers and redstone using a new blocks and peripherals. +![Example dashboard](https://cdn.modrinth.com/data/xsv4H3pa/images/a6726a966b6ceb6cbfa81d4886b26375ee500854.png) + +This mod is an addon for the [TARDIM mod](https://www.curseforge.com/minecraft/mc-mods/tardim), and adds a way to control your time (but mostly space) machine with [ComputerCraft: Tweaked](https://tweaked.cc) computers and redstone using new blocks and peripherals. ### Features: -* Digital TARDIM interface: ComputerCraft peripheral that lets you control a TARDIM using CC methods! Full list of methods is available in the [Javadoc](http://andrey71.me/TARDIM-ic-docs/su/a71/tardim_ic/tardim_ic/DigitalInterfacePeripheral.html) (Sorry for that, this is the best auto-generated docs I could find for now). The peripheral supports almost all commands that the TARDIM computer panel has. -* Redstone TARDIM Input: New control block that lets you execute a TARDIM command with the power of redstone! After saving a command, this block executes it every time it gets powered by redstone +* Digital TARDIM interface: ComputerCraft peripheral that lets you control a TARDIM using computers! Full list of methods is available in the [Javadoc](http://andrey71.me/TARDIM-ic-docs/su/a71/tardim_ic/tardim_ic/DigitalInterfacePeripheral.html) (Sorry for that, this is the best auto-generated docs I could find for now). The peripheral supports almost all commands that the TARDIM computer panel has. +* Redstone TARDIM Input: New block that lets you execute a TARDIM command with the power of redstone! After saving a command, this block executes it every time it gets powered by redstone * *This is just the beginning, there are more features to come!* -### Note -This is important, due to nature of the mod **anyone** inside your TARDIM with access to a computer and this mod's peripheral -will be able to run **any** methods. There is no fix that I know of (aside from disabling any commands except "getters" like fuel info), so if you want to have this on your server -and do not trust everyone not to steal your blue box, make sure there is some kind of plot claim mod. If there will be demand for it I can try adding a config option to disable all but "harmless" methods.\ -And another thing: the method that sets destination dimension doesn't check if the dimension is valid, if you cannot land just change dimension to a valid one. - ### Example use-cases * Make a dashboard to monitor fuel levels, current location, and other information on a screen in a nice way. * Get refined control over your TARDIM, such as saving and loading locations, or setting a destination in a GUI. @@ -21,17 +17,27 @@ And another thing: the method that sets destination dimension doesn't check if t The possibilities are endless, the only limit is your imagination! (And coding skills) +### Note +Due to nature of the mod **anyone** inside your TARDIM with access to a computer and this mod's peripheral +will be able to run **any** methods. There is no fix that I know of (aside from disabling any commands except "getters" like fuel info), so if you want to use this mod on your server, +please don't let untrustworthy players anywhere near your computer.\ +And another thing: the method that sets destination dimension can't check if the dimension is valid. If you cannot land just change dimension to a valid one like overworld or nether. + ### FAQ **Is this for Fabric or Forge?** -: As a Fabric player who recognises Forge's large playerbase, I intend to support both major modloaders. -Right now, only Forge version is present. However, as of April 13th 2023, I started to port to multi-loader system and intend to have a Fabric version soon. +: Both! As a Fabric player who recognises Forge's large playerbase, I support both major modloaders. **Can I use this in my modpack?** -: Sure, as long as you credit me and link to this page. +: Sure, as long as you don't claim the mod as your own. A link to this mod's page would be appreciated too. **Will there be a 1.19.3 version and beyond?** -: Yes, I will try my best to update to later versions as soon as **both** ComputerCraft: Tweaked and TARDIM receive stable versions for them. +: Right now my focus on 1.19.2, but I will try my best to update to later versions as soon as this mod is fully stable. -**I don't know CC, will this always be a CC-only mod?** -: OK, fine, nobody actually asked that. But in case you did, good news: No! As you might've noticed, version 0.8 add a block that make it possible to integrate your TARDIM into good old redstone! Going forward, I plan to add some way to get redstone *output* from the TARDIM as well, and maybe even streamline things like the cloister bell for those who don't want to code their own implementations! \ No newline at end of file +**I encountered a bug or have a suggestion. What do I do?** +: If you have a problem or suggestion, the best way to get them to me is through the project's Discord server. + +**I don't know ComputerCraft, will this always be a CC-only mod?** +: Ok fine, nobody actually asked that. But in case you did, good news: No! The mod already adds things like Redstone TARDIM Input, +which let you integrate your TARDIM into good old redstone. Going forward, +I plan to add even more ways to control the TARDIM without computers for those who don't want to code their own implementation. \ No newline at end of file