mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-24 17:39:30 +00:00
优化
This commit is contained in:
@@ -5,12 +5,17 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
|
||||
import net.momirealms.craftengine.bukkit.util.ParticleUtils;
|
||||
import net.momirealms.craftengine.bukkit.world.particle.BukkitParticleType;
|
||||
import net.momirealms.craftengine.core.plugin.Platform;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleType;
|
||||
import net.momirealms.sparrow.nbt.CompoundTag;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -62,4 +67,13 @@ public class BukkitPlatform implements Platform {
|
||||
}
|
||||
return BukkitAdaptors.adapt(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleType getParticleType(Key name) {
|
||||
Particle particle = ParticleUtils.getParticle(name);
|
||||
if (particle == null) {
|
||||
throw new IllegalArgumentException("Invalid particle: " + name);
|
||||
}
|
||||
return new BukkitParticleType(particle, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.craftengine.core.world.*;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleData;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.SoundCategory;
|
||||
@@ -106,8 +107,8 @@ public class BukkitWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawnParticle(Position location, Key particle, int count, double xOffset, double yOffset, double zOffset, double speed, @Nullable ParticleData extraData, @NotNull Context context) {
|
||||
Particle particleType = ParticleUtils.getParticle(particle);
|
||||
public void spawnParticle(Position location, ParticleType particle, int count, double xOffset, double yOffset, double zOffset, double speed, @Nullable ParticleData extraData, @NotNull Context context) {
|
||||
Particle particleType = (Particle) particle.platformParticle();
|
||||
if (particleType == null) return;
|
||||
org.bukkit.World platformWorld = platformWorld();
|
||||
platformWorld.spawnParticle(particleType, location.x(), location.y(), location.z(), count, xOffset, yOffset, zOffset, speed, extraData == null ? null : ParticleUtils.toBukkitParticleData(extraData, context, platformWorld, location.x(), location.y(), location.z()));
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.momirealms.craftengine.bukkit.world.particle;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleType;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class BukkitParticleType implements ParticleType {
|
||||
private final Particle particle;
|
||||
private final Key type;
|
||||
|
||||
public BukkitParticleType(Particle particle, Key type) {
|
||||
this.particle = particle;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle platformParticle() {
|
||||
return particle;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public abstract class BlockEntity {
|
||||
protected final BlockPos pos;
|
||||
protected ImmutableBlockState blockState;
|
||||
protected BlockEntityType<? extends BlockEntity> type;
|
||||
protected CEWorld world;
|
||||
public CEWorld world;
|
||||
protected boolean valid;
|
||||
@Nullable
|
||||
protected DynamicBlockEntityRenderer blockEntityRenderer;
|
||||
|
||||
@@ -25,10 +25,8 @@ public class TickingBlockEntityImpl<T extends BlockEntity> implements TickingBlo
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
// 已无效
|
||||
if (!this.isValid()) return;
|
||||
// 还没加载完全
|
||||
if (this.blockEntity.world() == null) return;
|
||||
if (this.blockEntity.world == null) return;
|
||||
BlockPos pos = pos();
|
||||
ImmutableBlockState state = this.chunk.getBlockState(pos);
|
||||
// 不是合法方块
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package net.momirealms.craftengine.core.plugin;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleType;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
|
||||
public interface Platform {
|
||||
@@ -17,4 +19,6 @@ public interface Platform {
|
||||
Tag javaToSparrowNBT(Object object);
|
||||
|
||||
World getWorld(String name);
|
||||
|
||||
ParticleType getParticleType(Key name);
|
||||
}
|
||||
|
||||
@@ -31,8 +31,6 @@ public abstract class CEWorld {
|
||||
protected volatile boolean isUpdatingLights = false;
|
||||
protected SchedulerTask syncTickTask;
|
||||
protected SchedulerTask asyncTickTask;
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private int tileTickPosition;
|
||||
|
||||
public CEWorld(World world, StorageAdaptor adaptor) {
|
||||
this.world = world;
|
||||
@@ -207,12 +205,13 @@ public abstract class CEWorld {
|
||||
this.pendingTickingBlockEntities.clear();
|
||||
}
|
||||
if (!this.tickingBlockEntities.isEmpty()) {
|
||||
for (this.tileTickPosition = 0; this.tileTickPosition < this.tickingBlockEntities.size(); this.tileTickPosition++) {
|
||||
TickingBlockEntity blockEntity = this.tickingBlockEntities.get(this.tileTickPosition);
|
||||
if (blockEntity.isValid()) {
|
||||
blockEntity.tick();
|
||||
Object[] entities = this.tickingBlockEntities.elements();
|
||||
for (int i = 0, size = this.tickingBlockEntities.size(); i < size; i++) {
|
||||
TickingBlockEntity entity = (TickingBlockEntity) entities[i];
|
||||
if (entity.isValid()) {
|
||||
entity.tick();
|
||||
} else {
|
||||
this.tickingBlockEntities.markAsRemoved(this.tileTickPosition);
|
||||
this.tickingBlockEntities.markAsRemoved(i);
|
||||
}
|
||||
}
|
||||
this.tickingBlockEntities.removeMarkedEntries();
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.momirealms.craftengine.core.sound.SoundData;
|
||||
import net.momirealms.craftengine.core.sound.SoundSource;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleData;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -58,7 +59,7 @@ public interface World {
|
||||
|
||||
void levelEvent(int id, BlockPos pos, int data);
|
||||
|
||||
void spawnParticle(Position location, Key particle, int count, double xOffset, double yOffset, double zOffset, double speed, @Nullable ParticleData extraData, @NotNull Context context);
|
||||
void spawnParticle(Position location, ParticleType particle, int count, double xOffset, double yOffset, double zOffset, double speed, @Nullable ParticleData extraData, @NotNull Context context);
|
||||
|
||||
long time();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.core.world.particle;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
|
||||
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -9,7 +10,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ParticleConfig {
|
||||
public final Key particleType;
|
||||
public final ParticleType particleType;
|
||||
public final NumberProvider x;
|
||||
public final NumberProvider y;
|
||||
public final NumberProvider z;
|
||||
@@ -20,7 +21,7 @@ public class ParticleConfig {
|
||||
public final NumberProvider speed;
|
||||
public final ParticleData particleData;
|
||||
|
||||
public ParticleConfig(Key particleType, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider count, NumberProvider xOffset, NumberProvider yOffset, NumberProvider zOffset, NumberProvider speed, ParticleData particleData) {
|
||||
public ParticleConfig(ParticleType particleType, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider count, NumberProvider xOffset, NumberProvider yOffset, NumberProvider zOffset, NumberProvider speed, ParticleData particleData) {
|
||||
this.particleType = particleType;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -43,7 +44,7 @@ public class ParticleConfig {
|
||||
NumberProvider yOffset = NumberProviders.fromObject(arguments.getOrDefault("offset-y", 0));
|
||||
NumberProvider zOffset = NumberProviders.fromObject(arguments.getOrDefault("offset-z", 0));
|
||||
NumberProvider speed = NumberProviders.fromObject(arguments.getOrDefault("speed", 0));
|
||||
return new ParticleConfig(particleType, x, y, z, count, xOffset, yOffset, zOffset, speed, Optional.ofNullable(ParticleDataTypes.TYPES.get(particleType)).map(it -> it.apply(arguments)).orElse(null));
|
||||
return new ParticleConfig(CraftEngine.instance().platform().getParticleType(particleType), x, y, z, count, xOffset, yOffset, zOffset, speed, Optional.ofNullable(ParticleDataTypes.TYPES.get(particleType)).map(it -> it.apply(arguments)).orElse(null));
|
||||
}
|
||||
|
||||
public static ParticleConfig fromMap$blockEntity(Map<String, Object> arguments) {
|
||||
@@ -56,10 +57,10 @@ public class ParticleConfig {
|
||||
NumberProvider yOffset = NumberProviders.fromObject(arguments.getOrDefault("offset-y", 0));
|
||||
NumberProvider zOffset = NumberProviders.fromObject(arguments.getOrDefault("offset-z", 0));
|
||||
NumberProvider speed = NumberProviders.fromObject(arguments.getOrDefault("speed", 0));
|
||||
return new ParticleConfig(particleType, x, y, z, count, xOffset, yOffset, zOffset, speed, Optional.ofNullable(ParticleDataTypes.TYPES.get(particleType)).map(it -> it.apply(arguments)).orElse(null));
|
||||
return new ParticleConfig(CraftEngine.instance().platform().getParticleType(particleType), x, y, z, count, xOffset, yOffset, zOffset, speed, Optional.ofNullable(ParticleDataTypes.TYPES.get(particleType)).map(it -> it.apply(arguments)).orElse(null));
|
||||
}
|
||||
|
||||
public Key particleType() {
|
||||
public ParticleType particleType() {
|
||||
return particleType;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.momirealms.craftengine.core.world.particle;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public interface ParticleType {
|
||||
|
||||
Key type();
|
||||
|
||||
Object platformParticle();
|
||||
}
|
||||
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.62.20
|
||||
project_version=0.0.63
|
||||
config_version=45
|
||||
lang_version=29
|
||||
project_group=net.momirealms
|
||||
|
||||
Reference in New Issue
Block a user