1 parent
ad9c61cd1a
commit
42d59762a7
2 files changed
+67
-27
No files matched your search
@@ -2,11 +2,8 @@ package com.github.zly2006.carpetslsaddition;
|
||||
|
||||
import carpet.CarpetExtension;
|
||||
import carpet.CarpetServer;
|
||||
import com.github.zly2006.carpetslsaddition.command.BotCommand;
|
||||
import com.github.zly2006.carpetslsaddition.command.HatCommand;
|
||||
import com.github.zly2006.carpetslsaddition.command.SitCommand;
|
||||
import com.github.zly2006.carpetslsaddition.network.pca.PcaSyncProtocol;
|
||||
import com.github.zly2006.carpetslsaddition.util.access.SettingsManagerAccessor;
|
||||
import com.github.zly2006.carpetslsaddition.util.SitEntity;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@@ -16,13 +13,28 @@ import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.Version;
|
||||
import net.minecraft.command.CommandRegistryAccess;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.recipe.book.CraftingRecipeCategory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ServerMain implements ModInitializer, CarpetExtension {
|
||||
@@ -46,7 +58,6 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
||||
public void onInitialize() {
|
||||
INSTANCE = this;
|
||||
CarpetServer.manageExtension(this);
|
||||
PcaSyncProtocol.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,12 +65,24 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
||||
ServerMain.server = server;
|
||||
CarpetServer.settingsManager.parseSettingsClass(SLSCarpetSettings.class);
|
||||
((SettingsManagerAccessor) CarpetServer.settingsManager).loadSettings();
|
||||
if (false) {
|
||||
ItemStack stack = new ItemStack(Items.STONE_PICKAXE);
|
||||
stack.setCustomName(Text.empty().formatted(Formatting.LIGHT_PURPLE).append("黑曜石镐"));
|
||||
stack.getOrCreateSubNbt(MOD_ID).putString(ITEM_NAME, OBSIDIAN_PICKAXE);
|
||||
DefaultedList<Ingredient> ingredients = DefaultedList.ofSize(9, Ingredient.EMPTY);
|
||||
ingredients.set(0, Ingredient.ofItems(Items.OBSIDIAN));
|
||||
ingredients.set(1, Ingredient.ofItems(Items.OBSIDIAN));
|
||||
ingredients.set(2, Ingredient.ofItems(Items.OBSIDIAN));
|
||||
ingredients.set(4, Ingredient.ofItems(Items.STICK));
|
||||
ingredients.set(7, Ingredient.ofItems(Items.STICK));
|
||||
server.getRecipeManager().setRecipes(List.of(new ShapedRecipe(new Identifier(MOD_ID, "recipe.obsidian_pickaxe"), MOD_ID, CraftingRecipeCategory.EQUIPMENT, 3, 3, ingredients, stack)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> canHasTranslations(String lang) {
|
||||
Map<String, String> translation = Maps.newHashMap();
|
||||
|
||||
PcaSyncProtocol.init();
|
||||
String jsonFile;
|
||||
try {
|
||||
try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/%s.json".formatted(lang))) {
|
||||
@@ -86,8 +109,42 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
||||
|
||||
@Override
|
||||
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandBuildContext) {
|
||||
HatCommand.register(dispatcher);
|
||||
SitCommand.register(dispatcher);
|
||||
BotCommand.register(dispatcher);
|
||||
dispatcher.register(CommandManager.literal("hat")
|
||||
.requires(ServerCommandSource::isExecutedByPlayer)
|
||||
.requires((commandSource) -> SLSCarpetSettings.canUseHatCommand)
|
||||
.executes(context -> {
|
||||
ServerPlayerEntity 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();
|
||||
|
||||
return 1;
|
||||
}));
|
||||
|
||||
dispatcher.register(CommandManager.literal("sit")
|
||||
.requires(ServerCommandSource::isExecutedByPlayer)
|
||||
.requires((commandSource) -> SLSCarpetSettings.canUseSitCommand)
|
||||
.executes(context -> {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
assert player != null;
|
||||
|
||||
if (player.getVehicle() != null) { // 防止重复的坐下行为
|
||||
return 1;
|
||||
}
|
||||
|
||||
World world = player.getWorld();
|
||||
|
||||
ArmorStandEntity armorStandEntity = new ArmorStandEntity(world, player.getX(), player.getY(), player.getZ());
|
||||
((SitEntity) armorStandEntity).setSitEntity(true);
|
||||
world.spawnEntity(armorStandEntity);
|
||||
player.setSneaking(false);
|
||||
player.startRiding(armorStandEntity);
|
||||
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user