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.CarpetExtension;
|
||||||
import carpet.CarpetServer;
|
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.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.common.collect.Maps;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
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.FabricLoader;
|
||||||
import net.fabricmc.loader.api.Version;
|
import net.fabricmc.loader.api.Version;
|
||||||
import net.minecraft.command.CommandRegistryAccess;
|
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.MinecraftServer;
|
||||||
|
import net.minecraft.server.command.CommandManager;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
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.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ServerMain implements ModInitializer, CarpetExtension {
|
public class ServerMain implements ModInitializer, CarpetExtension {
|
||||||
@@ -46,7 +58,6 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
|||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
INSTANCE = this;
|
INSTANCE = this;
|
||||||
CarpetServer.manageExtension(this);
|
CarpetServer.manageExtension(this);
|
||||||
PcaSyncProtocol.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -54,12 +65,24 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
|||||||
ServerMain.server = server;
|
ServerMain.server = server;
|
||||||
CarpetServer.settingsManager.parseSettingsClass(SLSCarpetSettings.class);
|
CarpetServer.settingsManager.parseSettingsClass(SLSCarpetSettings.class);
|
||||||
((SettingsManagerAccessor) CarpetServer.settingsManager).loadSettings();
|
((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
|
@Override
|
||||||
public Map<String, String> canHasTranslations(String lang) {
|
public Map<String, String> canHasTranslations(String lang) {
|
||||||
Map<String, String> translation = Maps.newHashMap();
|
Map<String, String> translation = Maps.newHashMap();
|
||||||
|
PcaSyncProtocol.init();
|
||||||
String jsonFile;
|
String jsonFile;
|
||||||
try {
|
try {
|
||||||
try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/%s.json".formatted(lang))) {
|
try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/%s.json".formatted(lang))) {
|
||||||
@@ -86,8 +109,42 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandBuildContext) {
|
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandBuildContext) {
|
||||||
HatCommand.register(dispatcher);
|
dispatcher.register(CommandManager.literal("hat")
|
||||||
SitCommand.register(dispatcher);
|
.requires(ServerCommandSource::isExecutedByPlayer)
|
||||||
BotCommand.register(dispatcher);
|
.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;
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-18
@@ -1,6 +1,6 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.entity;
|
package com.github.zly2006.carpetslsaddition.mixin.entity;
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.util.access.PlayerAccess;
|
import com.github.zly2006.carpetslsaddition.PlayerAccess;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
@@ -8,7 +8,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.stat.Stat;
|
import net.minecraft.stat.Stat;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -23,10 +22,6 @@ public abstract class MixinPlayerEntity implements PlayerAccess {
|
|||||||
|
|
||||||
@Shadow public abstract void resetStat(Stat<?> stat);
|
@Shadow public abstract void resetStat(Stat<?> stat);
|
||||||
|
|
||||||
@Shadow public abstract Text getName();
|
|
||||||
|
|
||||||
private Text displayName = null;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean holdingObsidianPickaxe() {
|
public boolean holdingObsidianPickaxe() {
|
||||||
ItemStack itemStack = getEquippedStack(EquipmentSlot.MAINHAND);
|
ItemStack itemStack = getEquippedStack(EquipmentSlot.MAINHAND);
|
||||||
@@ -34,18 +29,6 @@ public abstract class MixinPlayerEntity implements PlayerAccess {
|
|||||||
return compound != null && compound.contains(ITEM_NAME) && compound.getString(ITEM_NAME).equals(OBSIDIAN_PICKAXE);
|
return compound != null && compound.contains(ITEM_NAME) && compound.getString(ITEM_NAME).equals(OBSIDIAN_PICKAXE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDisplayName(Text name) {
|
|
||||||
this.displayName = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "getDisplayName", at = @At("HEAD"), cancellable = true)
|
|
||||||
public void injectGetDisplayName(CallbackInfoReturnable<Text> cir) {
|
|
||||||
if (this.displayName != null) {
|
|
||||||
cir.setReturnValue(displayName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Inject(method = "getBlockBreakingSpeed", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "getBlockBreakingSpeed", at = @At("HEAD"), cancellable = true)
|
||||||
private void onGetBlockBreakingSpeed(BlockState block, CallbackInfoReturnable<Float> cir) {
|
private void onGetBlockBreakingSpeed(BlockState block, CallbackInfoReturnable<Float> cir) {
|
||||||
|
|||||||
Reference in new issue
Block a user