mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-03 22:26:16 +00:00
添加低版本存储实现
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package net.momirealms.craftengine.bukkit.compatibility.item;
|
||||
|
||||
import me.arcaniax.hdb.api.HeadDatabaseAPI;
|
||||
import net.momirealms.craftengine.core.item.ExternalItemSource;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import me.arcaniax.hdb.api.HeadDatabaseAPI;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
@@ -15,10 +15,12 @@ import net.momirealms.craftengine.core.block.properties.Property;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.sound.SoundData;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import net.momirealms.sparrow.nbt.CompoundTag;
|
||||
import net.momirealms.sparrow.nbt.ListTag;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameEvent;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -29,6 +31,7 @@ import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
@@ -52,14 +55,21 @@ public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
@Nullable ItemStack[] storageContents = this.inventory.getStorageContents();
|
||||
for (int i = 0; i < storageContents.length; i++) {
|
||||
if (storageContents[i] != null) {
|
||||
int slot = i;
|
||||
CoreReflections.instance$ItemStack$CODEC.encodeStart(MRegistryOps.SPARROW_NBT, FastNMS.INSTANCE.field$CraftItemStack$handle(storageContents[i]))
|
||||
.ifSuccess(success -> {
|
||||
CompoundTag itemTag = (CompoundTag) success;
|
||||
itemTag.putInt("slot", slot);
|
||||
itemsTag.add(itemTag);
|
||||
})
|
||||
.ifError(error -> CraftEngine.instance().logger().severe("Error while saving storage item: " + error));
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
int slot = i;
|
||||
CoreReflections.instance$ItemStack$CODEC.encodeStart(MRegistryOps.SPARROW_NBT, FastNMS.INSTANCE.field$CraftItemStack$handle(storageContents[i]))
|
||||
.ifSuccess(success -> {
|
||||
CompoundTag itemTag = (CompoundTag) success;
|
||||
itemTag.putInt("slot", slot);
|
||||
itemsTag.add(itemTag);
|
||||
})
|
||||
.ifError(error -> CraftEngine.instance().logger().severe("Error while saving storage item: " + error));
|
||||
} else {
|
||||
Object nmsTag = FastNMS.INSTANCE.method$itemStack$save(FastNMS.INSTANCE.field$CraftItemStack$handle(storageContents[i]), FastNMS.INSTANCE.constructor$CompoundTag());
|
||||
CompoundTag itemTag = (CompoundTag) MRegistryOps.NBT.convertTo(MRegistryOps.SPARROW_NBT, nmsTag);
|
||||
itemTag.putInt("slot", i);
|
||||
itemsTag.add(itemTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
tag.put("items", itemsTag);
|
||||
@@ -68,16 +78,24 @@ public class SimpleStorageBlockEntity extends BlockEntity {
|
||||
@Override
|
||||
public void loadCustomData(CompoundTag tag) {
|
||||
ListTag itemsTag = Optional.ofNullable(tag.getList("items")).orElseGet(ListTag::new);
|
||||
ItemStack[] storageContents = new ItemStack[this.behavior.rows() * 9];
|
||||
for (int i = 0; i < itemsTag.size(); i++) {
|
||||
CompoundTag itemTag = itemsTag.getCompound(i);
|
||||
int slot = itemTag.getInt("slot");
|
||||
if (slot < 0 || slot >= this.behavior.rows() * 9) {
|
||||
if (slot < 0 || slot >= storageContents.length) {
|
||||
continue;
|
||||
}
|
||||
CoreReflections.instance$ItemStack$CODEC.parse(MRegistryOps.SPARROW_NBT, itemTag)
|
||||
.resultOrPartial((s) -> CraftEngine.instance().logger().severe("Tried to load invalid item: '" + itemTag + "'. " + s))
|
||||
.ifPresent(nmsStack -> this.inventory.setItem(slot, FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(nmsStack)));
|
||||
if (VersionHelper.isOrAbove1_20_5()) {
|
||||
CoreReflections.instance$ItemStack$CODEC.parse(MRegistryOps.SPARROW_NBT, itemTag)
|
||||
.resultOrPartial((s) -> CraftEngine.instance().logger().severe("Tried to load invalid item: '" + itemTag + "'. " + s))
|
||||
.ifPresent(nmsStack -> storageContents[slot] = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(nmsStack));
|
||||
} else {
|
||||
Object nmsTag = MRegistryOps.SPARROW_NBT.convertTo(MRegistryOps.NBT, itemTag);
|
||||
Object itemStack = FastNMS.INSTANCE.method$ItemStack$of(nmsTag);
|
||||
storageContents[slot] = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(itemStack);
|
||||
}
|
||||
}
|
||||
this.inventory.setStorageContents(storageContents);
|
||||
}
|
||||
|
||||
public Inventory inventory() {
|
||||
|
||||
@@ -107,7 +107,7 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
|
||||
return;
|
||||
}
|
||||
if (dataList.size() == 1) {
|
||||
ResourcePackDownloadData data = dataList.get(0);
|
||||
ResourcePackDownloadData data = dataList.getFirst();
|
||||
player.sendPacket(ResourcePackUtils.createPacket(data.uuid(), data.url(), data.sha1()), true);
|
||||
player.addResourcePackUUID(data.uuid());
|
||||
} else {
|
||||
|
||||
@@ -221,6 +221,7 @@ public final class WorldStorageInjector {
|
||||
CESection section = holder.ceSection();
|
||||
if (newState instanceof DelegatingBlockState delegatingBlockState) {
|
||||
ImmutableBlockState newImmutableBlockState = delegatingBlockState.blockState();
|
||||
if (newImmutableBlockState == null) return;
|
||||
ImmutableBlockState previousImmutableBlockState = section.setBlockState(x, y, z, newImmutableBlockState);
|
||||
if (previousImmutableBlockState == newImmutableBlockState) return;
|
||||
// 处理 自定义块到自定义块或原版块到自定义块
|
||||
@@ -282,7 +283,7 @@ public final class WorldStorageInjector {
|
||||
// 那么应该清空自定义块
|
||||
ImmutableBlockState previous = section.setBlockState(x, y, z, EmptyBlock.STATE);
|
||||
// 处理 自定义块 -> 原版块
|
||||
if (!previous.isEmpty()) {
|
||||
if (previous != null && !previous.isEmpty()) {
|
||||
CEChunk chunk = holder.ceChunk();
|
||||
chunk.setDirty(true);
|
||||
if (previous.hasBlockEntity()) {
|
||||
|
||||
@@ -65,9 +65,9 @@ resource-pack:
|
||||
# Remove 1.21.5+ tinted_leaves particles
|
||||
remove-tinted-leaves-particle: true
|
||||
merge-external-folders:
|
||||
- ModelEngine/resource pack
|
||||
- "ModelEngine/resource pack"
|
||||
merge-external-zip-files:
|
||||
- CustomNameplates/resourcepack.zip
|
||||
- "CustomNameplates/resourcepack.zip"
|
||||
- "BetterModel/build.zip"
|
||||
exclude-file-extensions: ["md", "psd", "bbmodel", "db", "ini"]
|
||||
# Exclude the shaders when generating the resource pack
|
||||
|
||||
@@ -86,7 +86,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
|
||||
private final CraftEngine plugin;
|
||||
private final Consumer<PackCacheData> cacheEventDispatcher;
|
||||
private final BiConsumer<Path, Path> eventDispatcher;
|
||||
private final BiConsumer<Path, Path> generationEventDispatcher;
|
||||
private final Map<String, Pack> loadedPacks = new HashMap<>();
|
||||
private final Map<String, ConfigParser> sectionParsers = new HashMap<>();
|
||||
private final JsonObject vanillaAtlas;
|
||||
@@ -95,10 +95,10 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
protected BiConsumer<Path, Path> zipGenerator;
|
||||
protected ResourcePackHost resourcePackHost;
|
||||
|
||||
public AbstractPackManager(CraftEngine plugin, Consumer<PackCacheData> cacheEventDispatcher, BiConsumer<Path, Path> eventDispatcher) {
|
||||
public AbstractPackManager(CraftEngine plugin, Consumer<PackCacheData> cacheEventDispatcher, BiConsumer<Path, Path> generationEventDispatcher) {
|
||||
this.plugin = plugin;
|
||||
this.cacheEventDispatcher = cacheEventDispatcher;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.generationEventDispatcher = generationEventDispatcher;
|
||||
this.zipGenerator = (p1, p2) -> {};
|
||||
Path resourcesFolder = this.plugin.dataFolderPath().resolve("resources");
|
||||
try {
|
||||
@@ -663,7 +663,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
long time1 = System.currentTimeMillis();
|
||||
|
||||
// Create cache data
|
||||
PackCacheData cacheData = new PackCacheData(plugin);
|
||||
PackCacheData cacheData = new PackCacheData(this.plugin);
|
||||
this.cacheEventDispatcher.accept(cacheData);
|
||||
|
||||
// get the target location
|
||||
@@ -725,7 +725,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
}
|
||||
long time4 = System.currentTimeMillis();
|
||||
this.plugin.logger().info("Created resource pack zip file in " + (time4 - time3) + "ms");
|
||||
this.eventDispatcher.accept(generatedPackPath, finalPath);
|
||||
this.generationEventDispatcher.accept(generatedPackPath, finalPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,16 +10,15 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PackCacheData {
|
||||
|
||||
private final Set<Path> externalZips;
|
||||
private final Set<Path> externalFolders;
|
||||
|
||||
PackCacheData(@NotNull CraftEngine plugin) {
|
||||
externalFolders = Config.foldersToMerge().stream()
|
||||
this.externalFolders = Config.foldersToMerge().stream()
|
||||
.map(it -> plugin.dataFolderPath().getParent().resolve(it))
|
||||
.filter(Files::exists)
|
||||
.collect(Collectors.toSet());
|
||||
externalZips = Config.zipsToMerge().stream()
|
||||
this.externalZips = Config.zipsToMerge().stream()
|
||||
.map(it -> plugin.dataFolderPath().getParent().resolve(it))
|
||||
.filter(Files::exists)
|
||||
.filter(Files::isRegularFile)
|
||||
@@ -29,11 +28,11 @@ public class PackCacheData {
|
||||
|
||||
@NotNull
|
||||
public Set<Path> externalFolders() {
|
||||
return externalFolders;
|
||||
return this.externalFolders;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Path> externalZips() {
|
||||
return externalZips;
|
||||
return this.externalZips;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.62.14
|
||||
project_version=0.0.62.15
|
||||
config_version=45
|
||||
lang_version=25
|
||||
project_group=net.momirealms
|
||||
@@ -50,7 +50,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.5
|
||||
anti_grief_version=0.20
|
||||
nms_helper_version=1.0.75
|
||||
nms_helper_version=1.0.76
|
||||
evalex_version=3.5.0
|
||||
reactive_streams_version=1.0.4
|
||||
amazon_awssdk_version=2.33.1
|
||||
|
||||
Reference in New Issue
Block a user