Skip to content

Commit 5b6bafe

Browse files
committed
refactor(minecraft): 更新命令方块相关类引用
- 将 AbstractCommandBlockEditScreen 中的 BaseCommandBlock 替换为 BaseCommandBlockCommandSource - 修改 AbstractMinecart 中的 MinecartCommandBlock 为 MinecartCommandBlockCommandSource - 更新 AdvancementHolder 实现接口路径 - 移除未使用的 EnumMap 导入 - 添加 AdvancementTreeMixin 以移除日志输出
1 parent 4d1019e commit 5b6bafe

37 files changed

Lines changed: 1553 additions & 36 deletions
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
--- a/net/minecraft/advancements/AdvancementHolder.java
22
+++ b/net/minecraft/advancements/AdvancementHolder.java
3-
@@ -1,12 +_,14 @@
3+
@@ -1,12 +_,13 @@
44
package net.minecraft.advancements;
55

66
import java.util.List;
77
+
8-
+import com.taiyitistmc.injection.advancements.AdvancementHolderInjection;
98
import net.minecraft.network.RegistryFriendlyByteBuf;
109
import net.minecraft.network.codec.ByteBufCodecs;
1110
import net.minecraft.network.codec.StreamCodec;
1211
import net.minecraft.resources.ResourceLocation;
1312

