Skip to content

Commit

Permalink
修复可能存在崩溃的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Mar 12, 2024
1 parent 6a761c2 commit 5eea1d0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public Value<?> with(String key, Comparable<?> value) {
public static @NotNull Map<String, Comparable<?>> statesFromNetwork(@NotNull FriendlyByteBuf buffer) {
Map<String, Comparable<?>> map = new HashMap<>();
String string = buffer.readUtf();
String[] strings = string.substring(1, string.length() - 2).split(", ");
String[] strings = string.substring(1, string.length() - 1).split(", ");
for (String str : strings) {
String[] strings1 = str.split("=");
if (strings1.length != 2) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.gson.JsonSyntaxException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.datafixers.util.Pair;
import dev.dubhe.anvilcraft.AnvilCraft;
import net.minecraft.commands.arguments.blocks.BlockStateParser;
import net.minecraft.core.*;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -161,7 +162,7 @@ default int lastNonSpace(@NotNull String entry) {
}

default @NotNull ItemStack itemStackFromJson(JsonElement element) {
if(!element.isJsonObject()) throw new JsonSyntaxException("Expected item to be string");
if (!element.isJsonObject()) throw new JsonSyntaxException("Expected item to be string");
JsonObject object = element.getAsJsonObject();
Item item = ShapedRecipe.itemFromJson(object);
int i = GsonHelper.getAsInt(object, "count", 1);
Expand Down Expand Up @@ -228,7 +229,7 @@ default BlockState stateFromNetwork(@NotNull FriendlyByteBuf buffer) {
}

default void stateToNetwork(@NotNull FriendlyByteBuf buffer, @NotNull BlockState state) {
buffer.writeUtf(state.toString());
buffer.writeUtf(state.toString().replace("Block{", "").replace("}", ""));
}

class BlockHolderLookup implements HolderLookup<Block>, HolderOwner<Block> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.dubhe.anvilcraft.mixin;

import dev.dubhe.anvilcraft.AnvilCraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.List;

@Mixin(ClientboundUpdateRecipesPacket.class)
public class ClientboundUpdateRecipesPacketMixin {

@Redirect(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/FriendlyByteBuf;readList(Lnet/minecraft/network/FriendlyByteBuf$Reader;)Ljava/util/List;"))
private <T> @NotNull List<T> init(@NotNull FriendlyByteBuf instance, FriendlyByteBuf.Reader<T> elementReader) {
try {
return instance.readList(elementReader);
} catch (Exception e) {
AnvilCraft.LOGGER.printStackTrace(e);
throw e;
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/anvilcraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"AnvilBlockMixin",
"ClientboundUpdateRecipesPacketMixin",
"ItemEntityMixin",
"ItemStackInjector",
"event.FallingBlockEntityMixin",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"anvilcraft.mixins.json"
],
"depends": {
"fabricloader": ">=0.15.7",
"fabricloader": ">=0.14.0",
"fabric": "*",
"minecraft": "1.20.1"
},
Expand Down

0 comments on commit 5eea1d0

Please sign in to comment.