Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/edn/stratodonut/drivebywire/WireBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,5 +41,12 @@ public class WireBlocks {
.simpleItem()
.register();

public static final BlockEntry<TFMGEngineControllerHubBlock> TFMG_ENGINE_CONTROLLER_HUB =
REGISTRATE.block("tfmg_engine_controller_hub", TFMGEngineControllerHubBlock::new)
.initialProperties(SharedProperties::copperMetal)
.transform(axeOrPickaxe())
.simpleItem()
.register();

public static void register() {}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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()));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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())
);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package edn.stratodonut.drivebywire.mixinducks;

public interface TFMGControllerDuck {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "drivebywire:block/hub" }
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/drivebywire/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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!",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "drivebywire:block/hub"
}
4 changes: 3 additions & 1 deletion src/main/resources/drivebywire.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down