diff --git a/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java index bfcdd3f..1047514 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java +++ b/common/src/main/java/io/github/foundationgames/automobility/block/AutomobilityBlocks.java @@ -2,8 +2,8 @@ import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.block.entity.AutomobileAssemblerBlockEntity; -import io.github.foundationgames.automobility.item.DashPanelItem; import io.github.foundationgames.automobility.item.CreativeTabQueue; +import io.github.foundationgames.automobility.item.DashPanelItem; import io.github.foundationgames.automobility.item.SlopeBlockItem; import io.github.foundationgames.automobility.item.SteepSlopeBlockItem; import io.github.foundationgames.automobility.item.TooltipBlockItem; diff --git a/common/src/main/java/io/github/foundationgames/automobility/controller/AutomobileController.java b/common/src/main/java/io/github/foundationgames/automobility/controller/AutomobileController.java index 5be0933..e52f4ad 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/controller/AutomobileController.java +++ b/common/src/main/java/io/github/foundationgames/automobility/controller/AutomobileController.java @@ -9,7 +9,15 @@ public interface AutomobileController { default void crashRumble() {} - default void updateDriftRumbleState(boolean drifting) {}; + default void groundThudRumble() {} + + default void driftChargeRumble() {} + + default void updateMaxChargeRumbleState(boolean maxCharge) {} + + default void updateBoostingRumbleState(boolean boosting, float boostPower) {} + + default void updateOffRoadRumbleState(boolean inOffRoad) {} boolean inControllerMode(); diff --git a/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java index 346f54a..dcc1cd4 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/AutomobileEntity.java @@ -15,6 +15,7 @@ import io.github.foundationgames.automobility.block.AutomobileAssemblerBlock; import io.github.foundationgames.automobility.block.LaunchGelBlock; import io.github.foundationgames.automobility.block.OffRoadBlock; +import io.github.foundationgames.automobility.controller.AutomobileController; import io.github.foundationgames.automobility.item.AutomobileInteractable; import io.github.foundationgames.automobility.item.AutomobilityItems; import io.github.foundationgames.automobility.particle.AutomobilityParticles; @@ -25,6 +26,7 @@ import io.github.foundationgames.automobility.util.duck.CollisionArea; import io.github.foundationgames.automobility.util.network.ClientPackets; import io.github.foundationgames.automobility.util.network.CommonPackets; +import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; import net.minecraft.core.Cursor3D; @@ -316,6 +318,14 @@ public void recreateFromPacket(ClientboundAddEntityPacket packet) { } } + private void controllerAction(Consumer action) { + if (this.level().isClientSide()) { + if (this.getControllingPassenger() == Minecraft.getInstance().player) { + action.accept(Platform.get().controller()); + } + } + } + @Override public AutomobileFrame getFrame() { return frame; @@ -420,10 +430,6 @@ private void setDrifting(boolean drifting) { if (!this.drifting && drifting) { skidSound.accept(this); } - - if (this.drifting != drifting) { - Platform.get().controller().updateDriftRumbleState(drifting); - } } this.drifting = drifting; @@ -434,6 +440,10 @@ private void setBurningOut(boolean burningOut) { skidSound.accept(this); } + if (this.burningOut != burningOut || (this.turboCharge >= LARGE_TURBO_TIME) != burningOut) { + controllerAction(c -> c.updateMaxChargeRumbleState(burningOut)); + } + this.burningOut = burningOut; } @@ -736,6 +746,10 @@ public void movementTick() { engineSpeed += 0.012f; } markDirty(); + + if (boostTimer == 0) { + controllerAction(c -> c.updateBoostingRumbleState(false, 0)); + } } else { boostSpeed = AUtils.zero(boostSpeed, 0.09f); } @@ -810,15 +824,21 @@ public void movementTick() { slopeStickingTimer = Math.max(0, slopeStickingTimer--); } + boolean wasOffRoad = this.offRoad && this.hSpeed > 0.01; + // Handle being in off-road - if (boostSpeed < 0.4f && level().getBlockState(blockPosition()).getBlock() instanceof OffRoadBlock offRoad) { + if (boostSpeed < 0.4f && level().getBlockState(blockPosition()).getBlock() instanceof OffRoadBlock block) { int layers = level().getBlockState(blockPosition()).getValue(OffRoadBlock.LAYERS); float cap = stats.getComfortableSpeed() * (1 - ((float)layers / 3.5f)); engineSpeed = Math.min(cap, engineSpeed); - this.debrisColor = offRoad.color; + this.debrisColor = block.color; this.offRoad = true; } else this.offRoad = false; + if ((this.offRoad && this.hSpeed > 0.01) != wasOffRoad) { + controllerAction(c -> c.updateOffRoadRumbleState(this.offRoad)); + } + // Set the horizontal speed if (!burningOut()) hSpeed = engineSpeed + boostSpeed; @@ -904,7 +924,7 @@ public void postMovementTick() { if (isVehicle() && level().isClientSide()) { if (getPassengers().stream().anyMatch(p -> p instanceof LocalPlayer)) { - Platform.get().controller().crashRumble(); + controllerAction(c -> c.crashRumble()); } } @@ -1124,6 +1144,8 @@ public void boost(float power, int time) { if (this.isControlledByLocalInstance()) { this.engineSpeed = Math.max(this.engineSpeed, this.stats.getComfortableSpeed() * 0.5f); } + + controllerAction(c -> c.updateBoostingRumbleState(true, power)); } private void steeringTick() { @@ -1152,10 +1174,13 @@ private void consumeTurboCharge() { } private void driftingTick() { + int prevTurboCharge = turboCharge; + // Handles starting a drift if (!prevHoldDrift && holdingDrift) { if (steering != 0 && !drifting && hSpeed > 0.4f && automobileOnGround) { setDrifting(true); + controllerAction(AutomobileController::driftChargeRumble); driftDir = steering > 0 ? 1 : -1; // Reduce speed when a drift starts, based on how long the last drift was for // This allows you to do a series of short drifts without tanking all your speed, while still reducing your speed when you begin the drift(s) @@ -1171,15 +1196,27 @@ private void driftingTick() { // Ending a drift successfully, giving you a turbo boost if (prevHoldDrift && !holdingDrift) { setDrifting(false); + controllerAction(c -> c.updateMaxChargeRumbleState(false)); consumeTurboCharge(); // Ending a drift unsuccessfully, not giving you a boost } else if (hSpeed < 0.33f) { setDrifting(false); + controllerAction(c -> c.updateMaxChargeRumbleState(false)); turboCharge = 0; } if (automobileOnGround) turboCharge += ((steeringLeft && driftDir < 0) || (steeringRight && driftDir > 0)) ? 2 : 1; } + if (turboCharge == SMALL_TURBO_TIME || turboCharge == MEDIUM_TURBO_TIME || turboCharge == LARGE_TURBO_TIME) { + controllerAction(AutomobileController::driftChargeRumble); + } + + if (turboCharge >= LARGE_TURBO_TIME && prevTurboCharge < LARGE_TURBO_TIME) { + controllerAction(c -> c.updateMaxChargeRumbleState(true)); + } else if (prevTurboCharge >= LARGE_TURBO_TIME && turboCharge < LARGE_TURBO_TIME) { + controllerAction(c -> c.updateMaxChargeRumbleState(false)); + } + this.prevHoldDrift = this.holdingDrift; } @@ -1472,6 +1509,7 @@ public float getTrackedFrontAttachmentAnimation() { public void bounce() { suspensionBounceTimer = 3; level().playLocalSound(this.getX(), this.getY(), this.getZ(), AutomobilitySounds.LANDING.require(), SoundSource.AMBIENT, 1, 1.5f + (0.15f * (this.level().random.nextFloat() - 0.5f)), true); + controllerAction(AutomobileController::groundThudRumble); } public static final class Displacement { diff --git a/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java b/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java index 801c776..db42af9 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java +++ b/common/src/main/java/io/github/foundationgames/automobility/entity/render/AutomobileEntityRenderer.java @@ -3,12 +3,12 @@ import com.mojang.blaze3d.vertex.PoseStack; import io.github.foundationgames.automobility.automobile.render.AutomobileRenderer; import io.github.foundationgames.automobility.entity.AutomobileEntity; -import org.joml.Quaternionf; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; +import org.joml.Quaternionf; public class AutomobileEntityRenderer extends EntityRenderer { public AutomobileEntityRenderer(EntityRendererProvider.Context ctx) { diff --git a/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java b/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java index 13a83cd..2828887 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java +++ b/common/src/main/java/io/github/foundationgames/automobility/item/DashPanelItem.java @@ -1,8 +1,6 @@ package io.github.foundationgames.automobility.item; import io.github.foundationgames.automobility.block.AutomobilityBlocks; -import io.github.foundationgames.automobility.block.SlopeBlock; -import io.github.foundationgames.automobility.block.SteepSlopeBlock; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; diff --git a/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java index 2676ca5..1b40662 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java +++ b/common/src/main/java/io/github/foundationgames/automobility/recipe/AutoMechanicTableRecipe.java @@ -1,7 +1,6 @@ package io.github.foundationgames.automobility.recipe; import io.github.foundationgames.automobility.Automobility; - import net.minecraft.core.RegistryAccess; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.Container; diff --git a/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java b/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java index f1c7a3d..7cf7446 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java +++ b/common/src/main/java/io/github/foundationgames/automobility/screen/SingleSlotScreen.java @@ -1,13 +1,10 @@ package io.github.foundationgames.automobility.screen; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; import io.github.foundationgames.automobility.Automobility; - import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.MenuAccess; -import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; diff --git a/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java b/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java index f15bafc..f980e6e 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java +++ b/common/src/main/java/io/github/foundationgames/automobility/sound/AutomobilitySounds.java @@ -3,7 +3,6 @@ import io.github.foundationgames.automobility.Automobility; import io.github.foundationgames.automobility.util.Eventual; import io.github.foundationgames.automobility.util.RegistryQueue; -import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.sounds.SoundEvent; diff --git a/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java b/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java index eb655fa..01f5910 100644 --- a/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java +++ b/common/src/main/java/io/github/foundationgames/automobility/util/AUtils.java @@ -8,8 +8,6 @@ import io.github.foundationgames.automobility.automobile.AutomobilePrefab; import io.github.foundationgames.automobility.automobile.AutomobileWheel; import io.github.foundationgames.automobility.item.AutomobilityItems; -import org.joml.Vector3f; - import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; @@ -18,6 +16,7 @@ import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.Vec3; +import org.joml.Vector3f; import java.text.DecimalFormat; diff --git a/fabric/build.gradle b/fabric/build.gradle index db79024..7ab4dd7 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -41,7 +41,7 @@ dependencies { } // Controlify Support - modImplementation "dev.isxander:controlify:${project.controlify_version}" + modCompileOnly "dev.isxander:controlify:${project.controlify_version}" // Json entity models modImplementation "maven.modrinth:jsonem:${project.jsonem_version}" diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityClientFabric.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityClientFabric.java index 7391c50..d526b06 100644 --- a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityClientFabric.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/AutomobilityClientFabric.java @@ -8,9 +8,11 @@ import io.github.foundationgames.automobility.fabric.block.render.FabricSlopeBakedModel; import io.github.foundationgames.automobility.particle.AutomobilityParticles; import io.github.foundationgames.automobility.particle.DriftSmokeParticle; +import io.github.foundationgames.automobility.platform.Platform; import io.github.foundationgames.automobility.screen.AutomobileHud; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; @@ -19,6 +21,8 @@ import net.minecraft.client.renderer.RenderType; public class AutomobilityClientFabric implements ClientModInitializer { + private static boolean wasRidingAutomobile = false; + @Override public void onInitializeClient() { FabricPlatform.init(); @@ -41,6 +45,21 @@ public void onInitializeClient() { ModelLoadingRegistry.INSTANCE.registerResourceProvider(manager -> (location, context) -> SlopeUnbakedModel.DEFAULT_MODELS.containsKey(location) ? SlopeUnbakedModel.DEFAULT_MODELS.get(location).get() : null); + ClientTickEvents.START_WORLD_TICK.register(world -> { + boolean isRidingAutomobile = Minecraft.getInstance().player != null && + Minecraft.getInstance().player.getVehicle() instanceof AutomobileEntity; + + if (wasRidingAutomobile && !isRidingAutomobile) { + var con = Platform.get().controller(); + + con.updateMaxChargeRumbleState(false); + con.updateOffRoadRumbleState(false); + con.updateBoostingRumbleState(false, 0); + } + + wasRidingAutomobile = isRidingAutomobile; + }); + BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.LAUNCH_GEL.require(), RenderType.translucent()); BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.AUTOMOBILE_ASSEMBLER.require(), RenderType.cutout()); BlockRenderLayerMap.INSTANCE.putBlock(AutomobilityBlocks.SLOPE.require(), RenderType.translucent()); diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/FabricPlatform.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/FabricPlatform.java index d31c0a3..b1cbfe6 100644 --- a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/FabricPlatform.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/FabricPlatform.java @@ -14,11 +14,11 @@ import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; +import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes; -import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.Minecraft; import net.minecraft.client.color.block.BlockColor; diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/controlify/ControlifyCompat.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/controlify/ControlifyCompat.java index f4f11b2..d320801 100644 --- a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/controlify/ControlifyCompat.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/controlify/ControlifyCompat.java @@ -1,6 +1,7 @@ package io.github.foundationgames.automobility.fabric.controller.controlify; import dev.isxander.controlify.api.ControlifyApi; +import dev.isxander.controlify.api.bind.BindingSupplier; import dev.isxander.controlify.api.bind.ControlifyBindingsApi; import dev.isxander.controlify.api.entrypoint.ControlifyEntrypoint; import dev.isxander.controlify.api.event.ControlifyEvents; @@ -12,10 +13,13 @@ import io.github.foundationgames.automobility.entity.AutomobileEntity; import net.minecraft.network.chat.Component; +import java.util.HashSet; import java.util.Optional; import java.util.Set; public class ControlifyCompat implements ControlifyEntrypoint { + public static final Set AUTOMOBILITY_BINDINGS = new HashSet<>(); + @Override public void onControlifyPreInit(ControlifyApi controlify) { BindContext drivingCtx = new BindContext(Automobility.rl("driving"), Set.of()); @@ -34,6 +38,11 @@ public void onControlifyPreInit(ControlifyApi controlify) { .context(drivingCtx) .category(category)); + AUTOMOBILITY_BINDINGS.clear(); + AUTOMOBILITY_BINDINGS.add(ControlifyController.accelerateBinding); + AUTOMOBILITY_BINDINGS.add(ControlifyController.brakeBinding); + AUTOMOBILITY_BINDINGS.add(ControlifyController.driftBinding); + ControlifyEvents.INGAME_GUIDE_REGISTRY.register((bindings, registry) -> { var accelerate = bindings.get(Automobility.rl("accelerate_automobile")); var brake = bindings.get(Automobility.rl("brake_automobile")); diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/controlify/ControlifyController.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/controlify/ControlifyController.java index 40b5d77..8905992 100644 --- a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/controlify/ControlifyController.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/controlify/ControlifyController.java @@ -11,7 +11,7 @@ public class ControlifyController implements AutomobileController { static BindingSupplier accelerateBinding, brakeBinding, driftBinding; - private ContinuousRumbleEffect driftRumbleEffect = null; + private ContinuousRumbleEffect maxChargeRumble = null, boostingRumble = null, offRoadRumble = null; @Override public boolean accelerating() { @@ -46,26 +46,81 @@ public void crashRumble() { controller.rumbleManager().play( RumbleSource.DAMAGE, BasicRumbleEffect.byTime( - t -> new RumbleState(t < 0.5 ? 1 : 0, 1 - t), - 20 + t -> new RumbleState(t < 0.25 ? 1 : 0, (1 - t) * 0.7f), + 5 ) ); }); } @Override - public void updateDriftRumbleState(boolean drifting) { - if (drifting) { - if (driftRumbleEffect != null && !driftRumbleEffect.isFinished()) + public void groundThudRumble() { + ControlifyApi.get().getCurrentController().ifPresent(controller -> { + controller.rumbleManager().play( + RumbleSource.DAMAGE, + BasicRumbleEffect.constant(0.1f, 0.3f, 3) + ); + }); + } + + @Override + public void driftChargeRumble() { + ControlifyApi.get().getCurrentController().ifPresent(controller -> { + controller.rumbleManager().play( + RumbleSource.DAMAGE, + BasicRumbleEffect.byTime( + t -> new RumbleState(t < 0.15 ? 0.4f : 0, (1 - t) * 0.2f), + 6 + ) + ); + }); + } + + @Override + public void updateMaxChargeRumbleState(boolean maxCharge) { + if (maxCharge) { + if (maxChargeRumble != null && !maxChargeRumble.isFinished()) + return; + + maxChargeRumble = ContinuousRumbleEffect.builder() + .constant(0f, 0.05f) + .build(); + ControlifyApi.get().getCurrentController().ifPresent(controller -> + controller.rumbleManager().play(RumbleSource.MASTER, maxChargeRumble)); + } else if (maxChargeRumble != null) { + maxChargeRumble.stop(); + } + } + + @Override + public void updateBoostingRumbleState(boolean boosting, float boostPower) { + if (boosting) { + if (boostingRumble != null && !boostingRumble.isFinished()) + return; + + boostingRumble = ContinuousRumbleEffect.builder() + .constant(0.1f * boostPower, 0.5f * boostPower) + .build(); + ControlifyApi.get().getCurrentController().ifPresent(controller -> + controller.rumbleManager().play(RumbleSource.MASTER, boostingRumble)); + } else if (boostingRumble != null) { + boostingRumble.stop(); + } + } + + @Override + public void updateOffRoadRumbleState(boolean inOffRoad) { + if (inOffRoad) { + if (offRoadRumble != null && !offRoadRumble.isFinished()) return; - driftRumbleEffect = ContinuousRumbleEffect.builder() - .constant(0f, 0.8f) + offRoadRumble = ContinuousRumbleEffect.builder() + .constant(0.04f, 0.02f) .build(); ControlifyApi.get().getCurrentController().ifPresent(controller -> - controller.rumbleManager().play(RumbleSource.MASTER, driftRumbleEffect)); - } else if (driftRumbleEffect != null) { - driftRumbleEffect.stop(); + controller.rumbleManager().play(RumbleSource.MASTER, offRoadRumble)); + } else if (offRoadRumble != null) { + offRoadRumble.stop(); } } } diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/midnightcontrols/MidnightController.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/midnightcontrols/MidnightController.java index ded8420..1c01a07 100644 --- a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/midnightcontrols/MidnightController.java +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/controller/midnightcontrols/MidnightController.java @@ -9,8 +9,8 @@ import eu.midnightdust.midnightcontrols.client.controller.ButtonCategory; import eu.midnightdust.midnightcontrols.client.controller.InputManager; import io.github.foundationgames.automobility.Automobility; -import io.github.foundationgames.automobility.entity.AutomobileEntity; import io.github.foundationgames.automobility.controller.AutomobileController; +import io.github.foundationgames.automobility.entity.AutomobileEntity; import net.minecraft.client.Minecraft; import org.aperlambda.lambdacommon.Identifier; import org.aperlambda.lambdacommon.utils.function.PairPredicate; @@ -20,9 +20,7 @@ import java.util.Set; import java.util.function.Supplier; -import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER; -import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_BUTTON_A; -import static org.lwjgl.glfw.GLFW.GLFW_GAMEPAD_BUTTON_B; +import static org.lwjgl.glfw.GLFW.*; public class MidnightController implements CompatHandler, AutomobileController { public final PairPredicate ON_AUTOMOBILE = (client, button) -> client.player != null && client.player.getVehicle() instanceof AutomobileEntity; diff --git a/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/controlify/ControllerBindingImplMixin.java b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/controlify/ControllerBindingImplMixin.java new file mode 100644 index 0000000..bd68fa5 --- /dev/null +++ b/fabric/src/main/java/io/github/foundationgames/automobility/fabric/mixin/controlify/ControllerBindingImplMixin.java @@ -0,0 +1,44 @@ +package io.github.foundationgames.automobility.fabric.mixin.controlify; + +import dev.isxander.controlify.api.bind.ControllerBinding; +import dev.isxander.controlify.bindings.ControllerBindingImpl; +import dev.isxander.controlify.bindings.IBind; +import dev.isxander.controlify.controller.Controller; +import dev.isxander.controlify.controller.ControllerState; +import io.github.foundationgames.automobility.entity.AutomobileEntity; +import io.github.foundationgames.automobility.fabric.controller.controlify.ControlifyCompat; +import net.minecraft.client.Minecraft; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Pseudo +@Mixin(value = ControllerBindingImpl.class, remap = false) +public abstract class ControllerBindingImplMixin implements ControllerBinding { + @Shadow @Final private Controller controller; + + @Shadow public abstract IBind getBind(); + + @Inject(method = "held", at = @At("HEAD"), cancellable = true) + private void automobility$makeAutomobileInputsWork(CallbackInfoReturnable cir) { + var player = Minecraft.getInstance().player; + if (player != null && player.getVehicle() instanceof AutomobileEntity) { + var controller = this.controller; + for (var supplier : ControlifyCompat.AUTOMOBILITY_BINDINGS) { + var binding = supplier.onController(controller); + if (binding != this && binding.getBind().equals(this.getBind())) { + cir.setReturnValue(false); + } + } + } + } + + @Inject(method = "prevHeld", at = @At("HEAD"), cancellable = true) + private void automobility$makeAutomobileInputsHaveWorked(CallbackInfoReturnable cir) { + this.automobility$makeAutomobileInputsWork(cir); + } +} diff --git a/fabric/src/main/resources/automobility_fabric.mixins.json b/fabric/src/main/resources/automobility_fabric.mixins.json index aa9701c..2fe3d03 100644 --- a/fabric/src/main/resources/automobility_fabric.mixins.json +++ b/fabric/src/main/resources/automobility_fabric.mixins.json @@ -8,6 +8,7 @@ ], "client": [ "GameRendererMixin", + "controlify.ControllerBindingImplMixin", "midnightcontrols.InputHandlersMixin" ], "injectors": { diff --git a/gradle.properties b/gradle.properties index 30cfe2d..c3b3aa3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,8 +11,8 @@ midnightcontrols_version=1.8.2+1.20 midnightlib_version=1.4.1 spruceui_version=5.0.0+1.20 jsonem_version=0.2.1+1.20 -controlify_version=1.4.6+1.20 +controlify_version=1.5.1+1.20 -mod_version = 0.4.2 +mod_version = 0.4.2.a maven_group = io.github.foundationgames archives_base_name = automobility