修复集装箱部署已有实体时丢失数据的问题

This commit is contained in:
Light_Quanta 2025-05-16 03:14:19 +08:00
parent 87ca42f096
commit 4ccb3112ed
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -56,22 +56,17 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
} else {
var direction = pState.getValue(ContainerBlock.FACING);
var entity = blockEntity.entityType.create(pLevel);
if (entity == null) return;
if (blockEntity.entityTag != null) {
var entity = blockEntity.entityType.create(pLevel);
if (entity != null) {
entity.setPos(pPos.getX() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getY() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getZ() + 0.5 + (2 * Math.random() - 1) * 0.1f);
entity.setYRot(direction.toYRot());
pLevel.addFreshEntity(entity);
}
} else if (blockEntity.entityType != null) {
var entity = blockEntity.entityType.create(pLevel);
if (entity != null) {
entity.setPos(pPos.getX() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getY() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getZ() + 0.5 + (2 * Math.random() - 1) * 0.1f);
entity.setYRot(direction.toYRot());
pLevel.addFreshEntity(entity);
}
entity.load(blockEntity.entityTag);
}
entity.setPos(pPos.getX() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getY() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getZ() + 0.5 + (2 * Math.random() - 1) * 0.1f);
entity.setYRot(direction.toYRot());
pLevel.addFreshEntity(entity);
pLevel.setBlockAndUpdate(pPos, Blocks.AIR.defaultBlockState());
}
}