diff --git a/build.gradle b/build.gradle index 4a4a104..cf7ae44 100644 --- a/build.gradle +++ b/build.gradle @@ -227,6 +227,8 @@ dependencies { implementation fg.deobf("maven.modrinth:create-tweaked-controllers:1.20.1-1.2.5") + implementation fg.deobf("maven.modrinth:create-tfmg:1.0.2f-forge") + //runtimeOnly fg.deobf("maven.modrinth:eureka:9gbnRz82") runtimeOnly fg.deobf("maven.modrinth:vlib:1.20.1-0.1.0+forge") runtimeOnly fg.deobf("org.valkyrienskies:clockwork-forge:1.20.1-0.4.0-forge-a764c6701b") {transitive = false } diff --git a/src/main/java/edn/stratodonut/drivebywire/WireBlocks.java b/src/main/java/edn/stratodonut/drivebywire/WireBlocks.java index 7d3f227..f4f2e92 100644 --- a/src/main/java/edn/stratodonut/drivebywire/WireBlocks.java +++ b/src/main/java/edn/stratodonut/drivebywire/WireBlocks.java @@ -6,6 +6,7 @@ import com.simibubi.create.foundation.data.SharedProperties; import com.tterrag.registrate.util.entry.BlockEntry; import edn.stratodonut.drivebywire.blocks.ControllerHubBlock; +import edn.stratodonut.drivebywire.blocks.TFMGEngineControllerHubBlock; import edn.stratodonut.drivebywire.blocks.TweakedControllerHubBlock; import edn.stratodonut.drivebywire.blocks.WireNetworkBackupBlock; import net.minecraft.resources.ResourceLocation; @@ -40,5 +41,12 @@ public class WireBlocks { .simpleItem() .register(); + public static final BlockEntry TFMG_ENGINE_CONTROLLER_HUB = + REGISTRATE.block("tfmg_engine_controller_hub", TFMGEngineControllerHubBlock::new) + .initialProperties(SharedProperties::copperMetal) + .transform(axeOrPickaxe()) + .simpleItem() + .register(); + public static void register() {} } diff --git a/src/main/java/edn/stratodonut/drivebywire/WireCreativeTabs.java b/src/main/java/edn/stratodonut/drivebywire/WireCreativeTabs.java index ab0f49d..95de230 100644 --- a/src/main/java/edn/stratodonut/drivebywire/WireCreativeTabs.java +++ b/src/main/java/edn/stratodonut/drivebywire/WireCreativeTabs.java @@ -1,6 +1,7 @@ package edn.stratodonut.drivebywire; import com.tterrag.registrate.util.entry.RegistryEntry; +import edn.stratodonut.drivebywire.blocks.TFMGEngineControllerHubBlock; import edn.stratodonut.drivebywire.blocks.TweakedControllerHubBlock; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; @@ -39,6 +40,9 @@ public static boolean include(Object thing) { if (!ModList.get().isLoaded("create_tweaked_controllers")) { if (thing instanceof TweakedControllerHubBlock) return false; } + if (!ModList.get().isLoaded("tfmg")) { + if (thing instanceof TFMGEngineControllerHubBlock) return false; + } return true; } diff --git a/src/main/java/edn/stratodonut/drivebywire/WirePackets.java b/src/main/java/edn/stratodonut/drivebywire/WirePackets.java index 6e9a2b8..a73aff4 100644 --- a/src/main/java/edn/stratodonut/drivebywire/WirePackets.java +++ b/src/main/java/edn/stratodonut/drivebywire/WirePackets.java @@ -22,7 +22,9 @@ public enum WirePackets { CREATE_CONNECTION(WireAddConnectionPacket.class, WireAddConnectionPacket::new, PLAY_TO_SERVER), REMOVE_CONNECTION(WireRemoveConnectionPacket.class, WireRemoveConnectionPacket::new, PLAY_TO_SERVER), REQUEST_SYNC(WireNetworkRequestSyncPacket.class, WireNetworkRequestSyncPacket::new, PLAY_TO_SERVER), - LINK_NETWORKS(WireLinkNetworksPacket .class, WireLinkNetworksPacket::new, PLAY_TO_SERVER); + LINK_NETWORKS(WireLinkNetworksPacket .class, WireLinkNetworksPacket::new, PLAY_TO_SERVER), + + TFMG_STEERING_INPUT(TFMGSteeringInputPacket.class, TFMGSteeringInputPacket::new, PLAY_TO_SERVER); // DO NOT TOUCH ANYTHING BELOW THIS LINE, THANKS CREATE @@ -47,6 +49,8 @@ public static void registerPackets() { for (WirePackets packet : values()) packet.packetType.register(); + + System.out.println("[DBW] Packets registered"); } public static SimpleChannel getChannel() { diff --git a/src/main/java/edn/stratodonut/drivebywire/blocks/TFMGEngineControllerHubBlock.java b/src/main/java/edn/stratodonut/drivebywire/blocks/TFMGEngineControllerHubBlock.java new file mode 100644 index 0000000..4caf2aa --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/blocks/TFMGEngineControllerHubBlock.java @@ -0,0 +1,92 @@ +package edn.stratodonut.drivebywire.blocks; + +import edn.stratodonut.drivebywire.WireSounds; +import edn.stratodonut.drivebywire.compat.TFMGEngineControllerWireServerHandler; +import edn.stratodonut.drivebywire.mixinducks.TFMGControllerDuck; +import edn.stratodonut.drivebywire.util.HubItem; +import edn.stratodonut.drivebywire.wire.MultiChannelWireSource; +import net.minecraft.core.BlockPos; +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.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class TFMGEngineControllerHubBlock extends Block implements MultiChannelWireSource{ + private static final List channels = List.of( + TFMGEngineControllerWireServerHandler.STEER_LEFT, + TFMGEngineControllerWireServerHandler.STEER_RIGHT, + + TFMGEngineControllerWireServerHandler.ENGINE_STARTED, + + TFMGEngineControllerWireServerHandler.SHIFT_REVERSE, + TFMGEngineControllerWireServerHandler.SHIFT_NEUTRAL, + TFMGEngineControllerWireServerHandler.SHIFT_1, + TFMGEngineControllerWireServerHandler.SHIFT_2, + TFMGEngineControllerWireServerHandler.SHIFT_3, + TFMGEngineControllerWireServerHandler.SHIFT_4, + TFMGEngineControllerWireServerHandler.SHIFT_5, + TFMGEngineControllerWireServerHandler.SHIFT_6, + + TFMGEngineControllerWireServerHandler.PEDAL_CLUTCH, + TFMGEngineControllerWireServerHandler.PEDAL_BRAKE, + TFMGEngineControllerWireServerHandler.PEDAL_GAS + ); + + public TFMGEngineControllerHubBlock(Properties props) { + super(props); + } + + @Override + public @NotNull InteractionResult use( + @NotNull BlockState state, + @NotNull Level level, + @NotNull BlockPos pos, + @NotNull Player player, + @NotNull InteractionHand hand, + @NotNull BlockHitResult hit + ) { + ItemStack stack = player.getItemInHand(hand); + + if (stack.getItem() instanceof TFMGControllerDuck) { + HubItem.putHub(stack, pos); + if (!level.isClientSide) { + level.playSound(null, pos, WireSounds.PLUG_IN.get(), SoundSource.BLOCKS, 1, 1); + player.displayClientMessage( + Component.literal("TFMG Controller connected!"), true + ); + } + return InteractionResult.SUCCESS; + } + + return super.use(state, level, pos, player, hand, hit); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext ctx) { + return ControllerHubBlock.BOTTOM_AABB; + } + + @Override + public List wire$getChannels() { + return channels; + } + + @Override + public @NotNull String wire$nextChannel(String current, boolean forward) { + int idx = channels.indexOf(current); + if (idx == -1) return channels.get(0); + return channels.get(Math.floorMod(idx + (forward ? 1 : -1), channels.size())); + } +} diff --git a/src/main/java/edn/stratodonut/drivebywire/client/TFMGClientControllerTracker.java b/src/main/java/edn/stratodonut/drivebywire/client/TFMGClientControllerTracker.java new file mode 100644 index 0000000..5187dee --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/client/TFMGClientControllerTracker.java @@ -0,0 +1,20 @@ +package edn.stratodonut.drivebywire.client; + +import net.minecraft.core.BlockPos; + +public final class TFMGClientControllerTracker { + + private static BlockPos current; + + public static void set(BlockPos pos) { + current = pos; + } + + public static void clear() { + current = null; + } + + public static BlockPos get() { + return current; + } +} diff --git a/src/main/java/edn/stratodonut/drivebywire/compat/TFMGEngineControllerWireServerHandler.java b/src/main/java/edn/stratodonut/drivebywire/compat/TFMGEngineControllerWireServerHandler.java new file mode 100644 index 0000000..173349c --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/compat/TFMGEngineControllerWireServerHandler.java @@ -0,0 +1,70 @@ +package edn.stratodonut.drivebywire.compat; + +import edn.stratodonut.drivebywire.wire.ShipWireNetworkManager; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; + +public class TFMGEngineControllerWireServerHandler { + + public static final String STEER_LEFT = "tfmg_steer_left"; + public static final String STEER_RIGHT = "tfmg_steer_right"; + + public static final String ENGINE_STARTED = "tfmg_engine_started"; + + public static final String SHIFT_REVERSE = "tfmg_shift_reverse"; + public static final String SHIFT_NEUTRAL = "tfmg_shift_neutral"; + public static final String SHIFT_1 = "tfmg_shift_1"; + public static final String SHIFT_2 = "tfmg_shift_2"; + public static final String SHIFT_3 = "tfmg_shift_3"; + public static final String SHIFT_4 = "tfmg_shift_4"; + public static final String SHIFT_5 = "tfmg_shift_5"; + public static final String SHIFT_6 = "tfmg_shift_6"; + + public static final String PEDAL_CLUTCH = "tfmg_pedal_clutch"; + public static final String PEDAL_BRAKE = "tfmg_pedal_brake"; + public static final String PEDAL_GAS = "tfmg_pedal_gas"; + + public static void set(Level level, BlockPos pos, String channel, boolean active) { + ShipWireNetworkManager.trySetSignalAt( + level, + pos, + channel, + active ? 15 : 0 + ); + } + + public static void setAnalog(Level level, BlockPos pos, String channel, float value) { + // clamp between 0 and 1 + float clamped = Math.max(0f, Math.min(1f, value)); + + int strength = (int)(clamped * 15f); + + ShipWireNetworkManager.trySetSignalAt( + level, + pos, + channel, + strength + ); + } + + public static void reset(Level level, BlockPos pos) { + set(level, pos, STEER_LEFT, false); + set(level, pos, STEER_RIGHT, false); + + set(level, pos, ENGINE_STARTED, false); + + set(level, pos, SHIFT_REVERSE, false); + set(level, pos, SHIFT_NEUTRAL, false); + set(level, pos, SHIFT_1, false); + set(level, pos, SHIFT_2, false); + set(level, pos, SHIFT_3, false); + set(level, pos, SHIFT_4, false); + set(level, pos, SHIFT_5, false); + set(level, pos, SHIFT_6, false); + + set(level, pos, PEDAL_CLUTCH, false); + set(level, pos, PEDAL_BRAKE, false); + set(level, pos, PEDAL_GAS, false); + } + +} diff --git a/src/main/java/edn/stratodonut/drivebywire/compat/TFMGSteeringState.java b/src/main/java/edn/stratodonut/drivebywire/compat/TFMGSteeringState.java new file mode 100644 index 0000000..b122715 --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/compat/TFMGSteeringState.java @@ -0,0 +1,23 @@ +package edn.stratodonut.drivebywire.compat; + +import net.minecraft.core.BlockPos; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class TFMGSteeringState { + + private static final Map STEER = new ConcurrentHashMap<>(); + + public static void set(BlockPos pos, float steer) { + STEER.put(pos, steer); + } + + public static float getSteer(BlockPos pos) { + return STEER.getOrDefault(pos, 0f); + } + + public static void clear(BlockPos pos) { + STEER.remove(pos); + } +} diff --git a/src/main/java/edn/stratodonut/drivebywire/mixin/client/TFMGEngineControllerClientHandlerMixin.java b/src/main/java/edn/stratodonut/drivebywire/mixin/client/TFMGEngineControllerClientHandlerMixin.java new file mode 100644 index 0000000..4c35d25 --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/mixin/client/TFMGEngineControllerClientHandlerMixin.java @@ -0,0 +1,30 @@ +package edn.stratodonut.drivebywire.mixin.client; + +import com.drmangotea.tfmg.content.engines.engine_controller.EngineControllerClientHandler; +import edn.stratodonut.drivebywire.client.TFMGClientControllerTracker; +import net.minecraft.core.BlockPos; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +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; + +@OnlyIn(Dist.CLIENT) +@Mixin(EngineControllerClientHandler.class) +public class TFMGEngineControllerClientHandlerMixin { + + static { + System.out.println("[DBW] TFMG EngineControllerClientHandler mixin loaded"); + } + + @Inject(method = "activateInLectern", at = @At("HEAD"), remap = false) + private static void drivebywire$onActivate(BlockPos pos, CallbackInfo ci) { + TFMGClientControllerTracker.set(pos); + } + + @Inject(method = "deactivateInLectern", at = @At("HEAD"), remap = false) + private static void drivebywire$onDeactivate(CallbackInfo ci) { + TFMGClientControllerTracker.clear(); + } +} diff --git a/src/main/java/edn/stratodonut/drivebywire/mixin/client/TFMGEngineControllerClientSteeringMixin.java b/src/main/java/edn/stratodonut/drivebywire/mixin/client/TFMGEngineControllerClientSteeringMixin.java new file mode 100644 index 0000000..e05e128 --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/mixin/client/TFMGEngineControllerClientSteeringMixin.java @@ -0,0 +1,67 @@ +package edn.stratodonut.drivebywire.mixin.client; + +import com.drmangotea.tfmg.content.engines.engine_controller.EngineControllerBlockEntity; +import edn.stratodonut.drivebywire.WirePackets; +import edn.stratodonut.drivebywire.client.TFMGClientControllerTracker; +import edn.stratodonut.drivebywire.network.TFMGSteeringInputPacket; +import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@OnlyIn(Dist.CLIENT) +@Pseudo +@Mixin(EngineControllerBlockEntity.class) +public abstract class TFMGEngineControllerClientSteeringMixin { + + private float drivebywire$lastSent = 0f; + + @Inject(method = "tick", at = @At("TAIL"), remap = false) + private void drivebywire$captureSteering(CallbackInfo ci) { + EngineControllerBlockEntity self = (EngineControllerBlockEntity)(Object)this; + Level level = self.getLevel(); + + if (level == null || !level.isClientSide) return; + + BlockPos active = TFMGClientControllerTracker.get(); + if (active == null || !active.equals(self.getBlockPos())) return; + + float angle = self.steeringWheelAngle.getValue(); + + final float DEADZONE = 4.0f; + if (Math.abs(angle) < DEADZONE) { + angle = 0f; + } + + final float MAX_STEER = 38f; + float normalized = angle / MAX_STEER; + normalized = Math.max(-1f, Math.min(1f, normalized)); + + float delta = Math.abs(normalized - drivebywire$lastSent); + + if (normalized == 0f && drivebywire$lastSent != 0f) { + drivebywire$lastSent = 0f; + + WirePackets.getChannel().sendToServer( + new TFMGSteeringInputPacket(self.getBlockPos(), 0f) + ); + return; + } + + if (delta < 0.02f) { + return; + } + + drivebywire$lastSent = normalized; + + WirePackets.getChannel().sendToServer( + new TFMGSteeringInputPacket(self.getBlockPos(), normalized) + ); + } +} diff --git a/src/main/java/edn/stratodonut/drivebywire/mixin/compat/tfmg/MixinTFMGEngineControllerBlock.java b/src/main/java/edn/stratodonut/drivebywire/mixin/compat/tfmg/MixinTFMGEngineControllerBlock.java new file mode 100644 index 0000000..2317abb --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/mixin/compat/tfmg/MixinTFMGEngineControllerBlock.java @@ -0,0 +1,50 @@ +package edn.stratodonut.drivebywire.mixin.compat.tfmg; + +import com.drmangotea.tfmg.content.engines.engine_controller.EngineControllerBlock; +import edn.stratodonut.drivebywire.compat.TFMGEngineControllerWireServerHandler; +import edn.stratodonut.drivebywire.wire.MultiChannelWireSource; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Unique; +import javax.annotation.Nonnull; +import java.util.List; + +@Pseudo +@Mixin(EngineControllerBlock.class) +public abstract class MixinTFMGEngineControllerBlock implements MultiChannelWireSource { + + @Unique + private static final List wire$channels = List.of( + TFMGEngineControllerWireServerHandler.STEER_LEFT, + TFMGEngineControllerWireServerHandler.STEER_RIGHT, + + TFMGEngineControllerWireServerHandler.ENGINE_STARTED, + + TFMGEngineControllerWireServerHandler.SHIFT_REVERSE, + TFMGEngineControllerWireServerHandler.SHIFT_NEUTRAL, + TFMGEngineControllerWireServerHandler.SHIFT_1, + TFMGEngineControllerWireServerHandler.SHIFT_2, + TFMGEngineControllerWireServerHandler.SHIFT_3, + TFMGEngineControllerWireServerHandler.SHIFT_4, + TFMGEngineControllerWireServerHandler.SHIFT_5, + TFMGEngineControllerWireServerHandler.SHIFT_6, + + TFMGEngineControllerWireServerHandler.PEDAL_CLUTCH, + TFMGEngineControllerWireServerHandler.PEDAL_BRAKE, + TFMGEngineControllerWireServerHandler.PEDAL_GAS + ); + + @Override + public List wire$getChannels() { + return wire$channels; + } + + @Override + public @Nonnull String wire$nextChannel(String current, boolean forward) { + int i = wire$channels.indexOf(current); + if (i == -1) return wire$channels.get(0); + return wire$channels.get( + Math.floorMod(i + (forward ? 1 : -1), wire$channels.size()) + ); + } +} diff --git a/src/main/java/edn/stratodonut/drivebywire/mixin/compat/tfmg/MixinTFMGEngineControllerBlockEntity.java b/src/main/java/edn/stratodonut/drivebywire/mixin/compat/tfmg/MixinTFMGEngineControllerBlockEntity.java new file mode 100644 index 0000000..3ccfd5d --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/mixin/compat/tfmg/MixinTFMGEngineControllerBlockEntity.java @@ -0,0 +1,60 @@ +package edn.stratodonut.drivebywire.mixin.compat.tfmg; + +import com.drmangotea.tfmg.content.engines.engine_controller.EngineControllerBlockEntity; +import com.drmangotea.tfmg.content.engines.upgrades.TransmissionUpgrade.TransmissionState; +import edn.stratodonut.drivebywire.compat.TFMGEngineControllerWireServerHandler; +import edn.stratodonut.drivebywire.compat.TFMGSteeringState; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Pseudo +@Mixin(EngineControllerBlockEntity.class) +public abstract class MixinTFMGEngineControllerBlockEntity { + + @Inject(method = "tick", at = @At("TAIL"), remap = false) + private void drivebywire$emitSignals(CallbackInfo ci) { + EngineControllerBlockEntity self = (EngineControllerBlockEntity)(Object)this; + Level level = self.getLevel(); + if (level == null || level.isClientSide) return; + + BlockPos pos = self.getBlockPos(); + + float steer = TFMGSteeringState.getSteer(pos); + float leftSteerSignal = steer < 0 ? -steer : 0f; + float rightSteerSignal = steer > 0 ? steer : 0f; + + TFMGEngineControllerWireServerHandler.setAnalog(level, pos, TFMGEngineControllerWireServerHandler.STEER_LEFT, leftSteerSignal); + TFMGEngineControllerWireServerHandler.setAnalog(level, pos, TFMGEngineControllerWireServerHandler.STEER_RIGHT, rightSteerSignal); + + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.ENGINE_STARTED, self.engineStarted); + + TransmissionState s = self.shift; + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_REVERSE, s == TransmissionState.REVERSE); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_NEUTRAL, s == TransmissionState.NEUTRAL); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_1, s == TransmissionState.SHIFT_1); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_2, s == TransmissionState.SHIFT_2); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_3, s == TransmissionState.SHIFT_3); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_4, s == TransmissionState.SHIFT_4); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_5, s == TransmissionState.SHIFT_5); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_6, s == TransmissionState.SHIFT_6); + + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.PEDAL_CLUTCH, self.clutch); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.PEDAL_BRAKE, self.brake); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.PEDAL_GAS, self.gas); + } + + @Inject(method = "remove", at = @At("HEAD"), remap = false) + private void drivebywire$cleanup(CallbackInfo ci) { + EngineControllerBlockEntity self = (EngineControllerBlockEntity)(Object)this; + Level level = self.getLevel(); + if (level != null && !level.isClientSide) { + TFMGSteeringState.clear(self.getBlockPos()); + TFMGEngineControllerWireServerHandler.reset(level, self.getBlockPos()); + } + } +} diff --git a/src/main/java/edn/stratodonut/drivebywire/mixinducks/TFMGControllerDuck.java b/src/main/java/edn/stratodonut/drivebywire/mixinducks/TFMGControllerDuck.java new file mode 100644 index 0000000..3e64adc --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/mixinducks/TFMGControllerDuck.java @@ -0,0 +1,4 @@ +package edn.stratodonut.drivebywire.mixinducks; + +public interface TFMGControllerDuck { +} diff --git a/src/main/java/edn/stratodonut/drivebywire/network/TFMGSteeringInputPacket.java b/src/main/java/edn/stratodonut/drivebywire/network/TFMGSteeringInputPacket.java new file mode 100644 index 0000000..ea0822b --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/network/TFMGSteeringInputPacket.java @@ -0,0 +1,41 @@ +package edn.stratodonut.drivebywire.network; + +import com.simibubi.create.foundation.networking.SimplePacketBase; +import edn.stratodonut.drivebywire.compat.TFMGSteeringState; +import net.minecraft.core.BlockPos; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.network.NetworkEvent; + +public class TFMGSteeringInputPacket extends SimplePacketBase { + + private final BlockPos pos; + float steering; + + public TFMGSteeringInputPacket(BlockPos pos, float steering) { + this.pos = pos; + this.steering = steering; + } + + public TFMGSteeringInputPacket(FriendlyByteBuf buf) { + this.pos = buf.readBlockPos(); + this.steering = buf.readFloat(); + } + + @Override + public void write(FriendlyByteBuf buf) { + buf.writeBlockPos(pos); + buf.writeFloat(steering); + } + + @Override + public boolean handle(NetworkEvent.Context ctx) { + ctx.enqueueWork(() -> { + ServerPlayer player = ctx.getSender(); + if (player == null) return; + + TFMGSteeringState.set(pos, steering); + }); + return true; + } +} \ No newline at end of file diff --git a/src/main/java/edn/stratodonut/drivebywire/server/TFMGSteeringInputCache.java b/src/main/java/edn/stratodonut/drivebywire/server/TFMGSteeringInputCache.java new file mode 100644 index 0000000..512e622 --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/server/TFMGSteeringInputCache.java @@ -0,0 +1,26 @@ +package edn.stratodonut.drivebywire.server; + +import net.minecraft.core.BlockPos; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public final class TFMGSteeringInputCache { + + private static final Map CACHE = new ConcurrentHashMap<>(); + + public static void update(BlockPos pos, boolean left, boolean right) { + CACHE.put(pos, new State(left, right)); + } + + public static State get(BlockPos pos) { + return CACHE.getOrDefault(pos, State.NONE); + } + + public static void clear(BlockPos pos) { + CACHE.remove(pos); + } + + public record State(boolean left, boolean right) { + public static final State NONE = new State(false, false); + } +} diff --git a/src/main/resources/assets/drivebywire/blockstates/tfmg_engine_controller_hub.json b/src/main/resources/assets/drivebywire/blockstates/tfmg_engine_controller_hub.json new file mode 100644 index 0000000..9a99693 --- /dev/null +++ b/src/main/resources/assets/drivebywire/blockstates/tfmg_engine_controller_hub.json @@ -0,0 +1,5 @@ +{ + "variants": { + "": { "model": "drivebywire:block/hub" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/drivebywire/lang/en_us.json b/src/main/resources/assets/drivebywire/lang/en_us.json index b011897..33982ac 100644 --- a/src/main/resources/assets/drivebywire/lang/en_us.json +++ b/src/main/resources/assets/drivebywire/lang/en_us.json @@ -4,6 +4,7 @@ "block.drivebywire.backup_block" : "Network Backup Block", "block.drivebywire.controller_hub" : "Linked Controller Hub", "block.drivebywire.tweaked_controller_hub" : "Tweaked Controller Hub", + "block.drivebywire.tfmg_engine_controller_hub": "TFMG Engine Controller Hub", "item.drivebywire.wire" : "Cable", "item.drivebywire.wire_cutter" : "Cable Cutter", @@ -12,6 +13,7 @@ "block.drivebywire.backup_block.tooltip.summary" : "Saves the ship network when put in a schematic, and loads when shipified", "block.drivebywire.controller_hub.tooltip.summary" : "Bind your controller to this block, and control this network from far away!", "block.drivebywire.tweaked_controller_hub.tooltip.summary" : "Bind your controller to this block, and control this network from far away!", + "block.drivebywire.tfmg_engine_controller_hub.tooltip.summary" : "Bind your controller to this block, and control this network from far away!", "drivebywire.ponder.wires.header" : "Cable networks 101", "drivebywire.ponder.wires.text_1" : "Disclaimer: Cable networks only work on assembled VS2 ships!", diff --git a/src/main/resources/assets/drivebywire/models/item/tfmg_engine_controller_hub.json b/src/main/resources/assets/drivebywire/models/item/tfmg_engine_controller_hub.json new file mode 100644 index 0000000..d2729a9 --- /dev/null +++ b/src/main/resources/assets/drivebywire/models/item/tfmg_engine_controller_hub.json @@ -0,0 +1,3 @@ +{ + "parent": "drivebywire:block/hub" +} \ No newline at end of file diff --git a/src/main/resources/drivebywire.mixins.json b/src/main/resources/drivebywire.mixins.json index 2d27cce..4482ad4 100644 --- a/src/main/resources/drivebywire.mixins.json +++ b/src/main/resources/drivebywire.mixins.json @@ -11,10 +11,14 @@ "compat.tweaked.MixinTweakedController", "compat.tweaked.MixinTweakedControllerAxisPacket", "compat.tweaked.MixinTweakedControllerButtonPacket", - "compat.tweaked.MixinTweakedControllerStopLecternPacket" + "compat.tweaked.MixinTweakedControllerStopLecternPacket", + "compat.tfmg.MixinTFMGEngineControllerBlock", + "compat.tfmg.MixinTFMGEngineControllerBlockEntity" ], "client": [ - "client.MixinSnqHandler" + "client.MixinSnqHandler", + "client.TFMGEngineControllerClientHandlerMixin", + "client.TFMGEngineControllerClientSteeringMixin" ], "injectors": { "defaultRequire": 1