mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-28 11:19:08 +00:00
some clean up
This commit is contained in:
@@ -67,8 +67,9 @@ public abstract class SpecialisedExplosion<T extends Entity> extends ServerExplo
|
||||
}
|
||||
|
||||
protected final List<BlockPos> collectBlocksAndImpactEntities(final boolean interactWithBlocks, final boolean dispatch) {
|
||||
if (interactWithBlocks && this.gameEvents.add(BlockPos.containing(this.center))) {
|
||||
this.level().gameEvent(this.source, GameEvent.EXPLODE, this.center);
|
||||
final Vec3 center = this.center;
|
||||
if (interactWithBlocks && this.gameEvents.add(BlockPos.containing(center))) {
|
||||
this.level().gameEvent(this.cause, GameEvent.EXPLODE, center);
|
||||
}
|
||||
|
||||
// Collect all the blocks to explode
|
||||
@@ -77,7 +78,6 @@ public abstract class SpecialisedExplosion<T extends Entity> extends ServerExplo
|
||||
: List.of();
|
||||
|
||||
// Buffer explosions to reduce the amount of calculations and improve locality
|
||||
final Vec3 center = this.center;
|
||||
this.bounds = this.bounds.expand(center);
|
||||
this.bufferedExplosions.add(center);
|
||||
|
||||
@@ -86,6 +86,7 @@ public abstract class SpecialisedExplosion<T extends Entity> extends ServerExplo
|
||||
this.locateAndImpactEntitiesInBounds(this.bounds, this.bufferedExplosions);
|
||||
this.bounds = new AABB(center, center);
|
||||
this.bufferedExplosions.clear();
|
||||
this.gameEvents.clear();
|
||||
}
|
||||
|
||||
return blocksToExplode;
|
||||
@@ -94,9 +95,9 @@ public abstract class SpecialisedExplosion<T extends Entity> extends ServerExplo
|
||||
protected final boolean needToDispatchEntities(final List<BlockPos> blocksToBlow, final Vec3 center) {
|
||||
if (this.dispatchPosition.distanceToSqr(center) > ENTITY_DISPATCH_DISTANCE_SQR) {
|
||||
this.dispatchPosition = center;
|
||||
this.gameEvents.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
return !blocksToBlow.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,9 @@ public final class TntExplosion extends SpecialisedExplosion<PrimedTnt> {
|
||||
}
|
||||
|
||||
private void mergeEntitiesBeforeExploding() {
|
||||
final PrimedTnt cause = this.cause;
|
||||
final IteratorSafeOrderedReferenceSet<Entity> entities = this.level().entityTickList.entities;
|
||||
int index = entities.indexOf(this.cause);
|
||||
int index = entities.indexOf(cause);
|
||||
|
||||
entities.createRawIterator();
|
||||
// iterate over the entityTickList to find entities that are exploding in the same position.
|
||||
@@ -63,12 +64,12 @@ public final class TntExplosion extends SpecialisedExplosion<PrimedTnt> {
|
||||
}
|
||||
|
||||
// Check if the found entity is the same type and has the same state as the explosion source.
|
||||
if (!foundEntity.compareState(this.cause) || !mergeEntity.isSafeToMergeInto(this.cause, true)) {
|
||||
if (!foundEntity.compareState(cause) || !mergeEntity.isSafeToMergeInto(cause, true)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Merge the found entity into the explosion source
|
||||
this.level().mergeHandler.mergeEntity(mergeEntity, this.cause);
|
||||
this.level().mergeHandler.mergeEntity(mergeEntity, cause);
|
||||
}
|
||||
entities.finishRawIterator();
|
||||
}
|
||||
@@ -138,12 +139,14 @@ public final class TntExplosion extends SpecialisedExplosion<PrimedTnt> {
|
||||
}
|
||||
|
||||
private void updateExplosionPosition(final EntityState entityState, final boolean destroyedBlocks) {
|
||||
// Before setting entity state, otherwise we might cause issues.
|
||||
final Vec3 entityMomentum = this.cause.entityState().momentum();
|
||||
final PrimedTnt cause = this.cause;
|
||||
final Vec3 entityMomentum = cause.entityState().momentum();
|
||||
final boolean hasMoved;
|
||||
|
||||
// Check if we have moved before applying the entity state
|
||||
if (this.moved) {
|
||||
hasMoved = true;
|
||||
} else if (this.center.equals(this.cause.position())) {
|
||||
} else if (this.center.equals(cause.position())) {
|
||||
hasMoved = false;
|
||||
} else {
|
||||
final double newMomentumSqr = entityState.momentum().lengthSqr();
|
||||
@@ -153,13 +156,13 @@ public final class TntExplosion extends SpecialisedExplosion<PrimedTnt> {
|
||||
}
|
||||
|
||||
// Keep track of entity state
|
||||
entityState.apply(this.cause);
|
||||
this.cause.storeEntityState();
|
||||
entityState.apply(cause);
|
||||
cause.storeEntityState();
|
||||
|
||||
// Ticking is always required after destroying a block.
|
||||
if (destroyedBlocks || hasMoved) {
|
||||
this.cause.setFuse(100);
|
||||
this.cause.tick();
|
||||
cause.setFuse(100);
|
||||
cause.tick();
|
||||
this.recalculateExplosionPosition();
|
||||
this.moved |= !this.center.equals(this.originalPosition);
|
||||
}
|
||||
|
||||
@@ -70,13 +70,13 @@ public final class BlockDensityCache {
|
||||
}
|
||||
|
||||
public void expire(final long tick) {
|
||||
this.invalidate();
|
||||
|
||||
if (tick % 600 == 0) {
|
||||
// Trim everything down every 600 ticks
|
||||
this.paperExactPosDensityCache.trim(0);
|
||||
this.lenientDensityCache.trim(0);
|
||||
}
|
||||
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
|
||||
@@ -31,8 +31,8 @@ public final class CachedBlockDensity {
|
||||
return this.isExplosionPosition(explosionPos) && this.entity.containsInclusive(entityBoundingBox);
|
||||
}
|
||||
|
||||
public boolean isKnownPosition(final Vec3 point) {
|
||||
return this.entity.containsInclusive(point);
|
||||
public boolean isKnownPosition(final Vec3 pos) {
|
||||
return this.entity.containsInclusive(pos);
|
||||
}
|
||||
|
||||
public boolean isExplosionPosition(final Vec3 explosionPos) {
|
||||
|
||||
Reference in New Issue
Block a user