已改:accessWidener/ fabric.mod.json/ HatCommand/ SitCommand/ util 接口/ 映射表文档。剩余源码待迁移。
This commit is contained in:
1 parent
88aaea801c
commit
a1a2103f47
8 files changed
+156
-50
No files matched your search
@@ -2,29 +2,28 @@ package com.github.zly2006.carpetslsaddition.command;
|
||||
|
||||
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class HatCommand {
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
dispatcher.register(CommandManager.literal("hat")
|
||||
.requires(ServerCommandSource::isExecutedByPlayer)
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("hat")
|
||||
.requires(CommandSourceStack::isPlayer)
|
||||
.requires((commandSource) -> SLSCarpetSettings.canUseHatCommand)
|
||||
.executes(context -> {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
ServerPlayer player = context.getSource().getPlayer();
|
||||
assert player != null;
|
||||
ItemStack stack = player.getMainHandStack();
|
||||
ItemStack head = player.getEquippedStack(EquipmentSlot.HEAD);
|
||||
player.equipStack(EquipmentSlot.HEAD, stack);
|
||||
player.getInventory().setStack(player.getInventory().selectedSlot, head);
|
||||
player.currentScreenHandler.syncState();
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
ItemStack head = player.getItemBySlot(EquipmentSlot.HEAD);
|
||||
player.setItemSlot(EquipmentSlot.HEAD, stack);
|
||||
player.getInventory().setItem(player.getInventory().getSelectedSlot(), head);
|
||||
player.containerMenu.sendAllDataToRemote();
|
||||
|
||||
return 1;
|
||||
}
|
||||
)
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,35 +3,35 @@ package com.github.zly2006.carpetslsaddition.command;
|
||||
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||
import com.github.zly2006.carpetslsaddition.util.SitEntity;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
|
||||
public class SitCommand {
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
dispatcher.register(CommandManager.literal("sit")
|
||||
.requires(ServerCommandSource::isExecutedByPlayer)
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(Commands.literal("sit")
|
||||
.requires(CommandSourceStack::isPlayer)
|
||||
.requires((commandSource) -> SLSCarpetSettings.canUseSitCommand)
|
||||
.executes(context -> {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
ServerPlayer player = context.getSource().getPlayer();
|
||||
assert player != null;
|
||||
|
||||
if (player.getVehicle() != null || !player.isOnGround()) { // 防止错误的坐下行为
|
||||
if (player.getVehicle() != null || !player.onGround()) { // 防止错误的坐下行为
|
||||
return 1;
|
||||
}
|
||||
|
||||
World world = player.getWorld();
|
||||
ServerLevel world = (ServerLevel) player.level();
|
||||
|
||||
ArmorStandEntity armorStandEntity = new ArmorStandEntity(world, player.getX(), player.getY(), player.getZ());
|
||||
ArmorStand armorStandEntity = new ArmorStand(world, player.getX(), player.getY(), player.getZ());
|
||||
((SitEntity) armorStandEntity).setSitEntity(true);
|
||||
world.spawnEntity(armorStandEntity);
|
||||
player.setSneaking(false);
|
||||
world.addFreshEntity(armorStandEntity);
|
||||
player.setShiftKeyDown(false);
|
||||
player.startRiding(armorStandEntity);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,4 @@ public interface SitEntity {
|
||||
boolean isSitEntity();
|
||||
|
||||
void setSitEntity(boolean sitEntity);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.github.zly2006.carpetslsaddition.util.access;
|
||||
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public interface PlayerAccessor {
|
||||
void carpet_SLS_Addition$setDisplayName(Text name);
|
||||
}
|
||||
void carpet_SLS_Addition$setDisplayName(Component name);
|
||||
}
|
||||
@@ -5,4 +5,4 @@ public interface SLSBotAccessor {
|
||||
void carpet_SLS_Addition$setBot(boolean isBot);
|
||||
long carpet_SLS_Addition$getSpawnTime();
|
||||
void carpet_SLS_Addition$setSpawnTime(long spawnTime);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user