mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
优化
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user