mirror of
https://github.com/TheWhiteDog9487/RandomTeleporter.git
synced 2025-08-29 19:33:05 +00:00
0.1.1
游戏版本1.19.1,功能全部完成
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package xyz.thewhitedog9487;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class RandomTeleporterClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package xyz.thewhitedog9487.mixin.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class ExampleClientMixin {
|
||||
@Inject(at = @At("HEAD"), method = "run")
|
||||
private void run(CallbackInfo info) {
|
||||
// This code is injected into the start of MinecraftClient.run()V
|
||||
}
|
||||
}
|
11
src/client/resources/randomteleporter.client.mixins.json
Normal file
11
src/client/resources/randomteleporter.client.mixins.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"required": false,
|
||||
"package": "xyz.thewhitedog9487.mixin.client",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
63
src/main/java/xyz/thewhitedog9487/CommandRegister.java
Normal file
63
src/main/java/xyz/thewhitedog9487/CommandRegister.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package xyz.thewhitedog9487;
|
||||
|
||||
import com.mojang.brigadier.arguments.LongArgumentType;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.SplittableRandom;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
import static xyz.thewhitedog9487.Toolbox.Distance;
|
||||
|
||||
public class CommandRegister {
|
||||
final static long WorldBorder = (long) 2.9e7;
|
||||
static byte Retry = 0;
|
||||
public static void Register(String Name){
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) ->{
|
||||
dispatcher.register(literal(Name)
|
||||
.requires(source -> source.hasPermissionLevel(4))
|
||||
.executes(context -> execute_command_radius(
|
||||
context.getSource(),null)));});
|
||||
CommandRegistrationCallback.EVENT
|
||||
.register((dispatcher, registryAccess, environment) -> {
|
||||
dispatcher.register(literal(Name)
|
||||
.then(argument("Radius(半径)", LongArgumentType.longArg())
|
||||
.requires(source -> source.hasPermissionLevel(4))
|
||||
.executes(context -> execute_command_radius(
|
||||
context.getSource(),
|
||||
LongArgumentType.getLong(context, "Radius(半径)")))));});}
|
||||
public static void Register(){
|
||||
Register("随机传送");
|
||||
Register("rtp");}
|
||||
static int execute_command_radius(ServerCommandSource Source, Long Radius){
|
||||
if (Source.getPlayer() == null) {
|
||||
Source.sendFeedback(Text.translatable("error.twd.rtp.not_player"), true);
|
||||
return -1;}
|
||||
if (Radius == null){Radius = WorldBorder - (long) 1e4;}
|
||||
Radius = Math.abs(Radius);
|
||||
long Coordinate_X = new SplittableRandom().nextLong(-Radius, Radius);
|
||||
long Coordinate_Z = new SplittableRandom().nextLong(-Radius, Radius);
|
||||
int Coordinate_Y = 320;
|
||||
for (;
|
||||
Blocks.AIR == Source.getWorld().getBlockState(new BlockPos(Coordinate_X, Coordinate_Y, Coordinate_Z)).getBlock() ||
|
||||
Blocks.VOID_AIR == Source.getWorld().getBlockState(new BlockPos(Coordinate_X, Coordinate_Y, Coordinate_Z)).getBlock() ||
|
||||
Blocks.CAVE_AIR == Source.getWorld().getBlockState(new BlockPos(Coordinate_X, Coordinate_Y, Coordinate_Z)).getBlock()
|
||||
;Coordinate_Y--){}
|
||||
Coordinate_Y++;
|
||||
Vec3d Coordinate = new Vec3d(Coordinate_X, Coordinate_Y, Coordinate_Z);
|
||||
if (Radius == WorldBorder && Retry < 126 && Distance(Source.getPlayer().getPos(), Coordinate) < 1e5){
|
||||
Retry++;
|
||||
execute_command_radius(Source, Radius);
|
||||
return 0;}
|
||||
if (Retry >= 126){
|
||||
Source.sendFeedback(Text.translatable("warning.twd.rtp.retry"), true);}
|
||||
Source.getPlayer().teleport(Source.getWorld(), Coordinate_X, Coordinate_Y, Coordinate_Z, 0, 0);
|
||||
Source.sendFeedback(Text.translatable("info.twd.rtp.success", Source.getPlayer().getName(), Coordinate_X, Coordinate_Y, Coordinate_Z),true);
|
||||
return 0;}
|
||||
}
|
22
src/main/java/xyz/thewhitedog9487/RandomTeleporter.java
Normal file
22
src/main/java/xyz/thewhitedog9487/RandomTeleporter.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package xyz.thewhitedog9487;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RandomTeleporter implements ModInitializer {
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("randomteleporter");
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
CommandRegister.Register();
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
}
|
||||
}
|
10
src/main/java/xyz/thewhitedog9487/Toolbox.java
Normal file
10
src/main/java/xyz/thewhitedog9487/Toolbox.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package xyz.thewhitedog9487;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class Toolbox {
|
||||
static public double Distance(Vec3d A, Vec3d B){
|
||||
return Math.sqrt(
|
||||
Math.pow(A.getX() - B.getX(), 2) +
|
||||
Math.pow(A.getY() - B.getY(), 2));}
|
||||
}
|
15
src/main/java/xyz/thewhitedog9487/mixin/ExampleMixin.java
Normal file
15
src/main/java/xyz/thewhitedog9487/mixin/ExampleMixin.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package xyz.thewhitedog9487.mixin;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "loadWorld")
|
||||
private void init(CallbackInfo info) {
|
||||
// This code is injected into the start of MinecraftServer.loadWorld()V
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/randomteleporter/icon.png
Normal file
BIN
src/main/resources/assets/randomteleporter/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 453 B |
@@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"info.twd.rtp.success": "已将玩家%s传送到%d %d %d",
|
||||
"error.twd.rtp.not_player": "执行命令的不是玩家",
|
||||
"warning.twd.rtp.retry": "重试次数过大,为避免死循环将在本次传送中取消距离保护"
|
||||
}
|
47
src/main/resources/fabric.mod.json
Normal file
47
src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "randomteleporter",
|
||||
"version": "${version}",
|
||||
"name": "RandomTeleporter",
|
||||
"description": "增加了两个用于随机传送的命令",
|
||||
"authors": [
|
||||
"TheWhiteDog9487"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://modrinth.com/mod/randomteleporter",
|
||||
"sources": "https://github.com/TheWhiteDog9487/RandomTeleporter"
|
||||
},
|
||||
"license": "WTFPL",
|
||||
"icon": "assets/randomteleporter/icon.png",
|
||||
"environment": "server",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"xyz.thewhitedog9487.RandomTeleporter"
|
||||
],
|
||||
"client": [
|
||||
"xyz.thewhitedog9487.RandomTeleporterClient"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"randomteleporter.mixins.json",
|
||||
{
|
||||
"config": "randomteleporter.client.mixins.json",
|
||||
"environment": "client"
|
||||
}
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.24",
|
||||
"minecraft": "~1.19.1",
|
||||
"java": ">=17",
|
||||
"fabric": "*"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
},
|
||||
"custom": {
|
||||
"modmenu": {
|
||||
"links": {
|
||||
"twd-sasf.bilibili": "https://space.bilibili.com/401746666",
|
||||
"twd-sasf.blog": "www.thewhitedog9487.xyz"},
|
||||
"update_checker": true}}
|
||||
}
|
11
src/main/resources/randomteleporter.mixins.json
Normal file
11
src/main/resources/randomteleporter.mixins.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"required": false,
|
||||
"package": "xyz.thewhitedog9487.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user