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

修复其他弹射物

This commit is contained in:
XiaoMoMi
2025-06-21 19:17:34 +08:00
parent 82933f9537
commit dfac8503cb
16 changed files with 515 additions and 189 deletions

View File

@@ -615,17 +615,16 @@ public class BukkitBlockManager extends AbstractBlockManager {
if (!Files.exists(mappingsFile)) {
this.plugin.saveResource("mappings.yml");
}
File mappingFile = new File(plugin.dataFolderFile(), "mappings.yml");
Yaml yaml = new Yaml(new StringKeyConstructor(null, new LoaderOptions()));
Yaml yaml = new Yaml(new StringKeyConstructor(mappingsFile, new LoaderOptions()));
try (InputStream inputStream = Files.newInputStream(mappingsFile)) {
Map<String, String> blockStateMappings = loadBlockStateMappings(yaml.load(inputStream));
this.validateBlockStateMappings(mappingFile, blockStateMappings);
this.validateBlockStateMappings(mappingsFile, blockStateMappings);
Map<Integer, String> stateMap = new Int2ObjectOpenHashMap<>();
Map<Key, Integer> blockTypeCounter = new LinkedHashMap<>();
Map<Integer, Integer> appearanceMapper = new Int2IntOpenHashMap();
Map<Key, List<Integer>> appearanceArranger = new HashMap<>();
for (Map.Entry<String, String> entry : blockStateMappings.entrySet()) {
this.processBlockStateMapping(mappingFile, entry, stateMap, blockTypeCounter, appearanceMapper, appearanceArranger);
this.processBlockStateMapping(mappingsFile, entry, stateMap, blockTypeCounter, appearanceMapper, appearanceArranger);
}
this.blockAppearanceMapper = ImmutableMap.copyOf(appearanceMapper);
this.blockAppearanceArranger = ImmutableMap.copyOf(appearanceArranger);
@@ -679,7 +678,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
return blockStateMappings;
}
private void validateBlockStateMappings(File mappingFile, Map<String, String> blockStateMappings) {
private void validateBlockStateMappings(Path mappingFile, Map<String, String> blockStateMappings) {
Map<String, String> temp = new HashMap<>(blockStateMappings);
for (Map.Entry<String, String> entry : temp.entrySet()) {
String state = entry.getValue();
@@ -690,7 +689,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
}
}
private void processBlockStateMapping(File mappingFile,
private void processBlockStateMapping(Path mappingFile,
Map.Entry<String, String> entry,
Map<Integer, String> stateMap,
Map<Key, Integer> counter,
@@ -725,7 +724,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
}
}
private Object createBlockState(File mappingFile, String state) {
private Object createBlockState(Path mappingFile, String state) {
try {
Object registryOrLookUp = MBuiltInRegistries.BLOCK;
if (CoreReflections.method$Registry$asLookup != null) {

View File

@@ -16,4 +16,10 @@ public class BukkitCustomProjectile extends AbstractCustomProjectile {
public BukkitProjectile projectile() {
return (BukkitProjectile) super.projectile();
}
@SuppressWarnings("unchecked")
@Override
public Item<ItemStack> item() {
return (Item<ItemStack>) item;
}
}

View File

@@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.entity.projectile;
import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent;
import com.destroystokyo.paper.event.player.PlayerReadyArrowEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
@@ -65,7 +66,7 @@ public class BukkitProjectileManager implements Listener, ProjectileManager {
}
@Override
public Optional<CustomProjectile> projectileByEntityId(int entityId) {
public Optional<BukkitCustomProjectile> projectileByEntityId(int entityId) {
return Optional.ofNullable(this.projectiles.get(entityId));
}
@@ -191,14 +192,18 @@ public class BukkitProjectileManager implements Listener, ProjectileManager {
this.cachedServerEntity = serverEntity;
}
boolean inGround = FastNMS.INSTANCE.method$AbstractArrow$isInGround(nmsEntity);
if (canSpawnParticle(nmsEntity, inGround)) {
this.projectile.getWorld().spawnParticle(ParticleUtils.BUBBLE, this.projectile.getLocation(), 3, 0.1, 0.1, 0.1, 0);
}
if (inGround) {
updateProjectileUpdateInterval(Integer.MAX_VALUE);
} else {
if (!CoreReflections.clazz$AbstractArrow.isInstance(nmsEntity)) {
updateProjectileUpdateInterval(1);
} else {
boolean inGround = FastNMS.INSTANCE.method$AbstractArrow$isInGround(nmsEntity);
if (canSpawnParticle(nmsEntity, inGround)) {
this.projectile.getWorld().spawnParticle(ParticleUtils.BUBBLE, this.projectile.getLocation(), 3, 0.1, 0.1, 0.1, 0);
}
if (inGround) {
updateProjectileUpdateInterval(Integer.MAX_VALUE);
} else {
updateProjectileUpdateInterval(1);
}
}
}

View File

@@ -303,13 +303,14 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
public void unload() {
if (!Config.enableRecipeSystem()) return;
super.unload();
try {
if (VersionHelper.isOrAbove1_21_2()) {
// TODO: 排查为什么会出现并发修改问题
CoreReflections.method$RecipeManager$finalizeRecipeLoading.invoke(nmsRecipeManager);
}
} catch (ReflectiveOperationException e) {
this.plugin.logger().warn("Failed to unregister recipes", e);
if (VersionHelper.isOrAbove1_21_2()) {
this.plugin.scheduler().executeSync(() -> {
try {
CoreReflections.method$RecipeManager$finalizeRecipeLoading.invoke(nmsRecipeManager);
} catch (ReflectiveOperationException e) {
this.plugin.logger().warn("Failed to unregister recipes", e);
}
});
}
}
@@ -435,7 +436,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
}
}
} catch (Exception e) {
plugin.logger().warn("Failed to read data pack recipes", e);
this.plugin.logger().warn("Failed to read data pack recipes", e);
}
}

View File

@@ -1,6 +1,8 @@
package net.momirealms.craftengine.bukkit.plugin.network.handler;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.entity.data.ItemDisplayEntityData;
import net.momirealms.craftengine.bukkit.entity.projectile.BukkitCustomProjectile;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.injector.ProtectedFieldVisitor;
@@ -26,11 +28,11 @@ import java.util.UUID;
public class ProjectilePacketHandler implements EntityPacketHandler {
private final int entityId;
private final CustomProjectile projectile;
private final BukkitCustomProjectile projectile;
private final Object cachedPacket;
private final List<Object> cachedData;
public ProjectilePacketHandler(CustomProjectile projectile, int entityId) {
public ProjectilePacketHandler(BukkitCustomProjectile projectile, int entityId) {
this.projectile = projectile;
this.entityId = entityId;
this.cachedData = createCustomProjectileEntityDataValues();
@@ -111,7 +113,7 @@ public class ProjectilePacketHandler implements EntityPacketHandler {
Optional<CustomItem<ItemStack>> customItem = BukkitItemManager.instance().getCustomItem(this.projectile.metadata().item());
if (customItem.isEmpty()) return itemDisplayValues;
ProjectileMeta meta = this.projectile.metadata();
Item<?> displayedItem = customItem.get().buildItem(ItemBuildContext.EMPTY);
Item<ItemStack> displayedItem = customItem.get().buildItem(ItemBuildContext.EMPTY);
// 我们应当使用新的展示物品的组件覆盖原物品的组件,以完成附魔,附魔光效等组件的继承
displayedItem = this.projectile.item().mergeCopy(displayedItem);
ItemDisplayEntityData.InterpolationDelay.addEntityDataIfNotDefaultValue(-1, itemDisplayValues);
@@ -124,7 +126,11 @@ public class ProjectilePacketHandler implements EntityPacketHandler {
} else {
ItemDisplayEntityData.InterpolationDuration.addEntityDataIfNotDefaultValue(1, itemDisplayValues);
}
ItemDisplayEntityData.DisplayedItem.addEntityDataIfNotDefaultValue(displayedItem.getLiteralObject(), itemDisplayValues);
Object literalItem = displayedItem.getLiteralObject();
BukkitItemManager.instance().s2c(displayedItem.getItem(), null).ifPresentOrElse(
it -> ItemDisplayEntityData.DisplayedItem.addEntityDataIfNotDefaultValue(FastNMS.INSTANCE.field$CraftItemStack$handle(it), itemDisplayValues),
() -> ItemDisplayEntityData.DisplayedItem.addEntityDataIfNotDefaultValue(literalItem, itemDisplayValues));
ItemDisplayEntityData.DisplayType.addEntityDataIfNotDefaultValue(meta.displayType().id(), itemDisplayValues);
return itemDisplayValues;
}