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/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/compat/TFMGEngineControllerWireServerHandler.java b/src/main/java/edn/stratodonut/drivebywire/compat/TFMGEngineControllerWireServerHandler.java new file mode 100644 index 0000000..2ff003d --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/compat/TFMGEngineControllerWireServerHandler.java @@ -0,0 +1,56 @@ +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 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/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..771f1bf --- /dev/null +++ b/src/main/java/edn/stratodonut/drivebywire/mixin/compat/tfmg/MixinTFMGEngineControllerBlockEntity.java @@ -0,0 +1,70 @@ +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 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; + + var pos = self.getBlockPos(); + + boolean steerLeft = self.isPressed(2); + boolean steerRight = self.isPressed(3); + + boolean engineStarted = self.engineStarted; + + boolean shiftReverse = self.shift == TransmissionState.REVERSE; + boolean shiftNeutral = self.shift == TransmissionState.NEUTRAL; + boolean shift1 = self.shift == TransmissionState.SHIFT_1; + boolean shift2 = self.shift == TransmissionState.SHIFT_2; + boolean shift3 = self.shift == TransmissionState.SHIFT_3; + boolean shift4 = self.shift == TransmissionState.SHIFT_4; + boolean shift5 = self.shift == TransmissionState.SHIFT_5; + boolean shift6 = self.shift == TransmissionState.SHIFT_6; + + boolean pedalClutch = self.clutch; + boolean pedalBrake = self.brake; + boolean pedalGas = self.gas; + + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.STEER_LEFT, steerLeft); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.STEER_RIGHT, steerRight); + + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.ENGINE_STARTED, engineStarted); + + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_REVERSE, shiftReverse); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_NEUTRAL, shiftNeutral); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_1, shift1); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_2, shift2); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_3, shift3); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_4, shift4); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_5, shift5); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.SHIFT_6, shift6); + + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.PEDAL_CLUTCH, pedalClutch); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.PEDAL_BRAKE, pedalBrake); + TFMGEngineControllerWireServerHandler.set(level, pos, TFMGEngineControllerWireServerHandler.PEDAL_GAS, pedalGas); + } + + @Inject(method = "remove", at = @At("HEAD"), remap = false) + private void drivebywire$reset(CallbackInfo ci) { + EngineControllerBlockEntity self = (EngineControllerBlockEntity)(Object)this; + Level level = self.getLevel(); + if (level != null && !level.isClientSide) { + 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/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..1ed42f2 100644 --- a/src/main/resources/drivebywire.mixins.json +++ b/src/main/resources/drivebywire.mixins.json @@ -11,7 +11,9 @@ "compat.tweaked.MixinTweakedController", "compat.tweaked.MixinTweakedControllerAxisPacket", "compat.tweaked.MixinTweakedControllerButtonPacket", - "compat.tweaked.MixinTweakedControllerStopLecternPacket" + "compat.tweaked.MixinTweakedControllerStopLecternPacket", + "compat.tfmg.MixinTFMGEngineControllerBlock", + "compat.tfmg.MixinTFMGEngineControllerBlockEntity" ], "client": [ "client.MixinSnqHandler"