Implement PlayerAbilities and PlayerLookTarget provider (#245)

* implemented providers from my last pull requests

* only register providers on the client

* added UserConnection#isClientSide checks
This commit is contained in:
EnZaXD 2023-05-11 14:20:43 +02:00 committed by GitHub
parent 9d77da9912
commit 0c0cfdcfda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 324 additions and 0 deletions

View File

@ -2,6 +2,8 @@ package com.viaversion.fabric.mc114.platform;
import com.viaversion.fabric.mc114.providers.VRHandItemProvider;
import com.viaversion.fabric.mc114.providers.FabricVersionProvider;
import com.viaversion.fabric.mc114.providers.VRPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
@ -24,6 +26,9 @@ public class VFLoader implements ViaPlatformLoader {
}
Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
}
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
Via.getManager().getProviders().use(PlayerLookTargetProvider.class, new VRPlayerLookTargetProvider());
}
}
@Override

View File

@ -0,0 +1,24 @@
package com.viaversion.fabric.mc114.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
public class VRPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}
}

View File

@ -2,6 +2,8 @@ package com.viaversion.fabric.mc115.platform;
import com.viaversion.fabric.mc115.providers.VRHandItemProvider;
import com.viaversion.fabric.mc115.providers.FabricVersionProvider;
import com.viaversion.fabric.mc115.providers.VRPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
@ -24,6 +26,9 @@ public class VFLoader implements ViaPlatformLoader {
}
Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
}
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
Via.getManager().getProviders().use(PlayerLookTargetProvider.class, new VRPlayerLookTargetProvider());
}
}
@Override

View File

@ -0,0 +1,24 @@
package com.viaversion.fabric.mc115.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
public class VRPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}
}

View File

@ -2,6 +2,10 @@ package com.viaversion.fabric.mc116.platform;
import com.viaversion.fabric.mc116.providers.VRHandItemProvider;
import com.viaversion.fabric.mc116.providers.FabricVersionProvider;
import com.viaversion.fabric.mc116.providers.VRPlayerAbilitiesProvider;
import com.viaversion.fabric.mc116.providers.VRPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
@ -24,6 +28,10 @@ public class VFLoader implements ViaPlatformLoader {
}
Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
}
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
Via.getManager().getProviders().use(PlayerAbilitiesProvider.class, new VRPlayerAbilitiesProvider());
Via.getManager().getProviders().use(PlayerLookTargetProvider.class, new VRPlayerLookTargetProvider());
}
}
@Override

View File

@ -0,0 +1,22 @@
package com.viaversion.fabric.mc116.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VRPlayerAbilitiesProvider extends PlayerAbilitiesProvider {
@Override
public float getFlyingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getFlyingSpeed(connection);
return MinecraftClient.getInstance().player.abilities.getFlySpeed();
}
@Override
public float getWalkingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getWalkingSpeed(connection);
return MinecraftClient.getInstance().player.abilities.getWalkSpeed();
}
}

View File

@ -0,0 +1,24 @@
package com.viaversion.fabric.mc116.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
public class VRPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}
}

View File

@ -2,6 +2,10 @@ package com.viaversion.fabric.mc117.platform;
import com.viaversion.fabric.mc117.providers.VRHandItemProvider;
import com.viaversion.fabric.mc117.providers.FabricVersionProvider;
import com.viaversion.fabric.mc117.providers.VRPlayerAbilitiesProvider;
import com.viaversion.fabric.mc117.providers.VRPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
@ -24,6 +28,10 @@ public class VFLoader implements ViaPlatformLoader {
}
Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
}
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
Via.getManager().getProviders().use(PlayerAbilitiesProvider.class, new VRPlayerAbilitiesProvider());
Via.getManager().getProviders().use(PlayerLookTargetProvider.class, new VRPlayerLookTargetProvider());
}
}
@Override

View File

@ -0,0 +1,22 @@
package com.viaversion.fabric.mc117.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VRPlayerAbilitiesProvider extends PlayerAbilitiesProvider {
@Override
public float getFlyingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getFlyingSpeed(connection);
return MinecraftClient.getInstance().player.getAbilities().getFlySpeed();
}
@Override
public float getWalkingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getWalkingSpeed(connection);
return MinecraftClient.getInstance().player.getAbilities().getWalkSpeed();
}
}

View File

@ -0,0 +1,24 @@
package com.viaversion.fabric.mc117.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
public class VRPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}
}