1413
-public record AdvancementHolder(ResourceLocation id, Advancement value) {
15-
+public record AdvancementHolder(ResourceLocation id, Advancement value) implements AdvancementHolderInjection {
14+
+public record AdvancementHolder(ResourceLocation id, Advancement value) implements com.taiyitistmc.injection.advancements.InjectionAdvancementHolder {
1615
public static final StreamCodec<RegistryFriendlyByteBuf, AdvancementHolder> STREAM_CODEC = StreamCodec.composite(
1716
ResourceLocation.STREAM_CODEC, AdvancementHolder::id, Advancement.STREAM_CODEC, AdvancementHolder::value, AdvancementHolder::new
1817
);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--- a/net/minecraft/client/gui/screens/inventory/AbstractCommandBlockEditScreen.java
2+
+++ b/net/minecraft/client/gui/screens/inventory/AbstractCommandBlockEditScreen.java
3+
@@ -11,7 +_,7 @@
4+
import net.minecraft.network.chat.CommonComponents;
5+
import net.minecraft.network.chat.Component;
6+
import net.minecraft.network.chat.MutableComponent;
7+
-import net.minecraft.world.level.BaseCommandBlock;
8+
+import net.minecraft.world.level.BaseCommandBlockCommandSource;
9+
import net.neoforged.api.distmarker.Dist;
10+
import net.neoforged.api.distmarker.OnlyIn;
11+
12+
@@ -38,7 +_,7 @@
13+
}
14+
}
15+
16+
- abstract BaseCommandBlock getCommandBlock();
17+
+ abstract BaseCommandBlockCommandSource getCommandBlock();
18+
19+
abstract int getPreviousY();
20+
21+
@@ -56,7 +_,7 @@
22+
.withInitialValue(flag)
23+
.displayOnlyValue()
24+
.create(this.width / 2 + 150 - 20, this.getPreviousY(), 20, 20, Component.translatable("advMode.trackOutput"), (p_169596_, p_169597_) -> {
25+
- BaseCommandBlock basecommandblock = this.getCommandBlock();
26+
+ BaseCommandBlockCommandSource basecommandblock = this.getCommandBlock();
27+
basecommandblock.setTrackOutput(p_169597_);
28+
this.updatePreviousOutput(p_169597_);
29+
})
30+
@@ -104,7 +_,7 @@
31+
}
32+
33+
protected void onDone() {
34+
- BaseCommandBlock basecommandblock = this.getCommandBlock();
35+
+ BaseCommandBlockCommandSource basecommandblock = this.getCommandBlock();
36+
this.populateAndSendPacket(basecommandblock);
37+
if (!basecommandblock.isTrackOutput()) {
38+
basecommandblock.setLastOutput(null);
39+
@@ -113,7 +_,7 @@
40+
this.minecraft.setScreen(null);
41+
}
42+
43+
- protected abstract void populateAndSendPacket(BaseCommandBlock p_97670_);
44+
+ protected abstract void populateAndSendPacket(BaseCommandBlockCommandSource p_97670_);
45+
46+
private void onEdited(String p_97689_) {
47+
this.commandSuggestions.updateCommandInfo();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--- a/net/minecraft/client/gui/screens/inventory/CommandBlockEditScreen.java
2+
+++ b/net/minecraft/client/gui/screens/inventory/CommandBlockEditScreen.java
3+
@@ -5,7 +_,7 @@
4+
import net.minecraft.core.BlockPos;
5+
import net.minecraft.network.chat.Component;
6+
import net.minecraft.network.protocol.game.ServerboundSetCommandBlockPacket;
7+
-import net.minecraft.world.level.BaseCommandBlock;
8+
+import net.minecraft.world.level.BaseCommandBlockCommandSource;
9+
import net.minecraft.world.level.block.entity.CommandBlockEntity;
10+
import net.neoforged.api.distmarker.Dist;
11+
import net.neoforged.api.distmarker.OnlyIn;
12+
@@ -25,7 +_,7 @@
13+
}
14+
15+
@Override
16+
- BaseCommandBlock getCommandBlock() {
17+
+ BaseCommandBlockCommandSource getCommandBlock() {
18+
return this.autoCommandBlock.getCommandBlock();
19+
}
20+
21+
@@ -76,7 +_,7 @@
22+
}
23+
24+
public void updateGui() {
25+
- BaseCommandBlock basecommandblock = this.autoCommandBlock.getCommandBlock();
26+
+ BaseCommandBlockCommandSource basecommandblock = this.autoCommandBlock.getCommandBlock();
27+
this.commandEdit.setValue(basecommandblock.getCommand());
28+
boolean flag = basecommandblock.isTrackOutput();
29+
this.mode = this.autoCommandBlock.getMode();
30+
@@ -97,7 +_,7 @@
31+
}
32+
33+
@Override
34+
- protected void populateAndSendPacket(BaseCommandBlock p_98384_) {
35+
+ protected void populateAndSendPacket(BaseCommandBlockCommandSource p_98384_) {
36+
this.minecraft
37+
.getConnection()
38+
.send(
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--- a/net/minecraft/client/gui/screens/inventory/MinecartCommandBlockEditScreen.java
2+
+++ b/net/minecraft/client/gui/screens/inventory/MinecartCommandBlockEditScreen.java
3+
@@ -1,21 +_,20 @@
4+
package net.minecraft.client.gui.screens.inventory;
5+
6+
import net.minecraft.network.protocol.game.ServerboundSetCommandMinecartPacket;
7+
-import net.minecraft.world.entity.vehicle.MinecartCommandBlock;
8+
-import net.minecraft.world.level.BaseCommandBlock;
9+
+import net.minecraft.world.level.BaseCommandBlockCommandSource;
10+
import net.neoforged.api.distmarker.Dist;
11+
import net.neoforged.api.distmarker.OnlyIn;
12+
13+
@OnlyIn(Dist.CLIENT)
14+
public class MinecartCommandBlockEditScreen extends AbstractCommandBlockEditScreen {
15+
- private final BaseCommandBlock commandBlock;
16+
+ private final BaseCommandBlockCommandSource commandBlock;
17+
18+
- public MinecartCommandBlockEditScreen(BaseCommandBlock p_99216_) {
19+
+ public MinecartCommandBlockEditScreen(BaseCommandBlockCommandSource p_99216_) {
20+
this.commandBlock = p_99216_;
21+
}
22+
23+
@Override
24+
- public BaseCommandBlock getCommandBlock() {
25+
+ public BaseCommandBlockCommandSource getCommandBlock() {
26+
return this.commandBlock;
27+
}
28+
29+
@@ -31,8 +_,8 @@
30+
}
31+
32+
@Override
33+
- protected void populateAndSendPacket(BaseCommandBlock p_99218_) {
34+
- if (p_99218_ instanceof MinecartCommandBlock.MinecartCommandBase minecartcommandblock$minecartcommandbase) {
35+
+ protected void populateAndSendPacket(BaseCommandBlockCommandSource p_99218_) {
36+
+ if (p_99218_ instanceof MinecartCommandBlock.MinecartCommandBaseCommandSource minecartcommandblock$minecartcommandbase) {
37+
this.minecraft
38+
.getConnection()
39+
.send(

‎patches/net/minecraft/client/player/LocalPlayer.java.patch‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
--- a/net/minecraft/client/player/LocalPlayer.java
22
+++ b/net/minecraft/client/player/LocalPlayer.java
3+
@@ -69,11 +_,10 @@
4+
import net.minecraft.world.entity.vehicle.AbstractMinecart;
5+
import net.minecraft.world.entity.vehicle.Boat;
6+
import net.minecraft.world.inventory.ClickAction;
7+
-import net.minecraft.world.item.ElytraItem;
8+
import net.minecraft.world.item.ItemStack;
9+
import net.minecraft.world.item.Items;
10+
import net.minecraft.world.item.crafting.RecipeHolder;
11+
-import net.minecraft.world.level.BaseCommandBlock;
12+
+import net.minecraft.world.level.BaseCommandBlockCommandSource;
13+
import net.minecraft.world.level.GameType;
14+
import net.minecraft.world.level.block.Portal;
15+
import net.minecraft.world.level.block.entity.CommandBlockEntity;
316
@@ -297,6 +_,7 @@
417
ServerboundPlayerActionPacket.Action serverboundplayeractionpacket$action = p_108701_
518
? ServerboundPlayerActionPacket.Action.DROP_ALL_ITEMS
@@ -24,6 +37,15 @@
2437
}
2538

2639
@Override
40+
@@ -574,7 +_,7 @@
41+
}
42+
43+
@Override
44+
- public void openMinecartCommandBlock(BaseCommandBlock p_108678_) {
45+
+ public void openMinecartCommandBlock(BaseCommandBlockCommandSource p_108678_) {
46+
this.minecraft.setScreen(new MinecartCommandBlockEditScreen(p_108678_));
47+
}
48+
2749
@@ -682,6 +_,7 @@
2850
&& (this.isShiftKeyDown() || !this.isSleeping() && !this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.STANDING));
2951
float f = (float)this.getAttributeValue(Attributes.SNEAKING_SPEED);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--- a/net/minecraft/commands/CommandSource.java
2+
+++ b/net/minecraft/commands/CommandSource.java
3+
@@ -2,7 +_,7 @@
4+
5+
import net.minecraft.network.chat.Component;
6+
7+
-public interface CommandSource {
8+
+public interface CommandSource extends com.taiyitistmc.injection.commands.InjectionCommandSource {
9+
CommandSource NULL = new CommandSource() {
10+
@Override
11+
public void sendSystemMessage(Component p_230799_) {
12+
@@ -22,6 +_,13 @@
13+
public boolean shouldInformAdmins() {
14+
return false;
15+
}
16+
+
17+
+ // CraftBukkit start
18+
+ @Override
19+
+ public org.bukkit.command.CommandSender getBukkitSender(CommandSourceStack wrapper) {
20+
+ throw new UnsupportedOperationException("Not supported yet.");
21+
+ }
22+
+ // CraftBukkit end
23+
};
24+
25+
void sendSystemMessage(Component p_230797_);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- a/net/minecraft/commands/CommandSourceStack.java
2+
+++ b/net/minecraft/commands/CommandSourceStack.java
3+
@@ -17,6 +_,7 @@
4+
import java.util.function.Supplier;
5+
import java.util.stream.Stream;
6+
import javax.annotation.Nullable;
7+
+
8+
import net.minecraft.ChatFormatting;
9+
import net.minecraft.commands.arguments.EntityAnchorArgument;
10+
import net.minecraft.commands.execution.TraceCallbacks;
11+
@@ -43,7 +_,7 @@
12+
import net.minecraft.world.phys.Vec2;
13+
import net.minecraft.world.phys.Vec3;
14+
15+
-public class CommandSourceStack implements ExecutionCommandSource<CommandSourceStack>, SharedSuggestionProvider, net.neoforged.neoforge.common.extensions.ICommandSourceStackExtension {
16+
+public class CommandSourceStack implements ExecutionCommandSource<CommandSourceStack>, SharedSuggestionProvider, net.neoforged.neoforge.common.extensions.ICommandSourceStackExtension, com.taiyitistmc.injection.commands.InjectionCommandSourceStack {
17+
public static final SimpleCommandExceptionType ERROR_NOT_PLAYER = new SimpleCommandExceptionType(Component.translatable("permissions.requires.player"));
18+
public static final SimpleCommandExceptionType ERROR_NOT_ENTITY = new SimpleCommandExceptionType(Component.translatable("permissions.requires.entity"));
19+
public final CommandSource source;

‎patches/net/minecraft/commands/Commands.java.patch‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
--- a/net/minecraft/commands/Commands.java
22
+++ b/net/minecraft/commands/Commands.java
3-
@@ -25,6 +_,8 @@
3+
@@ -8,23 +_,25 @@
4+
import com.mojang.brigadier.builder.ArgumentBuilder;
5+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
6+
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
7+
-import com.mojang.brigadier.context.CommandContext;
8+
import com.mojang.brigadier.context.CommandContextBuilder;
9+
import com.mojang.brigadier.context.ContextChain;
10+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
11+
import com.mojang.brigadier.tree.CommandNode;
12+
import com.mojang.brigadier.tree.RootCommandNode;
13+
import com.mojang.logging.LogUtils;
14+
-import java.util.Collection;
15+
+
16+
import java.util.Map;
17+
+import java.util.Objects;
18+
import java.util.Optional;
19+
import java.util.Set;
20+
+import java.util.concurrent.atomic.AtomicReference;
21+
import java.util.function.Consumer;
22+
import java.util.function.Predicate;
23+
import java.util.function.UnaryOperator;
424
import java.util.stream.Collectors;
525
import java.util.stream.Stream;
626
import javax.annotation.Nullable;
727
+
8-
+import com.taiyitistmc.injection.advancements.CommandsInjection;
928
import net.minecraft.ChatFormatting;
1029
import net.minecraft.SharedConstants;
1130
import net.minecraft.Util;
@@ -22,7 +41,7 @@
2241
import org.slf4j.Logger;
2342

2443
-public class Commands {
25-
+public class Commands implements CommandsInjection {
44+
+public class Commands implements com.taiyitistmc.injection.commands.InjectionCommands {
2645
private static final ThreadLocal<ExecutionContext<CommandSourceStack>> CURRENT_EXECUTION_CONTEXT = new ThreadLocal<>();
2746
private static final Logger LOGGER = LogUtils.getLogger();
2847
public static final int LEVEL_ALL = 0;
@@ -60,6 +79,31 @@
6079
commandsourcestack.getServer().getProfiler().push(() -> "/" + p_242841_);
6180
ContextChain<CommandSourceStack> contextchain = finishParsing(p_242844_, p_242841_, commandsourcestack);
6281

82+
@@ -306,6 +_,15 @@
83+
}
84+
}
85+
86+
+ private static AtomicReference<String> taiyitist$lable =
87+
+ new AtomicReference<>("/");
88+
+
89+
+ @Nullable
90+
+ private static ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> p_307220_, String p_307311_, CommandSourceStack p_307676_, String label) { // CraftBukkit
91+
+ taiyitist$lable.set(label);
92+
+ return finishParsing(p_307220_, p_307311_, p_307676_);
93+
+ }
94+
+
95+
@Nullable
96+
private static ContextChain<CommandSourceStack> finishParsing(ParseResults<CommandSourceStack> p_307220_, String p_307311_, CommandSourceStack p_307676_) {
97+
try {
98+
@@ -318,7 +_,7 @@
99+
int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor());
100+
MutableComponent mutablecomponent = Component.empty()
101+
.withStyle(ChatFormatting.GRAY)
102+
- .withStyle(p_82134_ -> p_82134_.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + p_307311_)));
103+
+ .withStyle(p_82134_ -> p_82134_.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, !Objects.equals(taiyitist$lable.get(), "/") ? taiyitist$lable.get() : taiyitist$lable.get() + p_307311_)));
104+
if (i > 10) {
105+
mutablecomponent.append(CommonComponents.ELLIPSIS);
106+
}
63107
@@ -362,7 +_,8 @@
64108
Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newHashMap();
65109
RootCommandNode<SharedSuggestionProvider> rootcommandnode = new RootCommandNode<>();

‎patches/net/minecraft/commands/arguments/EntityArgument.java.patch‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
--- a/net/minecraft/commands/arguments/EntityArgument.java
22
+++ b/net/minecraft/commands/arguments/EntityArgument.java
3+
@@ -13,6 +_,7 @@
4+
import java.util.Collection;
5+
import java.util.List;
6+
import java.util.concurrent.CompletableFuture;
7+
+
8+
import net.minecraft.commands.CommandBuildContext;
9+
import net.minecraft.commands.CommandSourceStack;
10+
import net.minecraft.commands.SharedSuggestionProvider;
11+
@@ -24,7 +_,7 @@
12+
import net.minecraft.server.level.ServerPlayer;
13+
import net.minecraft.world.entity.Entity;
14+
15+
-public class EntityArgument implements ArgumentType<EntitySelector> {
16+
+public class EntityArgument implements ArgumentType<EntitySelector>, com.taiyitistmc.injection.commands.arguments.InjectionEntityArgument {
17+
private static final Collection<String> EXAMPLES = Arrays.asList("Player", "0123", "@e", "@e[type=foo]", "dd12be42-52a9-4a91-a8a1-11c01849e498");
18+
public static final SimpleCommandExceptionType ERROR_NOT_SINGLE_ENTITY = new SimpleCommandExceptionType(Component.translatable("argument.entity.toomany"));
19+
public static final SimpleCommandExceptionType ERROR_NOT_SINGLE_PLAYER = new SimpleCommandExceptionType(Component.translatable("argument.player.toomany"));
320
@@ -127,7 +_,7 @@
421
if (p_91482_.getSource() instanceof SharedSuggestionProvider sharedsuggestionprovider) {
522
StringReader stringreader = new StringReader(p_91483_.getInput());

‎patches/net/minecraft/commands/arguments/selector/EntitySelectorParser.java.patch‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
--- a/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
22
+++ b/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
3+
@@ -31,7 +_,7 @@
4+
import net.minecraft.world.phys.AABB;
5+
import net.minecraft.world.phys.Vec3;
6+
7+
-public class EntitySelectorParser {
8+
+public class EntitySelectorParser implements com.taiyitistmc.injection.commands.arguments.selector.InjectionEntitySelectorParser{
9+
public static final char SYNTAX_SELECTOR_START = '@';
10+
private static final char SYNTAX_OPTIONS_START = '[';
11+
private static final char SYNTAX_OPTIONS_END = ']';
312
@@ -481,6 +_,9 @@
413
}
514

0 commit comments

Comments
 (0)