9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 04:19:27 +00:00

配方映射完成80%

This commit is contained in:
XiaoMoMi
2025-07-11 02:48:34 +08:00
parent 2146206415
commit 87f1a53497
62 changed files with 746 additions and 292 deletions

View File

@@ -276,7 +276,7 @@ public final class BukkitBlockManager extends AbstractBlockManager {
}
private void registerEmptyBlock() {
Holder.Reference<CustomBlock> holder = ((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).registerForHolder(new ResourceKey<>(BuiltInRegistries.BLOCK.key().location(), Key.withDefaultNamespace("empty")));
Holder.Reference<CustomBlock> holder = ((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).registerForHolder(ResourceKey.create(BuiltInRegistries.BLOCK.key().location(), Key.withDefaultNamespace("empty")));
EmptyBlock emptyBlock = new EmptyBlock(Key.withDefaultNamespace("empty"), holder);
holder.bindValue(emptyBlock);
}

View File

@@ -254,9 +254,8 @@ public final class BukkitCustomBlock extends AbstractCustomBlock {
@Override
public @NotNull CustomBlock build() {
// create or get block holder
Holder.Reference<CustomBlock> holder = BuiltInRegistries.BLOCK.get(id).orElseGet(() ->
((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).registerForHolder(new ResourceKey<>(BuiltInRegistries.BLOCK.key().location(), id)));
return new BukkitCustomBlock(id, holder, properties, appearances, variantMapper, settings, events, behavior, lootTable);
Holder.Reference<CustomBlock> holder = ((WritableRegistry<CustomBlock>) BuiltInRegistries.BLOCK).getOrRegisterForHolder(ResourceKey.create(BuiltInRegistries.BLOCK.key().location(), this.id));
return new BukkitCustomBlock(this.id, holder, this.properties, this.appearances, this.variantMapper, this.settings, this.events, this.behavior, this.lootTable);
}
}
}

View File

@@ -374,7 +374,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
VANILLA_ITEMS.add(itemKey);
Holder.Reference<Key> holder = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(itemKey)
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), itemKey), itemKey));
.register(ResourceKey.create(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), itemKey), itemKey));
Object mcHolder = FastNMS.INSTANCE.method$Registry$getHolderByResourceKey(MBuiltInRegistries.ITEM, FastNMS.INSTANCE.method$ResourceKey$create(MRegistries.ITEM, resourceLocation)).get();
Set<Object> tags = (Set<Object>) CoreReflections.field$Holder$Reference$tags.get(mcHolder);
for (Object tag : tags) {

View File

@@ -4,7 +4,6 @@ import com.google.gson.JsonElement;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import net.momirealms.craftengine.bukkit.item.ComponentItemWrapper;
import net.momirealms.craftengine.bukkit.item.ComponentTypes;
import net.momirealms.craftengine.bukkit.item.LegacyItemWrapper;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBuiltInRegistries;

View File

@@ -42,6 +42,7 @@ import net.momirealms.craftengine.core.item.CustomItem;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
import net.momirealms.craftengine.core.item.context.UseOnContext;
import net.momirealms.craftengine.core.item.recipe.network.legacy.LegacyRecipeHolder;
import net.momirealms.craftengine.core.item.recipe.network.modern.RecipeBookEntry;
import net.momirealms.craftengine.core.item.recipe.network.modern.display.RecipeDisplay;
import net.momirealms.craftengine.core.pack.host.ResourcePackDownloadData;
@@ -2317,7 +2318,7 @@ public class PacketConsumers {
}
boolean isTerminal = action == NetworkReflections.instance$ServerboundResourcePackPacket$Action$SUCCESSFULLY_LOADED || action == NetworkReflections.instance$ServerboundResourcePackPacket$Action$DOWNLOADED;
if (isTerminal) {
if (isTerminal && VersionHelper.isOrAbove1_20_2()) {
event.setCancelled(true);
Object packetListener = FastNMS.INSTANCE.method$Connection$getPacketListener(user.connection());
if (!CoreReflections.clazz$ServerConfigurationPacketListenerImpl.isInstance(packetListener)) return;
@@ -2520,6 +2521,15 @@ public class PacketConsumers {
try {
if (VersionHelper.isOrAbove1_21_2()) return;
FriendlyByteBuf buf = event.getBuffer();
List<LegacyRecipeHolder> holders = buf.readCollection(ArrayList::new, byteBuf -> {
LegacyRecipeHolder holder = LegacyRecipeHolder.read(byteBuf);
holder.recipe().applyClientboundData((BukkitServerPlayer) user);
return holder;
});
event.setChanged(true);
buf.clear();
buf.writeVarInt(event.packetID());
buf.writeCollection(holders, ((byteBuf, recipeHolder) -> recipeHolder.write(byteBuf)));
} catch (Exception e) {
CraftEngine.instance().logger().warn("Failed to handle ClientboundUpdateRecipesPacket", e);
}

View File

@@ -152,16 +152,16 @@ public class PacketIds1_20 implements PacketIds {
@Override
public int clientboundRecipeBookAddPacket() {
return PacketIdFinder.serverboundByClazz(NetworkReflections.clazz$ClientboundRecipeBookAddPacket);
return PacketIdFinder.clientboundByClazz(NetworkReflections.clazz$ClientboundRecipeBookAddPacket);
}
@Override
public int clientboundPlaceGhostRecipePacket() {
return PacketIdFinder.serverboundByClazz(NetworkReflections.clazz$ClientboundPlaceGhostRecipePacket);
return PacketIdFinder.clientboundByClazz(NetworkReflections.clazz$ClientboundPlaceGhostRecipePacket);
}
@Override
public int clientboundUpdateRecipesPacket() {
return PacketIdFinder.serverboundByClazz(NetworkReflections.clazz$ClientboundUpdateRecipesPacket);
return PacketIdFinder.clientboundByClazz(NetworkReflections.clazz$ClientboundUpdateRecipesPacket);
}
}

View File

@@ -1569,7 +1569,7 @@ public final class NetworkReflections {
public static final Class<?> clazz$ClientboundPlaceGhostRecipePacket = requireNonNull(
BukkitReflectionUtils.findReobfOrMojmapClass(
"network.protocol.game.ClientboundPlaceGhostRecipePacket",
"network.protocol.game.PacketPlayOutAutoRecipe",
"network.protocol.game.ClientboundPlaceGhostRecipePacket"
)
);

View File

@@ -1,7 +1,6 @@
package net.momirealms.craftengine.bukkit.util;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistries;
import net.momirealms.craftengine.core.util.Key;