This repository was archived by the owner on Jul 31, 2024. It is now read-only.
forked from Mafuyu33/mafishmod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForTest.txt
More file actions
143 lines (113 loc) · 4.47 KB
/
ForTest.txt
File metadata and controls
143 lines (113 loc) · 4.47 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
jvm参数加 -Dmixin.debug.export=true 可以输出mixin的注入后的结果
重置gradle
./gradlew clean
./gradlew --refresh-dependencies
调试
System.out.println(123);
发送信息给玩家
player.sendMessage(Text.literal((String.valueOf(123))),false);
播放音乐
world.playSound(user, user.getBlockPos(), ModSounds.METAL_DETECTOR_FOUND_ORE, SoundCategory.PLAYERS);
附魔查看
int k = EnchantmentHelper.getLevel(Enchantments, itemStack);
if (k > 0) {
}
方块附魔查看
int k = BlockEnchantmentStorage.getLevel(Enchantments.INFINITY,pos);
if(k>0){
}
给奇怪的方块实体添加onPlace
if (!world.isClient) {
System.out.println(itemStack.getEnchantments());
if (!Objects.equals(itemStack.getEnchantments(), new NbtList())) {
NbtList enchantments = itemStack.getEnchantments(); // 获取物品栈上的附魔信息列表
BlockEnchantmentHelper.storeEnchantment(pos,enchantments);// 将附魔信息列表存储
}
}
对某个实体造成伤害
this.damage(getDamageSources().playerAttack(closestPlayer), 10f+level*2);
entity.damage(entity.getDamageSources().cactus(),1f);
Mixin Helper
// 创建一个静态Map来存储实体ID和值
private static final Map<Integer, Integer> entityValueMap = new HashMap<>();
// 在适当的时候将实体ID和值添加到Map中
public static void storeEntityValue(int entityID, int value) {
entityValueMap.put(entityID, value);
}
// 在需要时从Map中检索值
public static int getEntityValue(int entityID) {
return entityValueMap.getOrDefault(entityID, 0); // 默认值为0,如果未找到实体ID
}
检测双手物品的附魔
Hand hand = this.getActiveHand();
ItemStack itemStack = this.getStackInHand(hand);
PlayerEntity playerEntity = getPlayerOwner();
if (playerEntity != null) {
Hand hand = playerEntity.getActiveHand();
if (hand != null) {
ItemStack itemStack = playerEntity.getStackInHand(hand);
if (itemStack.getItem() == Items.123) {
int k = EnchantmentHelper.getLevel(ModEnchantments.123, itemStack);
if (k > 0) {
}
}
}
}
引雷
LightningEntity lightningEntity = EntityType.LIGHTNING_BOLT.create(this.getWorld());
if (lightningEntity != null) {
lightningEntity.refreshPositionAfterTeleport(Vec3d.ofBottomCenter(blockPos));
lightningEntity.setChanneler(user instanceof ServerPlayerEntity ? (ServerPlayerEntity) user : null);
this.getWorld().spawnEntity(lightningEntity);
SoundEvent soundEvent = SoundEvents.ITEM_TRIDENT_THUNDER;
this.playSound(soundEvent, 5, 1.0F);
}
不显示指令
dispatcher.parse("gamerule sendCommandFeedback false", server.getCommandSource());
使用某个指令
if (user instanceof ServerPlayerEntity) {
MinecraftServer server = user.getServer();
// 获取服务器命令调度程序
CommandDispatcher<ServerCommandSource> dispatcher = server.getCommandManager().getDispatcher();
try {
// 解析指令并获取命令源
ParseResults<ServerCommandSource> parseResults
= dispatcher.parse("tick freeze", server.getCommandSource());
// 执行指令
dispatcher.execute(parseResults);
// 在控制台输出提示信息
} catch (CommandSyntaxException e) {
// 指令语法异常处理
e.printStackTrace();
}
}
计时器
private void startDelayedOperation(PlayerEntity player, BlockPos pos) {
if (ServerManager.getServerInstance() != null) {
ServerManager.getServerInstance().execute(() -> {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//执行的东西
}
}, 200); // 延迟0.2秒执行,单位为毫秒
});
}
}
生成动物
EntityType.COW.spawn(((ServerWorld) user.getWorld()),user.getBlockPos(), SpawnReason.TRIGGERED);
Mixin中强制转换this为原类
PlayerEntity user = (PlayerEntity) (Object) this;
网络传输
PacketByteBuf buf = PacketByteBufs.create();//C2S
buf.writeInt(*);
ClientPlayNetworking.send(ModMessages.*, buf);
PacketByteBuf buf = PacketByteBufs.create();//S2C
buf.writeInt(*);
ServerPlayNetworking.send((ServerPlayerEntity) player, ModMessages.*, buf);
获取ClientWorld实例
MinecraftClient.getInstance().world
有MC-VR-API并且在VR中的时候
if (entity instanceof PlayerEntity user && VRPlugin.canRetrieveData(user)) {
*玩家添加速度在客户端,其他生物添加速度在服务端*