aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/mc/asFakeServer.kt
blob: 1075d62a2969212f1481423c837ed7fed2a4fe16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package moe.nea.firmament.util.mc

import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.minecraft.commands.CommandSource
import net.minecraft.commands.CommandSourceStack
import net.minecraft.network.chat.Component

fun FabricClientCommandSource.asFakeServer(): CommandSourceStack {
	val source = this
	return CommandSourceStack(
		object : CommandSource {
			override fun sendSystemMessage(message: Component?) {
				source.player.displayClientMessage(message, false)
			}

			override fun acceptsSuccess(): Boolean {
				return true
			}

			override fun acceptsFailure(): Boolean {
				return true
			}

			override fun shouldInformAdmins(): Boolean {
				return true
			}
		},
		source.position,
		source.rotation,
		null,
		0,
		"FakeServerCommandSource",
		Component.literal("FakeServerCommandSource"),
		null,
		source.player
	)
}