fix: 修复了Windows下中文乱码及与PCA不兼容的问题
This commit is contained in:
1 parent
42d59762a7
commit
15764d67bc
16 files changed
+91
-169
No files matched your search
@@ -48,6 +48,7 @@ dependencies {
|
|||||||
|
|
||||||
// Fabric Permission API
|
// Fabric Permission API
|
||||||
include(modImplementation('me.lucko:fabric-permissions-api:0.2-SNAPSHOT'))
|
include(modImplementation('me.lucko:fabric-permissions-api:0.2-SNAPSHOT'))
|
||||||
|
include(modImplementation('com.github.Fallen-Breath:conditional-mixin:v0.4.0'))
|
||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
|
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.6.6
|
mod_version = 0.7.1
|
||||||
maven_group = com.github.zly2006
|
maven_group = com.github.zly2006
|
||||||
archives_base_name = carpet-sls-addition
|
archives_base_name = carpet-sls-addition
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ 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.SitEntity;
|
import com.github.zly2006.carpetslsaddition.util.access.SettingsManagerAccessor;
|
||||||
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;
|
||||||
@@ -13,28 +16,14 @@ 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.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ServerMain implements ModInitializer, CarpetExtension {
|
public class ServerMain implements ModInitializer, CarpetExtension {
|
||||||
@@ -51,13 +40,12 @@ public class ServerMain implements ModInitializer, CarpetExtension {
|
|||||||
public static MinecraftServer server;
|
public static MinecraftServer server;
|
||||||
|
|
||||||
public static final boolean tisCarpetLoaded = FabricLoader.getInstance().isModLoaded("carpet-tis-addition");
|
public static final boolean tisCarpetLoaded = FabricLoader.getInstance().isModLoaded("carpet-tis-addition");
|
||||||
public static final String ITEM_NAME = "item_name";
|
|
||||||
public static final String OBSIDIAN_PICKAXE = "obsidian_pickaxe";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
INSTANCE = this;
|
INSTANCE = this;
|
||||||
CarpetServer.manageExtension(this);
|
CarpetServer.manageExtension(this);
|
||||||
|
PcaSyncProtocol.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,86 +53,41 @@ 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))) {
|
||||||
assert stream != null;
|
assert stream != null;
|
||||||
jsonFile = new String(stream.readAllBytes());
|
jsonFile = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
} catch (IOException | NullPointerException ignored) {
|
} catch (IOException | NullPointerException ignored) {
|
||||||
try {
|
try {
|
||||||
try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/%s.json".formatted("en_us"))) {
|
try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/%s.json".formatted("en_us"))) {
|
||||||
assert stream != null;
|
assert stream != null;
|
||||||
jsonFile = new String(stream.readAllBytes());
|
jsonFile = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
} catch (IOException | NullPointerException e) {
|
} catch (IOException | NullPointerException e) {
|
||||||
return translation;
|
return translation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GSON.fromJson(jsonFile, JsonObject.class).entrySet().stream()
|
GSON.fromJson(jsonFile, JsonObject.class).entrySet().stream()
|
||||||
.filter(entry -> entry.getKey().startsWith("carpet."))
|
|
||||||
.filter(entry -> entry.getValue().isJsonPrimitive())
|
.filter(entry -> entry.getValue().isJsonPrimitive())
|
||||||
.map(entry -> Map.entry(entry.getKey(), entry.getValue().getAsString()))
|
.map(entry -> Map.entry(entry.getKey(), entry.getValue().getAsString()))
|
||||||
.forEach(entry -> translation.put(entry.getKey(), entry.getValue()));
|
.forEach(entry -> {
|
||||||
|
translation.put(entry.getKey(), entry.getValue());
|
||||||
|
});
|
||||||
return translation;
|
return translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandBuildContext) {
|
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandBuildContext) {
|
||||||
dispatcher.register(CommandManager.literal("hat")
|
HatCommand.register(dispatcher);
|
||||||
.requires(ServerCommandSource::isExecutedByPlayer)
|
SitCommand.register(dispatcher);
|
||||||
.requires((commandSource) -> SLSCarpetSettings.canUseHatCommand)
|
BotCommand.register(dispatcher);
|
||||||
.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;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+17
-12
@@ -2,6 +2,7 @@ package com.github.zly2006.carpetslsaddition.block;
|
|||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
|
import io.netty.util.internal.logging.Slf4JLoggerFactory;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -10,13 +11,14 @@ import net.minecraft.world.World;
|
|||||||
import net.minecraft.world.block.NeighborUpdater;
|
import net.minecraft.world.block.NeighborUpdater;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RewriteChainRestrictedNeighborUpdater implements NeighborUpdater {
|
public class RewriteChainRestrictedNeighborUpdater implements NeighborUpdater {
|
||||||
private static final Logger LOGGER = LogUtils.getLogger();
|
private static final Logger LOGGER = LoggerFactory.getLogger("Minecraft");
|
||||||
private final World world;
|
private final World world;
|
||||||
private final int maxChainDepth;
|
private final int maxChainDepth;
|
||||||
private final ArrayDeque<Entry> queue = new ArrayDeque<>();
|
private final ArrayDeque<Entry> queue = new ArrayDeque<>();
|
||||||
@@ -49,12 +51,14 @@ public class RewriteChainRestrictedNeighborUpdater implements NeighborUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enqueue(BlockPos pos, Entry entry) {
|
private void enqueue(BlockPos pos, Entry entry) {
|
||||||
int maxSize = SLSCarpetSettings.maxUpdateQueueSize;
|
if (!needUpdate) {
|
||||||
if (maxSize > 0) {
|
return;
|
||||||
needUpdate = this.pending.size() + 1 <= maxSize;
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
needUpdate = true;
|
int maxSize = SLSCarpetSettings.maxUpdateQueueSize;
|
||||||
|
|
||||||
|
if (maxSize > 0) {
|
||||||
|
needUpdate = this.pending.size() + this.queue.size() + 1 <= maxSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean notEmpty = this.depth > 0;
|
boolean notEmpty = this.depth > 0;
|
||||||
@@ -92,17 +96,17 @@ public class RewriteChainRestrictedNeighborUpdater implements NeighborUpdater {
|
|||||||
Entry entry = this.queue.peek();
|
Entry entry = this.queue.peek();
|
||||||
assert entry != null;
|
assert entry != null;
|
||||||
|
|
||||||
if (needUpdate) {
|
while(this.pending.isEmpty()) {
|
||||||
while(this.pending.isEmpty()) {
|
if (needUpdate) {
|
||||||
if (!entry.update(this.world)) {
|
if (!entry.update(this.world)) {
|
||||||
this.queue.pop();
|
this.queue.pop();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
else {
|
entry.update(this.world);
|
||||||
entry.update(this.world);
|
throw new OutOfMemoryError("Create by Carpet-SLS-Addition");
|
||||||
throw new OutOfMemoryError("Create by Carpet-SLS-Addition");
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,6 +122,7 @@ public class RewriteChainRestrictedNeighborUpdater implements NeighborUpdater {
|
|||||||
this.queue.clear();
|
this.queue.clear();
|
||||||
this.pending.clear();
|
this.pending.clear();
|
||||||
this.depth = 0;
|
this.depth = 0;
|
||||||
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ public class BotCommand {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
((PlayerAccess) player).setDisplayName(Text.empty().append(Text.literal("[%s] ".formatted(source.getName())).setStyle(Style.EMPTY.withColor(Formatting.GRAY))).append(Text.literal(playerName).setStyle(Style.EMPTY)));
|
((PlayerAccess) player).setDisplayName(Text.empty().append(Text.literal("[%s] ".formatted(source.getName())).setStyle(Style.EMPTY.withColor(Formatting.AQUA))).append(Text.literal(playerName).setStyle(Style.EMPTY)));
|
||||||
ServerMain.server.getPlayerManager().broadcast(Text.empty()
|
ServerMain.server.getPlayerManager().broadcast(Text.empty()
|
||||||
.append(Text.literal("假人").setStyle(Style.EMPTY.withColor(Formatting.GREEN)))
|
.append(Text.literal("假人").setStyle(Style.EMPTY.withColor(Formatting.GREEN)))
|
||||||
.append(Text.literal(playerName).setStyle(Style.EMPTY.withColor(Formatting.GOLD).withBold(true)))
|
.append(Text.literal(playerName).setStyle(Style.EMPTY.withColor(Formatting.GOLD).withBold(true)))
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.block;
|
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.util.access.PlayerAccess;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
|
||||||
import net.minecraft.server.world.ServerWorld;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mixin(Block.class)
|
|
||||||
public class MixinBlock {
|
|
||||||
@Inject(method = "getDroppedStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/item/ItemStack;)Ljava/util/List;", at = @At("HEAD"), cancellable = true)
|
|
||||||
private static void onDrop(BlockState state, ServerWorld world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack stack, CallbackInfoReturnable<List<ItemStack>> cir) {
|
|
||||||
if (entity instanceof ServerPlayerEntity player) {
|
|
||||||
if (((PlayerAccess) player).holdingObsidianPickaxe() && state.getBlock() == Blocks.OBSIDIAN) {
|
|
||||||
cir.setReturnValue(List.of(new ItemStack(Items.OBSIDIAN)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -24,7 +24,7 @@ public abstract class MixinSettingsManager implements SettingsManagerAccessor {
|
|||||||
this.loadConfigurationFromConf();
|
this.loadConfigurationFromConf();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "setRule", at = @At(value = "INVOKE", target = "Lcarpet/utils/Messenger;m(Lnet/minecraft/server/command/ServerCommandSource;[Ljava/lang/Object;)V", shift = At.Shift.BEFORE))
|
@Inject(method = "setRule", at = @At(value = "INVOKE", target = "Lcarpet/utils/Messenger;m(Lnet/minecraft/server/command/ServerCommandSource;[Ljava/lang/Object;)V", shift = At.Shift.BEFORE), remap = true)
|
||||||
private void injectSetRule(ServerCommandSource source, CarpetRule<?> rule, String newValue, CallbackInfoReturnable<Integer> cir) {
|
private void injectSetRule(ServerCommandSource source, CarpetRule<?> rule, String newValue, CallbackInfoReturnable<Integer> cir) {
|
||||||
if ("maxUpdateQueueSize".equals(rule.name())) {
|
if ("maxUpdateQueueSize".equals(rule.name())) {
|
||||||
MinecraftServer server = ServerMain.server;
|
MinecraftServer server = ServerMain.server;
|
||||||
|
|||||||
+15
-18
@@ -1,6 +1,6 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.entity;
|
package com.github.zly2006.carpetslsaddition.mixin.entity;
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.PlayerAccess;
|
import com.github.zly2006.carpetslsaddition.util.access.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,8 +8,11 @@ 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.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
@@ -22,26 +25,20 @@ 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();
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private Text displayName = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean holdingObsidianPickaxe() {
|
public void setDisplayName(Text name) {
|
||||||
ItemStack itemStack = getEquippedStack(EquipmentSlot.MAINHAND);
|
this.displayName = name;
|
||||||
NbtCompound compound = itemStack.getSubNbt(MOD_ID);
|
|
||||||
return compound != null && compound.contains(ITEM_NAME) && compound.getString(ITEM_NAME).equals(OBSIDIAN_PICKAXE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "getDisplayName", at = @At("HEAD"), cancellable = true)
|
||||||
@Inject(method = "getBlockBreakingSpeed", at = @At("HEAD"), cancellable = true)
|
public void injectGetDisplayName(CallbackInfoReturnable<Text> cir) {
|
||||||
private void onGetBlockBreakingSpeed(BlockState block, CallbackInfoReturnable<Float> cir) {
|
if (this.displayName != null) {
|
||||||
if (holdingObsidianPickaxe() && block.isOf(Blocks.OBSIDIAN)) {
|
cir.setReturnValue(displayName);
|
||||||
cir.setReturnValue(750f);// f = speed / 1500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Inject(method = "canHarvest", at = @At("HEAD"), cancellable = true)
|
|
||||||
private void onGetCanMine(BlockState state, CallbackInfoReturnable<Boolean> cir) {
|
|
||||||
if (holdingObsidianPickaxe() && state.isOf(Blocks.OBSIDIAN)) {
|
|
||||||
cir.setReturnValue(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-2
@@ -17,8 +17,6 @@ import org.spongepowered.asm.mixin.Shadow;
|
|||||||
public abstract class MixinServerPlayerEntity extends PlayerEntity {
|
public abstract class MixinServerPlayerEntity extends PlayerEntity {
|
||||||
@Shadow
|
@Shadow
|
||||||
public ServerPlayNetworkHandler networkHandler;
|
public ServerPlayNetworkHandler networkHandler;
|
||||||
|
|
||||||
|
|
||||||
private int sneakTimes = 0;
|
private int sneakTimes = 0;
|
||||||
private long lastSneakTime = 0;
|
private long lastSneakTime = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.item;
|
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.util.access.PlayerAccess;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(Item.class)
|
|
||||||
public class MixinItem {
|
|
||||||
@Inject(method = "canMine", at = @At("HEAD"), cancellable = true)
|
|
||||||
private void onCheckMine(BlockState state, World world, BlockPos pos, PlayerEntity miner, CallbackInfoReturnable<Boolean> cir) {
|
|
||||||
if (((PlayerAccess) miner).holdingObsidianPickaxe() && state.getBlock() == Blocks.OBSIDIAN) {
|
|
||||||
cir.setReturnValue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
+6
-2
@@ -2,6 +2,8 @@ package com.github.zly2006.carpetslsaddition.mixin.player;
|
|||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||||
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
||||||
|
import me.fallenbreath.conditionalmixin.api.annotation.Condition;
|
||||||
|
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
|
||||||
import net.minecraft.entity.player.PlayerAbilities;
|
import net.minecraft.entity.player.PlayerAbilities;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
@@ -12,6 +14,9 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Restriction(
|
||||||
|
conflict = @Condition("pca")
|
||||||
|
)
|
||||||
@Mixin(PlayerInventory.class)
|
@Mixin(PlayerInventory.class)
|
||||||
public abstract class MixinPlayerInventory implements Inventory, Nameable {
|
public abstract class MixinPlayerInventory implements Inventory, Nameable {
|
||||||
@Redirect(method = "insertStack(ILnet/minecraft/item/ItemStack;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getAbilities()Lnet/minecraft/entity/player/PlayerAbilities;"))
|
@Redirect(method = "insertStack(ILnet/minecraft/item/ItemStack;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getAbilities()Lnet/minecraft/entity/player/PlayerAbilities;"))
|
||||||
@@ -33,8 +38,7 @@ public abstract class MixinPlayerInventory implements Inventory, Nameable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 修改潜影盒拾取逻辑,使从地上捡起潜影盒时仍可堆叠
|
// 修改潜影盒拾取逻辑,使从地上捡起潜影盒时仍可堆叠
|
||||||
@Redirect(method = "canStackAddMore",
|
@Redirect(method = "canStackAddMore", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isStackable()Z", ordinal = 0))
|
||||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isStackable()Z", ordinal = 0))
|
|
||||||
private boolean canStackAddMoreIsStackable(ItemStack itemStack) {
|
private boolean canStackAddMoreIsStackable(ItemStack itemStack) {
|
||||||
return ShulkerBoxItemUtil.isStackable(itemStack);
|
return ShulkerBoxItemUtil.isStackable(itemStack);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.github.zly2006.carpetslsaddition.mixin.plugin;
|
||||||
|
|
||||||
|
import me.fallenbreath.conditionalmixin.api.mixin.RestrictiveMixinConfigPlugin;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class BasicMixinPlugin extends RestrictiveMixinConfigPlugin {
|
||||||
|
@Override
|
||||||
|
public String getRefMapperConfig() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getMixins() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -1,12 +1,17 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.screen;
|
package com.github.zly2006.carpetslsaddition.mixin.screen;
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
||||||
|
import me.fallenbreath.conditionalmixin.api.annotation.Condition;
|
||||||
|
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Restriction(
|
||||||
|
conflict = @Condition("pca")
|
||||||
|
)
|
||||||
@Mixin(ScreenHandler.class)
|
@Mixin(ScreenHandler.class)
|
||||||
public class MixinScreenHandler {
|
public class MixinScreenHandler {
|
||||||
@Redirect(method = "insertItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isStackable()Z", ordinal = 0))
|
@Redirect(method = "insertItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isStackable()Z", ordinal = 0))
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.mixin.screen;
|
package com.github.zly2006.carpetslsaddition.mixin.screen;
|
||||||
|
|
||||||
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
import com.github.zly2006.carpetslsaddition.util.ShulkerBoxItemUtil;
|
||||||
|
import me.fallenbreath.conditionalmixin.api.annotation.Condition;
|
||||||
|
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.screen.slot.Slot;
|
import net.minecraft.screen.slot.Slot;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Restriction(
|
||||||
|
conflict = @Condition("pca")
|
||||||
|
)
|
||||||
@Mixin(Slot.class)
|
@Mixin(Slot.class)
|
||||||
public class MixinSlot {
|
public class MixinSlot {
|
||||||
@Redirect(method = "getMaxItemCount(Lnet/minecraft/item/ItemStack;)I", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getMaxCount()I", ordinal = 0))
|
@Redirect(method = "getMaxItemCount(Lnet/minecraft/item/ItemStack;)I", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getMaxCount()I", ordinal = 0))
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.github.zly2006.carpetslsaddition.util;
|
package com.github.zly2006.carpetslsaddition.util;
|
||||||
|
|
||||||
import net.minecraft.world.block.NeighborUpdater;
|
|
||||||
|
|
||||||
public interface NeighborUpdaterChanger {
|
public interface NeighborUpdaterChanger {
|
||||||
void useRewriteChainNeighborUpdater(boolean use);
|
void useRewriteChainNeighborUpdater(boolean use);
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "com.github.zly2006.carpetslsaddition.mixin",
|
"package": "com.github.zly2006.carpetslsaddition.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
|
"plugin": "com.github.zly2006.carpetslsaddition.mixin.plugin.BasicMixinPlugin",
|
||||||
"server": [
|
"server": [
|
||||||
"server.MixinMinecraftDedicatedServer"
|
"server.MixinMinecraftDedicatedServer"
|
||||||
],
|
],
|
||||||
@@ -10,7 +11,6 @@
|
|||||||
],
|
],
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"block.BlockPatternTestTransformInvoker",
|
"block.BlockPatternTestTransformInvoker",
|
||||||
"block.MixinBlock",
|
|
||||||
"block.MixinRedstoneWireBlock",
|
"block.MixinRedstoneWireBlock",
|
||||||
"carpet.MixinFakePlayer",
|
"carpet.MixinFakePlayer",
|
||||||
"carpet.MixinSettingsManager",
|
"carpet.MixinSettingsManager",
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
"entity.MixinServerPlayerEntity",
|
"entity.MixinServerPlayerEntity",
|
||||||
"entity.MixinVillagerEntity",
|
"entity.MixinVillagerEntity",
|
||||||
"item.MixinDyeItem",
|
"item.MixinDyeItem",
|
||||||
"item.MixinItem",
|
|
||||||
"item.MixinPotionItem",
|
"item.MixinPotionItem",
|
||||||
"player.AccessorPlayerAbilities",
|
"player.AccessorPlayerAbilities",
|
||||||
"player.MixinPlayerInventory",
|
"player.MixinPlayerInventory",
|
||||||
|
|||||||
Reference in new issue
Block a user