View File

@ -2,6 +2,10 @@ package com.viaversion.fabric.mc118.platform;
import com.viaversion.fabric.mc118.providers.VRHandItemProvider;
import com.viaversion.fabric.mc118.providers.FabricVersionProvider;
import com.viaversion.fabric.mc118.providers.VRPlayerAbilitiesProvider;
import com.viaversion.fabric.mc118.providers.VRPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
@ -24,6 +28,10 @@ public class VFLoader implements ViaPlatformLoader {
}
Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
}
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
Via.getManager().getProviders().use(PlayerAbilitiesProvider.class, new VRPlayerAbilitiesProvider());
Via.getManager().getProviders().use(PlayerLookTargetProvider.class, new VRPlayerLookTargetProvider());
}
}
@Override

View File

@ -0,0 +1,22 @@
package com.viaversion.fabric.mc118.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VRPlayerAbilitiesProvider extends PlayerAbilitiesProvider {
@Override
public float getFlyingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getFlyingSpeed(connection);
return MinecraftClient.getInstance().player.getAbilities().getFlySpeed();
}
@Override
public float getWalkingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getWalkingSpeed(connection);
return MinecraftClient.getInstance().player.getAbilities().getWalkSpeed();
}
}

View File

@ -0,0 +1,24 @@
package com.viaversion.fabric.mc118.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
public class VRPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}
}

View File

@ -2,6 +2,10 @@ package com.viaversion.fabric.mc119.platform;
import com.viaversion.fabric.mc119.providers.VRHandItemProvider;
import com.viaversion.fabric.mc119.providers.FabricVersionProvider;
import com.viaversion.fabric.mc119.providers.VRPlayerAbilitiesProvider;
import com.viaversion.fabric.mc119.providers.VRPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
@ -24,6 +28,10 @@ public class VFLoader implements ViaPlatformLoader {
}
Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
}
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
Via.getManager().getProviders().use(PlayerAbilitiesProvider.class, new VRPlayerAbilitiesProvider());
Via.getManager().getProviders().use(PlayerLookTargetProvider.class, new VRPlayerLookTargetProvider());
}
}
@Override

View File

@ -0,0 +1,22 @@
package com.viaversion.fabric.mc119.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VRPlayerAbilitiesProvider extends PlayerAbilitiesProvider {
@Override
public float getFlyingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getFlyingSpeed(connection);
return MinecraftClient.getInstance().player.getAbilities().getFlySpeed();
}
@Override
public float getWalkingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getWalkingSpeed(connection);
return MinecraftClient.getInstance().player.getAbilities().getWalkSpeed();
}
}

View File

@ -0,0 +1,22 @@
package com.viaversion.fabric.mc119.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
public class VRPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
if (MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult blockHitResult) {
final BlockPos pos = blockHitResult.getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}
}

View File

@ -2,6 +2,10 @@ package com.viaversion.fabric.mc120.platform;
import com.viaversion.fabric.mc120.providers.VRHandItemProvider;
import com.viaversion.fabric.mc120.providers.FabricVersionProvider;
import com.viaversion.fabric.mc120.providers.VRPlayerAbilitiesProvider;
import com.viaversion.fabric.mc120.providers.VRPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
@ -24,6 +28,10 @@ public class VFLoader implements ViaPlatformLoader {
}
Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
}
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
Via.getManager().getProviders().use(PlayerAbilitiesProvider.class, new VRPlayerAbilitiesProvider());
Via.getManager().getProviders().use(PlayerLookTargetProvider.class, new VRPlayerLookTargetProvider());
}
}
@Override

View File

@ -0,0 +1,22 @@
package com.viaversion.fabric.mc120.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VRPlayerAbilitiesProvider extends PlayerAbilitiesProvider {
@Override
public float getFlyingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getFlyingSpeed(connection);
return MinecraftClient.getInstance().player.getAbilities().getFlySpeed();
}
@Override
public float getWalkingSpeed(UserConnection connection) {
if (!connection.isClientSide()) return super.getWalkingSpeed(connection);
return MinecraftClient.getInstance().player.getAbilities().getWalkSpeed();
}
}

View File

@ -0,0 +1,22 @@
package com.viaversion.fabric.mc120.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
public class VRPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
if (MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult blockHitResult) {
final BlockPos pos = blockHitResult.getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}
}