Skip to content

Commit

Permalink
Merge pull request #20 from Bunnui/19-功能建议-平面向下向上破基岩末地传送门
Browse files Browse the repository at this point in the history
19 功能建议 平面向下向上破基岩末地传送门
  • Loading branch information
bunnyi116 authored Aug 17, 2023
2 parents 9ca2087 + f8e9e04 commit 85128f7
Show file tree
Hide file tree
Showing 24 changed files with 1,005 additions and 534 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ free software which everyone can redistribute and change under these terms.

To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
TaskState the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx1G

# Mod Properties
mod_version=1.1.8
mod_version=1.1.9
maven_group=yan.lx.bedrockMiner
archives_base_name=bedrock-miner

Expand All @@ -11,8 +11,8 @@ archives_base_name=bedrock-miner

# Dependencies
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.8
loader_version=0.14.21
yarn_mappings=1.20.1+build.10
loader_version=0.14.22

#Fabric api
fabric_version=0.84.0+1.20.1
fabric_version=0.87.0+1.20.1
18 changes: 11 additions & 7 deletions src/main/java/yan/lx/bedrockminer/BedrockMinerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import yan.lx.bedrockminer.command.*;
import yan.lx.bedrockminer.handle.TaskManager;
import yan.lx.bedrockminer.task.TaskManager;

import java.util.ArrayList;

Expand All @@ -15,7 +15,8 @@ public class BedrockMinerMod implements ModInitializer {
public static final String MOD_NAME = "Bedrock Miner";
public static final String MOD_ID = "bedrockminer";
public static final String COMMAND_PREFIX = "bedrockMiner";
public static final Logger LOGGER = LoggerFactory.getLogger("Bedrock Miner");
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME);
public static final boolean TEST = false;

@Override
public void onInitialize() {
Expand All @@ -38,11 +39,14 @@ private void registerCommand() {
command.register(dispatcher, registryAccess);
}
// 主命令执行
dispatcher.register(literal(COMMAND_PREFIX).executes(context -> {
TaskManager.setWorking(!TaskManager.isWorking());
return 0;
})
);
var root = literal(COMMAND_PREFIX).executes(context -> {
TaskManager.setWorking(!TaskManager.isWorking());
return 0;
});
if (TEST) {
Test.register(root);
}
dispatcher.register(root);
});
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/yan/lx/bedrockminer/Debug.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package yan.lx.bedrockminer;

import java.util.ArrayList;
import java.util.List;

public class Debug {
public static void info(String msg) {
BedrockMinerMod.LOGGER.info(msg);
Expand Down
94 changes: 94 additions & 0 deletions src/main/java/yan/lx/bedrockminer/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package yan.lx.bedrockminer;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import yan.lx.bedrockminer.command.argument.BlockPosArgumentType;
import yan.lx.bedrockminer.utils.BlockPlacerUtils;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
import static net.minecraft.block.Block.sideCoversSmallSquare;

public class Test {

public static void register(LiteralArgumentBuilder<FabricClientCommandSource> root) {
root.then(literal("test").executes(Test::onCommandExecute)
.then(argument("blockPos", BlockPosArgumentType.blockPos()).executes(Test::onBlockPos)));
}

private static int onBlockPos(CommandContext<FabricClientCommandSource> context) {
var blockPos = BlockPosArgumentType.getBlockPos(context, "blockPos");
BlockPlacerUtils.placement(blockPos.up(), Direction.NORTH);
return 0;
}

public static int onCommandExecute(CommandContext<FabricClientCommandSource> context) {
var client = MinecraftClient.getInstance();
var world = client.world;
var player = client.player;
var hitResult = client.crosshairTarget;
var interactionManager = client.interactionManager;
if (world == null || player == null || hitResult == null) return 0;
if (hitResult.getType() == HitResult.Type.BLOCK) {
var blockHitResult = (BlockHitResult) hitResult;
var blockPos = blockHitResult.getBlockPos();
var blockState = world.getBlockState(blockPos);
var block = blockState.getBlock();

Debug.info(world.getWorldBorder().getMaxRadius());
}


//BlockPlacerUtils.placement(new BlockPos(8, -60, 8), Direction.NORTH, Items.REDSTONE_TORCH);
// var itemStack = player.getMainHandStack();
// var registry = world.getRegistryManager().get(RegistryKeys.BLOCK);
// var cachedBlockPosition = new CachedBlockPosition(world, blockPos, false);
// Debug.info();
// Debug.info("[canPlaceOn]" + itemStack.canPlaceOn(registry, cachedBlockPosition));
// Debug.info("[canDestroy]" + itemStack.canDestroy(registry, cachedBlockPosition));

return 0;
}


public static void onInteractBlock(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
var pos = hitResult.getPos();
var side = hitResult.getSide();
var blockPos = hitResult.getBlockPos();
var insideBlock = hitResult.isInsideBlock();
// Debug.info("%s, %s, %s, %s, %s", hand, pos, side, blockPos, insideBlock);
}

public static void onTick(ClientConnection connection, MinecraftServer server, ServerPlayerEntity player) {
// Debug.info("%s, %s", player.getYaw(), player.getPitch());
}

public static void onPlayerInteractBlock(ServerPlayerEntity player, PlayerInteractBlockC2SPacket packet, CallbackInfo ci) {
var hitResult = packet.getBlockHitResult();
var hand = packet.getHand();
var sequence = packet.getSequence();
var pos = hitResult.getPos();
var side = hitResult.getSide();
var blockPos = hitResult.getBlockPos();
var insideBlock = hitResult.isInsideBlock();
Debug.info("%s, %s", player.getYaw(), player.getPitch());
Debug.info("%s, %s, %s, %s, %s, %s", sequence, hand, pos, side, blockPos, insideBlock);
}
}
10 changes: 5 additions & 5 deletions src/main/java/yan/lx/bedrockminer/command/TaskCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import yan.lx.bedrockminer.BedrockMinerLang;
import yan.lx.bedrockminer.command.argument.BlockPosArgumentType;
import yan.lx.bedrockminer.config.Config;
import yan.lx.bedrockminer.handle.TaskManager;
import yan.lx.bedrockminer.task.TaskManager;
import yan.lx.bedrockminer.utils.MessageUtils;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
Expand All @@ -28,10 +28,10 @@ public void build(LiteralArgumentBuilder<FabricClientCommandSource> builder, Com
builder
.then(literal("add")
.then(argument("blockPos", BlockPosArgumentType.blockPos()).executes(this::add)))
.then(literal("clear").executes(this::clear))
.then(literal("limit")
.then(argument("limit", IntegerArgumentType.integer(1, 5))
.executes(this::toggleSwitch)));
.then(literal("clear").executes(this::clear));
// .then(literal("limit")
// .then(argument("limit", IntegerArgumentType.integer(1, 5))
// .executes(this::toggleSwitch)));
}

private int add(CommandContext<FabricClientCommandSource> context) {
Expand Down
Loading

0 comments on commit 85128f7

Please sign in to comment.