Skip to content

Commit

Permalink
feat(ViaVersion): 1.8 block place helper function (#5219)
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 authored Jan 7, 2025
1 parent dc34c51 commit 7c98e3a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 3 additions & 2 deletions config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
<ID>CognitiveComplexMethod:ModuleKillAura.kt$ModuleKillAura$private suspend fun Sequence&lt;*>.mightAttack(chosenEntity: Entity, rotation: Rotation)</ID>
<ID>CognitiveComplexMethod:PlacementRenderHandler.kt$PlacementRenderHandler$fun render(event: WorldRenderEvent, time: Long)</ID>
<ID>CognitiveComplexMethod:RegistryFunctions.kt$@Suppress("UNUSED_PARAMETER") fun getRegistries(requestObject: RequestObject)</ID>
<ID>CognitiveComplexMethod:ScaffoldGodBridgeTechnique.kt$ScaffoldGodBridgeTechnique$override fun ledge( ledge: Boolean, ledgeSoon: Boolean, target: BlockPlacementTarget?, rotation: Rotation ): LedgeState</ID>
<ID>CognitiveComplexMethod:SimulatedArrow.kt$SimulatedArrow$private fun updateCollision(pos: Vec3d, newPos: Vec3d): HitResult?</ID>
<ID>FunctionNaming:ProtocolUtil.kt$fun send1_8BlockPlacement(blockPos: BlockPos, face: Int, heldItem: ItemStack, facingXIn: Float, facingYIn: Float, facingZIn: Float)</ID>
<ID>FunctionNaming:ProtocolUtil.kt$fun send1_8SignUpdate(blockPos: BlockPos, lines: Array&lt;String>)</ID>
<ID>LongMethod:CommandClientIntegrationSubcommand.kt$CommandClientIntegrationSubcommand$private fun menuSubcommand()</ID>
<ID>LongMethod:CommandManager.kt$CommandManager$@ScriptApiRequired @JvmName("execute") fun execute(cmd: String)</ID>
<ID>LongParameterList:ProtocolUtil.kt$(blockPos: BlockPos, face: Int, heldItem: ItemStack, facingXIn: Float, facingYIn: Float, facingZIn: Float)</ID>
<ID>LoopWithTooManyJumpStatements:BlockPlacer.kt$BlockPlacer$while</ID>
<ID>LoopWithTooManyJumpStatements:ModuleKillAura.kt$ModuleKillAura$for</ID>
<ID>LoopWithTooManyJumpStatements:ModuleProjectilePuncher.kt$ModuleProjectilePuncher$for</ID>
<ID>LoopWithTooManyJumpStatements:TargetFinding.kt$for</ID>
<ID>NestedBlockDepth:AStarMode.kt$AStarMode$private fun findPath(start: Vec3i, end: Vec3i, maxCost: Int, maxIterations: Int = 500): List&lt;Vec3i></ID>
<ID>NestedBlockDepth:CombatExtensions.kt$fun Entity.attack(swing: Boolean, keepSprint: Boolean = false)</ID>
<ID>NestedBlockDepth:CommandManager.kt$CommandManager$fun autoComplete(origCmd: String, start: Int): CompletableFuture&lt;Suggestions></ID>
<ID>NestedBlockDepth:ScaffoldGodBridgeTechnique.kt$ScaffoldGodBridgeTechnique$override fun ledge( ledge: Boolean, ledgeSoon: Boolean, target: BlockPlacementTarget?, rotation: Rotation ): LedgeState</ID>
<ID>ThrowsCount:CommandManager.kt$CommandManager$@ScriptApiRequired @JvmName("execute") fun execute(cmd: String)</ID>
<ID>UnusedPrivateMember:HumanInputDeserializer.kt$HumanInputDeserializer$private fun fail(s: String): Boolean</ID>
</CurrentIssues>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_8;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;

import java.util.function.Consumer;
Expand Down Expand Up @@ -55,6 +57,18 @@ public void sendSignUpdate(final BlockPos blockPos, final String[] lines) throws
});
}

public void sendBlockPlacement(BlockPos blockPos, int face, ItemStack item,
float facingXIn, float facingYIn, float facingZIn) {
writePacket(ServerboundPackets1_8.USE_ITEM_ON, packet -> {
packet.write(Types.BLOCK_POSITION1_8, new BlockPosition(blockPos.getX(), blockPos.getY(), blockPos.getZ()));
packet.write(Types.UNSIGNED_BYTE, (short) face);
packet.write(Types.ITEM1_8, ViaFabricPlus.getImpl().translateItem(item, ProtocolVersion.v1_8));
packet.write(Types.FLOAT, facingXIn);
packet.write(Types.FLOAT, facingYIn);
packet.write(Types.FLOAT, facingZIn);
});
}

private void writePacket(ServerboundPacketType packetType, Consumer<PacketWrapper> writer) {
if (!VfpCompatibility.INSTANCE.isEqual1_8()) {
throw new IllegalStateException("Not on 1.8 protocol");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object TranslationSignExploit : Choice("TranslationSign") {
}

runCatching {
sendSignUpdate(original.pos, arrayOf(
send1_8SignUpdate(original.pos, arrayOf(
TEXT,
TEXT,
TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.viaversion.viafabricplus.ViaFabricPlus
import net.ccbluex.liquidbounce.utils.client.vfp.VfpCompatibility
import net.ccbluex.liquidbounce.utils.client.vfp.VfpCompatibility1_8
import net.minecraft.SharedConstants
import net.minecraft.item.ItemStack
import net.minecraft.util.math.BlockPos

// Only runs once
Expand Down Expand Up @@ -125,9 +126,17 @@ fun openVfpProtocolSelection() {
VfpCompatibility.INSTANCE.unsafeOpenVfpProtocolSelection()
}

fun sendSignUpdate(blockPos: BlockPos, lines: Array<String>) {
fun send1_8SignUpdate(blockPos: BlockPos, lines: Array<String>) {
require(usesViaFabricPlus) { "ViaFabricPlus is missing" }
require(isEqual1_8) { "Not 1.8 protocol" }

VfpCompatibility1_8.INSTANCE.sendSignUpdate(blockPos, lines)
}

fun send1_8BlockPlacement(blockPos: BlockPos, face: Int, heldItem: ItemStack,
facingXIn: Float, facingYIn: Float, facingZIn: Float) {
require(usesViaFabricPlus) { "ViaFabricPlus is missing" }
require(isEqual1_8) { "Not 1.8 protocol" }

VfpCompatibility1_8.INSTANCE.sendBlockPlacement(blockPos, face, heldItem, facingXIn, facingYIn, facingZIn)
}

0 comments on commit 7c98e3a

Please sign in to comment.